Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by update_test_checks.py |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 2 | ; RUN: opt -S -instsimplify < %s | FileCheck %s |
| 3 | |
| 4 | define i1 @test(i32 %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 5 | ; CHECK-LABEL: @test( |
| 6 | ; CHECK: ret i1 false |
| 7 | ; |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 8 | %rhs = add i32 %a, -1 |
| 9 | %and = and i32 %a, %rhs |
| 10 | %res = icmp eq i32 %and, 1 |
| 11 | ret i1 %res |
| 12 | } |
| 13 | |
| 14 | define i1 @test2(i32 %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 15 | ; CHECK-LABEL: @test2( |
| 16 | ; CHECK: ret i1 false |
| 17 | ; |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 18 | %rhs = add i32 %a, 1 |
| 19 | %and = and i32 %a, %rhs |
| 20 | %res = icmp eq i32 %and, 1 |
| 21 | ret i1 %res |
| 22 | } |
| 23 | |
| 24 | define i1 @test3(i32 %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 25 | ; CHECK-LABEL: @test3( |
| 26 | ; CHECK: ret i1 false |
| 27 | ; |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 28 | %rhs = add i32 %a, 7 |
| 29 | %and = and i32 %a, %rhs |
| 30 | %res = icmp eq i32 %and, 1 |
| 31 | ret i1 %res |
| 32 | } |
| 33 | |
| 34 | @B = external global i32 |
| 35 | declare void @llvm.assume(i1) |
| 36 | |
| 37 | ; Known bits without a constant |
| 38 | define i1 @test4(i32 %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 39 | ; CHECK-LABEL: @test4( |
| 40 | ; CHECK: [[B:%.*]] = load i32, i32* @B |
| 41 | ; CHECK-NEXT: [[B_AND:%.*]] = and i32 [[B]], 1 |
| 42 | ; CHECK-NEXT: [[B_CND:%.*]] = icmp eq i32 [[B_AND]], 1 |
| 43 | ; CHECK-NEXT: call void @llvm.assume(i1 [[B_CND]]) |
| 44 | ; CHECK-NEXT: ret i1 false |
| 45 | ; |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 46 | %b = load i32, i32* @B |
| 47 | %b.and = and i32 %b, 1 |
| 48 | %b.cnd = icmp eq i32 %b.and, 1 |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame^] | 49 | call void @llvm.assume(i1 %b.cnd) |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 50 | |
| 51 | %rhs = add i32 %a, %b |
| 52 | %and = and i32 %a, %rhs |
| 53 | %res = icmp eq i32 %and, 1 |
| 54 | ret i1 %res |
| 55 | } |
| 56 | |
| 57 | ; Negative test - even number |
| 58 | define i1 @test5(i32 %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 59 | ; CHECK-LABEL: @test5( |
| 60 | ; CHECK: [[RHS:%.*]] = add i32 %a, 2 |
| 61 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %a, [[RHS]] |
| 62 | ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[AND]], 1 |
| 63 | ; CHECK-NEXT: ret i1 [[RES]] |
| 64 | ; |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 65 | %rhs = add i32 %a, 2 |
| 66 | %and = and i32 %a, %rhs |
| 67 | %res = icmp eq i32 %and, 1 |
| 68 | ret i1 %res |
| 69 | } |
| 70 | |
| 71 | define i1 @test6(i32 %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 72 | ; CHECK-LABEL: @test6( |
| 73 | ; CHECK: ret i1 false |
| 74 | ; |
Philip Reames | 2d85874 | 2015-11-10 18:46:14 +0000 | [diff] [blame] | 75 | %lhs = add i32 %a, -1 |
| 76 | %and = and i32 %lhs, %a |
| 77 | %res = icmp eq i32 %and, 1 |
| 78 | ret i1 %res |
| 79 | } |