Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 3 | |
| 4 | ; Result of left shifting a non-negative integer |
| 5 | ; with nsw flag should also be non-negative |
| 6 | define i1 @test_shift_nonnegative(i32 %a) { |
| 7 | ; CHECK-LABEL: @test_shift_nonnegative( |
| 8 | ; CHECK-NEXT: ret i1 true |
| 9 | ; |
| 10 | %b = lshr i32 %a, 2 |
| 11 | %shift = shl nsw i32 %b, 3 |
| 12 | %cmp = icmp sge i32 %shift, 0 |
| 13 | ret i1 %cmp |
| 14 | } |
| 15 | |
| 16 | ; Result of left shifting a negative integer with |
| 17 | ; nsw flag should also be negative |
| 18 | define i1 @test_shift_negative(i32 %a, i32 %b) { |
| 19 | ; CHECK-LABEL: @test_shift_negative( |
| 20 | ; CHECK-NEXT: ret i1 true |
| 21 | ; |
| 22 | %c = or i32 %a, -2147483648 |
| 23 | %d = and i32 %b, 7 |
| 24 | %shift = shl nsw i32 %c, %d |
| 25 | %cmp = icmp slt i32 %shift, 0 |
| 26 | ret i1 %cmp |
| 27 | } |
| 28 | |
| 29 | ; If sign bit is a known zero, it cannot be a known one. |
Sanjay Patel | e272be7 | 2017-10-12 17:31:46 +0000 | [diff] [blame^] | 30 | ; This test should not crash opt. The shift produces poison. |
Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 31 | define i32 @test_no_sign_bit_conflict1(i1 %b) { |
| 32 | ; CHECK-LABEL: @test_no_sign_bit_conflict1( |
Sanjay Patel | e272be7 | 2017-10-12 17:31:46 +0000 | [diff] [blame^] | 33 | ; CHECK-NEXT: ret i32 0 |
Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 34 | ; |
Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 35 | %sel = select i1 %b, i32 8193, i32 8192 |
| 36 | %mul = shl nsw i32 %sel, 18 |
| 37 | ret i32 %mul |
| 38 | } |
| 39 | |
| 40 | ; If sign bit is a known one, it cannot be a known zero. |
Sanjay Patel | e272be7 | 2017-10-12 17:31:46 +0000 | [diff] [blame^] | 41 | ; This test should not crash opt. The shift produces poison. |
Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 42 | define i32 @test_no_sign_bit_conflict2(i1 %b) { |
| 43 | ; CHECK-LABEL: @test_no_sign_bit_conflict2( |
Sanjay Patel | e272be7 | 2017-10-12 17:31:46 +0000 | [diff] [blame^] | 44 | ; CHECK-NEXT: ret i32 0 |
Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 45 | ; |
Evgeny Stupachenko | d7f9c35 | 2016-08-24 23:01:33 +0000 | [diff] [blame] | 46 | %sel = select i1 %b, i32 -8193, i32 -8194 |
| 47 | %mul = shl nsw i32 %sel, 18 |
| 48 | ret i32 %mul |
| 49 | } |