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