| 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 | |
| Sanjay Patel | 5f3c703 | 2016-07-20 23:40:01 +0000 | [diff] [blame] | 122 | define <2 x i8> @test11vec(<2 x i8> %X) { |
| 123 | ; CHECK-LABEL: @test11vec( |
| 124 | ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> %X, <i8 127, i8 127> |
| 125 | ; CHECK-NEXT: ret <2 x i8> [[AND]] |
| 126 | ; |
| 127 | %cmp = icmp sgt <2 x i8> %X, <i8 -1, i8 -1> |
| 128 | %and = and <2 x i8> %X, <i8 127, i8 127> |
| 129 | %sel = select <2 x i1> %cmp, <2 x i8> %X, <2 x i8> %and |
| 130 | ret <2 x i8> %sel |
| 131 | } |
| 132 | |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 133 | define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) { |
| Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 134 | ; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8( |
| 135 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 8 |
| 136 | ; CHECK-NEXT: ret i32 [[OR]] |
| 137 | ; |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 138 | %and = and i32 %x, 8 |
| 139 | %cmp = icmp eq i32 %and, 0 |
| 140 | %or = or i32 %x, 8 |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 141 | %sel = select i1 %cmp, i32 %or, i32 %x |
| 142 | ret i32 %sel |
| 143 | } |
| 144 | |
| 145 | define i32 @select_icmp_and_8_eq_0_or_8_alt(i32 %x) { |
| 146 | ; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8_alt( |
| 147 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 8 |
| 148 | ; CHECK-NEXT: ret i32 [[OR]] |
| 149 | ; |
| 150 | %and = and i32 %x, 8 |
| 151 | %cmp = icmp ne i32 %and, 0 |
| 152 | %or = or i32 %x, 8 |
| 153 | %sel = select i1 %cmp, i32 %x, i32 %or |
| 154 | ret i32 %sel |
| 155 | } |
| 156 | |
| 157 | define i32 @select_icmp_and_8_ne_0_or_8(i32 %x) { |
| 158 | ; CHECK-LABEL: @select_icmp_and_8_ne_0_or_8( |
| 159 | ; CHECK-NEXT: ret i32 %x |
| 160 | ; |
| 161 | %and = and i32 %x, 8 |
| 162 | %cmp = icmp ne i32 %and, 0 |
| 163 | %or = or i32 %x, 8 |
| 164 | %sel = select i1 %cmp, i32 %or, i32 %x |
| 165 | ret i32 %sel |
| 166 | } |
| 167 | |
| 168 | define i32 @select_icmp_and_8_ne_0_or_8_alt(i32 %x) { |
| 169 | ; CHECK-LABEL: @select_icmp_and_8_ne_0_or_8_alt( |
| 170 | ; CHECK-NEXT: ret i32 %x |
| 171 | ; |
| 172 | %and = and i32 %x, 8 |
| 173 | %cmp = icmp eq i32 %and, 0 |
| 174 | %or = or i32 %x, 8 |
| 175 | %sel = select i1 %cmp, i32 %x, i32 %or |
| 176 | ret i32 %sel |
| 177 | } |
| 178 | |
| 179 | define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) { |
| 180 | ; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8( |
| 181 | ; CHECK-NEXT: [[AND1:%.*]] = and i32 %x, -9 |
| 182 | ; CHECK-NEXT: ret i32 [[AND1]] |
| 183 | ; |
| 184 | %and = and i32 %x, 8 |
| 185 | %cmp = icmp eq i32 %and, 0 |
| 186 | %and1 = and i32 %x, -9 |
| 187 | %sel = select i1 %cmp, i32 %x, i32 %and1 |
| 188 | ret i32 %sel |
| 189 | } |
| 190 | |
| 191 | define i32 @select_icmp_and_8_eq_0_and_not_8_alt(i32 %x) { |
| 192 | ; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8_alt( |
| 193 | ; CHECK-NEXT: [[AND1:%.*]] = and i32 %x, -9 |
| 194 | ; CHECK-NEXT: ret i32 [[AND1]] |
| 195 | ; |
| 196 | %and = and i32 %x, 8 |
| 197 | %cmp = icmp ne i32 %and, 0 |
| 198 | %and1 = and i32 %x, -9 |
| 199 | %sel = select i1 %cmp, i32 %and1, i32 %x |
| 200 | ret i32 %sel |
| 201 | } |
| 202 | |
| 203 | define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) { |
| 204 | ; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8( |
| 205 | ; CHECK-NEXT: ret i32 %x |
| 206 | ; |
| 207 | %and = and i32 %x, 8 |
| 208 | %cmp = icmp ne i32 %and, 0 |
| 209 | %and1 = and i32 %x, -9 |
| 210 | %sel = select i1 %cmp, i32 %x, i32 %and1 |
| 211 | ret i32 %sel |
| 212 | } |
| 213 | |
| 214 | define i32 @select_icmp_and_8_ne_0_and_not_8_alt(i32 %x) { |
| 215 | ; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8_alt( |
| 216 | ; CHECK-NEXT: ret i32 %x |
| 217 | ; |
| 218 | %and = and i32 %x, 8 |
| 219 | %cmp = icmp eq i32 %and, 0 |
| 220 | %and1 = and i32 %x, -9 |
| 221 | %sel = select i1 %cmp, i32 %and1, i32 %x |
| 222 | ret i32 %sel |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| Sanjay Patel | d2ff6d7 | 2016-07-19 16:49:55 +0000 | [diff] [blame] | 225 | ; PR28466: https://llvm.org/bugs/show_bug.cgi?id=28466 |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 226 | ; Each of the previous 8 patterns has a variant that replaces the |
| 227 | ; 'and' with a 'trunc' and the icmp eq/ne with icmp slt/sgt. |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 228 | |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 229 | define i32 @select_icmp_trunc_8_ne_0_or_128(i32 %x) { |
| 230 | ; CHECK-LABEL: @select_icmp_trunc_8_ne_0_or_128( |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 231 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i8 |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 232 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[TRUNC]], -1 |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 233 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 128 |
| 234 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[OR]], i32 %x |
| 235 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 236 | ; |
| 237 | %trunc = trunc i32 %x to i8 |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 238 | %cmp = icmp sgt i8 %trunc, -1 |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 239 | %or = or i32 %x, 128 |
| 240 | %sel = select i1 %cmp, i32 %or, i32 %x |
| 241 | ret i32 %sel |
| 242 | } |
| Sanjay Patel | d2ff6d7 | 2016-07-19 16:49:55 +0000 | [diff] [blame] | 243 | |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 244 | define i32 @select_icmp_trunc_8_ne_0_or_128_alt(i32 %x) { |
| 245 | ; CHECK-LABEL: @select_icmp_trunc_8_ne_0_or_128_alt( |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 246 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i8 |
| 247 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TRUNC]], 0 |
| 248 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 128 |
| 249 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 [[OR]] |
| 250 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 251 | ; |
| 252 | %trunc = trunc i32 %x to i8 |
| 253 | %cmp = icmp slt i8 %trunc, 0 |
| 254 | %or = or i32 %x, 128 |
| 255 | %sel = select i1 %cmp, i32 %x, i32 %or |
| 256 | ret i32 %sel |
| 257 | } |
| 258 | |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 259 | define i32 @select_icmp_trunc_8_eq_0_or_128(i32 %x) { |
| 260 | ; CHECK-LABEL: @select_icmp_trunc_8_eq_0_or_128( |
| 261 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i8 |
| 262 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TRUNC]], 0 |
| 263 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 128 |
| 264 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[OR]], i32 %x |
| 265 | ; CHECK-NEXT: ret i32 [[SEL]] |
| Sanjay Patel | 8a2bf30 | 2016-07-18 20:06:51 +0000 | [diff] [blame] | 266 | ; |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 267 | %trunc = trunc i32 %x to i8 |
| 268 | %cmp = icmp slt i8 %trunc, 0 |
| 269 | %or = or i32 %x, 128 |
| 270 | %sel = select i1 %cmp, i32 %or, i32 %x |
| 271 | ret i32 %sel |
| 272 | } |
| 273 | |
| 274 | define i32 @select_icmp_trunc_8_eq_0_or_128_alt(i32 %x) { |
| 275 | ; CHECK-LABEL: @select_icmp_trunc_8_eq_0_or_128_alt( |
| 276 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i8 |
| 277 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[TRUNC]], -1 |
| 278 | ; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 128 |
| 279 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 [[OR]] |
| 280 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 281 | ; |
| 282 | %trunc = trunc i32 %x to i8 |
| 283 | %cmp = icmp sgt i8 %trunc, -1 |
| 284 | %or = or i32 %x, 128 |
| 285 | %sel = select i1 %cmp, i32 %x, i32 %or |
| 286 | ret i32 %sel |
| 287 | } |
| 288 | |
| 289 | define i32 @select_icmp_trunc_8_eq_0_and_not_8(i32 %x) { |
| 290 | ; CHECK-LABEL: @select_icmp_trunc_8_eq_0_and_not_8( |
| 291 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i4 |
| 292 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i4 [[TRUNC]], -1 |
| 293 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, -9 |
| 294 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 [[AND]] |
| 295 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 296 | ; |
| 297 | %trunc = trunc i32 %x to i4 |
| 298 | %cmp = icmp sgt i4 %trunc, -1 |
| 299 | %and = and i32 %x, -9 |
| 300 | %sel = select i1 %cmp, i32 %x, i32 %and |
| 301 | ret i32 %sel |
| 302 | } |
| 303 | |
| 304 | define i32 @select_icmp_trunc_8_eq_0_and_not_8_alt(i32 %x) { |
| 305 | ; CHECK-LABEL: @select_icmp_trunc_8_eq_0_and_not_8_alt( |
| 306 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i4 |
| 307 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i4 [[TRUNC]], 0 |
| 308 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, -9 |
| 309 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[AND]], i32 %x |
| 310 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 311 | ; |
| 312 | %trunc = trunc i32 %x to i4 |
| 313 | %cmp = icmp slt i4 %trunc, 0 |
| 314 | %and = and i32 %x, -9 |
| 315 | %sel = select i1 %cmp, i32 %and, i32 %x |
| 316 | ret i32 %sel |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 319 | define i32 @select_icmp_trunc_8_ne_0_and_not_8(i32 %x) { |
| 320 | ; CHECK-LABEL: @select_icmp_trunc_8_ne_0_and_not_8( |
| 321 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i4 |
| 322 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i4 [[TRUNC]], 0 |
| 323 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, -9 |
| 324 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 [[AND]] |
| 325 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 326 | ; |
| 327 | %trunc = trunc i32 %x to i4 |
| 328 | %cmp = icmp slt i4 %trunc, 0 |
| 329 | %and = and i32 %x, -9 |
| 330 | %sel = select i1 %cmp, i32 %x, i32 %and |
| 331 | ret i32 %sel |
| 332 | } |
| 333 | |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 334 | define i32 @select_icmp_trunc_8_ne_0_and_not_8_alt(i32 %x) { |
| 335 | ; CHECK-LABEL: @select_icmp_trunc_8_ne_0_and_not_8_alt( |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 336 | ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i4 |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 337 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i4 [[TRUNC]], -1 |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 338 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, -9 |
| 339 | ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[AND]], i32 %x |
| 340 | ; CHECK-NEXT: ret i32 [[SEL]] |
| 341 | ; |
| 342 | %trunc = trunc i32 %x to i4 |
| Sanjay Patel | 47c04f9 | 2016-07-19 20:47:00 +0000 | [diff] [blame] | 343 | %cmp = icmp sgt i4 %trunc, -1 |
| Sanjay Patel | 8b76ebe | 2016-07-19 17:07:35 +0000 | [diff] [blame] | 344 | %and = and i32 %x, -9 |
| 345 | %sel = select i1 %cmp, i32 %and, i32 %x |
| 346 | ret i32 %sel |
| 347 | } |
| 348 | |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 349 | 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] | 350 | ; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8( |
| 351 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 8 |
| 352 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0 |
| 353 | ; CHECK-NEXT: [[AND1:%.*]] = and i64 %y, -9 |
| 354 | ; CHECK-NEXT: [[Y_AND1:%.*]] = select i1 [[CMP]], i64 %y, i64 [[AND1]] |
| 355 | ; CHECK-NEXT: ret i64 [[Y_AND1]] |
| 356 | ; |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 357 | %and = and i32 %x, 8 |
| 358 | %cmp = icmp eq i32 %and, 0 |
| 359 | %and1 = and i64 %y, -9 |
| 360 | %y.and1 = select i1 %cmp, i64 %y, i64 %and1 |
| 361 | ret i64 %y.and1 |
| 362 | } |
| 363 | |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 364 | 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] | 365 | ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8( |
| 366 | ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 8 |
| 367 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0 |
| 368 | ; CHECK-NEXT: [[AND1:%.*]] = and i64 %y, -9 |
| 369 | ; CHECK-NEXT: [[AND1_Y:%.*]] = select i1 [[CMP]], i64 [[AND1]], i64 %y |
| 370 | ; CHECK-NEXT: ret i64 [[AND1_Y]] |
| 371 | ; |
| David Majnemer | c6a5e1d | 2014-11-27 06:32:46 +0000 | [diff] [blame] | 372 | %and = and i32 %x, 8 |
| 373 | %cmp = icmp eq i32 %and, 0 |
| 374 | %and1 = and i64 %y, -9 |
| 375 | %and1.y = select i1 %cmp, i64 %and1, i64 %y |
| 376 | ret i64 %and1.y |
| 377 | } |
| 378 | |