Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 3 | |
| 4 | define i32 @test1(i32 %x) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 5 | ; CHECK-LABEL: @test1( |
| 6 | ; CHECK-NEXT: ret i32 %x |
| 7 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 8 | %and = and i32 %x, 1 |
| 9 | %cmp = icmp eq i32 %and, 0 |
| 10 | %and1 = and i32 %x, -2 |
| 11 | %and1.x = select i1 %cmp, i32 %and1, i32 %x |
| 12 | ret i32 %and1.x |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | define i32 @test2(i32 %x) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 16 | ; CHECK-LABEL: @test2( |
| 17 | ; CHECK-NEXT: ret i32 %x |
| 18 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 19 | %and = and i32 %x, 1 |
| 20 | %cmp = icmp ne i32 %and, 0 |
| 21 | %and1 = and i32 %x, -2 |
| 22 | %and1.x = select i1 %cmp, i32 %x, i32 %and1 |
| 23 | ret i32 %and1.x |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | define i32 @test3(i32 %x) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 27 | ; CHECK-LABEL: @test3( |
| 28 | ; CHECK-NEXT: [[AND1:%.*]] = and i32 %x, -2 |
| 29 | ; CHECK-NEXT: ret i32 [[AND1]] |
| 30 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 31 | %and = and i32 %x, 1 |
| 32 | %cmp = icmp ne i32 %and, 0 |
| 33 | %and1 = and i32 %x, -2 |
| 34 | %and1.x = select i1 %cmp, i32 %and1, i32 %x |
| 35 | ret i32 %and1.x |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 36 | } |
| 37 | |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 38 | define i32 @test4(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 39 | ; CHECK-LABEL: @test4( |
| 40 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %X, -2147483648 |
| 41 | ; CHECK-NEXT: ret i32 [[OR]] |
| 42 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 43 | %cmp = icmp slt i32 %X, 0 |
| 44 | %or = or i32 %X, -2147483648 |
| 45 | %cond = select i1 %cmp, i32 %X, i32 %or |
| 46 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | define i32 @test5(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 50 | ; CHECK-LABEL: @test5( |
| 51 | ; CHECK-NEXT: ret i32 %X |
| 52 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 53 | %cmp = icmp slt i32 %X, 0 |
| 54 | %or = or i32 %X, -2147483648 |
| 55 | %cond = select i1 %cmp, i32 %or, i32 %X |
| 56 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | define i32 @test6(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 60 | ; CHECK-LABEL: @test6( |
| 61 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %X, 2147483647 |
| 62 | ; CHECK-NEXT: ret i32 [[AND]] |
| 63 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 64 | %cmp = icmp slt i32 %X, 0 |
| 65 | %and = and i32 %X, 2147483647 |
| 66 | %cond = select i1 %cmp, i32 %and, i32 %X |
| 67 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | define i32 @test7(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 71 | ; CHECK-LABEL: @test7( |
| 72 | ; CHECK-NEXT: ret i32 %X |
| 73 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 74 | %cmp = icmp slt i32 %X, 0 |
| 75 | %and = and i32 %X, 2147483647 |
| 76 | %cond = select i1 %cmp, i32 %X, i32 %and |
| 77 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | define i32 @test8(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 81 | ; CHECK-LABEL: @test8( |
| 82 | ; CHECK-NEXT: ret i32 %X |
| 83 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 84 | %cmp = icmp sgt i32 %X, -1 |
| 85 | %or = or i32 %X, -2147483648 |
| 86 | %cond = select i1 %cmp, i32 %X, i32 %or |
| 87 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | define i32 @test9(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 91 | ; CHECK-LABEL: @test9( |
| 92 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %X, -2147483648 |
| 93 | ; CHECK-NEXT: ret i32 [[OR]] |
| 94 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 95 | %cmp = icmp sgt i32 %X, -1 |
| 96 | %or = or i32 %X, -2147483648 |
| 97 | %cond = select i1 %cmp, i32 %or, i32 %X |
| 98 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | define i32 @test10(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 102 | ; CHECK-LABEL: @test10( |
| 103 | ; CHECK-NEXT: ret i32 %X |
| 104 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 105 | %cmp = icmp sgt i32 %X, -1 |
| 106 | %and = and i32 %X, 2147483647 |
| 107 | %cond = select i1 %cmp, i32 %and, i32 %X |
| 108 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | define i32 @test11(i32 %X) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 112 | ; CHECK-LABEL: @test11( |
| 113 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %X, 2147483647 |
| 114 | ; CHECK-NEXT: ret i32 [[AND]] |
| 115 | ; |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 116 | %cmp = icmp sgt i32 %X, -1 |
| 117 | %and = and i32 %X, 2147483647 |
| 118 | %cond = select i1 %cmp, i32 %X, i32 %and |
| 119 | ret i32 %cond |
David Majnemer | 0b6a0b0 | 2014-12-20 03:04:38 +0000 | [diff] [blame] | 120 | } |
| 121 | |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 122 | define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 123 | ; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8( |
| 124 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 8 |
| 125 | ; CHECK-NEXT: ret i32 [[OR]] |
| 126 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 127 | %and = and i32 %x, 8 |
| 128 | %cmp = icmp eq i32 %and, 0 |
| 129 | %or = or i32 %x, 8 |
| 130 | %or.x = select i1 %cmp, i32 %or, i32 %x |
| 131 | ret i32 %or.x |
| 132 | } |
| 133 | |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 134 | define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 135 | ; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8( |
| 136 | ; CHECK-NEXT: [[AND1:%.*]] = and i32 %x, -9 |
| 137 | ; CHECK-NEXT: ret i32 [[AND1]] |
| 138 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 139 | %and = and i32 %x, 8 |
| 140 | %cmp = icmp eq i32 %and, 0 |
| 141 | %and1 = and i32 %x, -9 |
| 142 | %x.and1 = select i1 %cmp, i32 %x, i32 %and1 |
| 143 | ret i32 %x.and1 |
| 144 | } |
| 145 | |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 146 | define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 147 | ; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8( |
| 148 | ; CHECK-NEXT: ret i32 %x |
| 149 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 150 | %and = and i32 %x, 8 |
| 151 | %cmp = icmp eq i32 %and, 0 |
| 152 | %and1 = and i32 %x, -9 |
| 153 | %and1.x = select i1 %cmp, i32 %and1, i32 %x |
| 154 | ret i32 %and1.x |
| 155 | } |
| 156 | |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 157 | define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 158 | ; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8( |
| 159 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 8 |
| 160 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0 |
| 161 | ; CHECK-NEXT: [[AND1:%.*]] = and i64 %y, -9 |
| 162 | ; CHECK-NEXT: [[Y_AND1:%.*]] = select i1 [[CMP]], i64 %y, i64 [[AND1]] |
| 163 | ; CHECK-NEXT: ret i64 [[Y_AND1]] |
| 164 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 165 | %and = and i32 %x, 8 |
| 166 | %cmp = icmp eq i32 %and, 0 |
| 167 | %and1 = and i64 %y, -9 |
| 168 | %y.and1 = select i1 %cmp, i64 %y, i64 %and1 |
| 169 | ret i64 %y.and1 |
| 170 | } |
| 171 | |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 172 | define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) { |
Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 173 | ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8( |
| 174 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 8 |
| 175 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0 |
| 176 | ; CHECK-NEXT: [[AND1:%.*]] = and i64 %y, -9 |
| 177 | ; CHECK-NEXT: [[AND1_Y:%.*]] = select i1 [[CMP]], i64 [[AND1]], i64 %y |
| 178 | ; CHECK-NEXT: ret i64 [[AND1_Y]] |
| 179 | ; |
David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 180 | %and = and i32 %x, 8 |
| 181 | %cmp = icmp eq i32 %and, 0 |
| 182 | %and1 = and i64 %y, -9 |
| 183 | %and1.y = select i1 %cmp, i64 %and1, i64 %y |
| 184 | ret i64 %and1.y |
| 185 | } |
| 186 | |