1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i1 @and_consts(i32 %k, i32 %c1, i32 %c2) {
5 ; CHECK-LABEL: @and_consts(
6 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[K:%.*]], 12
7 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 12
8 ; CHECK-NEXT: ret i1 [[TMP2]]
11 %t2 = icmp eq i32 %t1, 0
13 %t6 = icmp eq i32 %t5, 0
18 define i1 @and_consts_logical(i32 %k, i32 %c1, i32 %c2) {
19 ; CHECK-LABEL: @and_consts_logical(
20 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[K:%.*]], 12
21 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 12
22 ; CHECK-NEXT: ret i1 [[TMP2]]
25 %t2 = icmp eq i32 %t1, 0
27 %t6 = icmp eq i32 %t5, 0
28 %or = select i1 %t2, i1 true, i1 %t6
32 define <2 x i1> @and_consts_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
33 ; CHECK-LABEL: @and_consts_vector(
34 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[K:%.*]], <i32 12, i32 12>
35 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne <2 x i32> [[TMP1]], <i32 12, i32 12>
36 ; CHECK-NEXT: ret <2 x i1> [[TMP2]]
38 %t1 = and <2 x i32> <i32 4, i32 4>, %k
39 %t2 = icmp eq <2 x i32> %t1, zeroinitializer
40 %t5 = and <2 x i32> <i32 8, i32 8>, %k
41 %t6 = icmp eq <2 x i32> %t5, zeroinitializer
42 %or = or <2 x i1> %t2, %t6
46 define i1 @foo1_and(i32 %k, i32 %c1, i32 %c2) {
47 ; CHECK-LABEL: @foo1_and(
48 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
49 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
50 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T]], [[T4]]
51 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
52 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
53 ; CHECK-NEXT: ret i1 [[TMP3]]
58 %t2 = icmp eq i32 %t1, 0
60 %t6 = icmp eq i32 %t5, 0
65 define i1 @foo1_and_logical(i32 %k, i32 %c1, i32 %c2) {
66 ; CHECK-LABEL: @foo1_and_logical(
67 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
68 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
69 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T4]]
70 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T]], [[TMP1]]
71 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K:%.*]]
72 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
73 ; CHECK-NEXT: ret i1 [[TMP4]]
78 %t2 = icmp eq i32 %t1, 0
80 %t6 = icmp eq i32 %t5, 0
81 %or = select i1 %t2, i1 true, i1 %t6
85 define <2 x i1> @foo1_and_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
86 ; CHECK-LABEL: @foo1_and_vector(
87 ; CHECK-NEXT: [[T:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C1:%.*]]
88 ; CHECK-NEXT: [[T4:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C2:%.*]]
89 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[T]], [[T4]]
90 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], [[K:%.*]]
91 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], [[TMP1]]
92 ; CHECK-NEXT: ret <2 x i1> [[TMP3]]
94 %t = shl <2 x i32> <i32 1, i32 1>, %c1
95 %t4 = shl <2 x i32> <i32 1, i32 1>, %c2
96 %t1 = and <2 x i32> %t, %k
97 %t2 = icmp eq <2 x i32> %t1, zeroinitializer
98 %t5 = and <2 x i32> %t4, %k
99 %t6 = icmp eq <2 x i32> %t5, zeroinitializer
100 %or = or <2 x i1> %t2, %t6
104 ; Same as above but with operands commuted one of the ands, but not the other.
105 define i1 @foo1_and_commuted(i32 %k, i32 %c1, i32 %c2) {
106 ; CHECK-LABEL: @foo1_and_commuted(
107 ; CHECK-NEXT: [[K2:%.*]] = mul i32 [[K:%.*]], [[K]]
108 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
109 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
110 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T]], [[T4]]
111 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[K2]], [[TMP1]]
112 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
113 ; CHECK-NEXT: ret i1 [[TMP3]]
115 %k2 = mul i32 %k, %k ; to trick the complexity sorting
118 %t1 = and i32 %k2, %t
119 %t2 = icmp eq i32 %t1, 0
120 %t5 = and i32 %t4, %k2
121 %t6 = icmp eq i32 %t5, 0
126 define i1 @foo1_and_commuted_logical(i32 %k, i32 %c1, i32 %c2) {
127 ; CHECK-LABEL: @foo1_and_commuted_logical(
128 ; CHECK-NEXT: [[K2:%.*]] = mul i32 [[K:%.*]], [[K]]
129 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
130 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
131 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T4]]
132 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T]], [[TMP1]]
133 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[K2]], [[TMP2]]
134 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
135 ; CHECK-NEXT: ret i1 [[TMP4]]
137 %k2 = mul i32 %k, %k ; to trick the complexity sorting
140 %t1 = and i32 %k2, %t
141 %t2 = icmp eq i32 %t1, 0
142 %t5 = and i32 %t4, %k2
143 %t6 = icmp eq i32 %t5, 0
144 %or = select i1 %t2, i1 true, i1 %t6
148 define <2 x i1> @foo1_and_commuted_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
149 ; CHECK-LABEL: @foo1_and_commuted_vector(
150 ; CHECK-NEXT: [[K2:%.*]] = mul <2 x i32> [[K:%.*]], [[K]]
151 ; CHECK-NEXT: [[T:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C1:%.*]]
152 ; CHECK-NEXT: [[T4:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C2:%.*]]
153 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[T]], [[T4]]
154 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[K2]], [[TMP1]]
155 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], [[TMP1]]
156 ; CHECK-NEXT: ret <2 x i1> [[TMP3]]
158 %k2 = mul <2 x i32> %k, %k ; to trick the complexity sorting
159 %t = shl <2 x i32> <i32 1, i32 1>, %c1
160 %t4 = shl <2 x i32> <i32 1, i32 1>, %c2
161 %t1 = and <2 x i32> %k2, %t
162 %t2 = icmp eq <2 x i32> %t1, zeroinitializer
163 %t5 = and <2 x i32> %t4, %k2
164 %t6 = icmp eq <2 x i32> %t5, zeroinitializer
165 %or = or <2 x i1> %t2, %t6
169 define i1 @or_consts(i32 %k, i32 %c1, i32 %c2) {
170 ; CHECK-LABEL: @or_consts(
171 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[K:%.*]], 12
172 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 12
173 ; CHECK-NEXT: ret i1 [[TMP2]]
176 %t2 = icmp ne i32 %t1, 0
178 %t6 = icmp ne i32 %t5, 0
179 %or = and i1 %t2, %t6
183 define i1 @or_consts_logical(i32 %k, i32 %c1, i32 %c2) {
184 ; CHECK-LABEL: @or_consts_logical(
185 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[K:%.*]], 12
186 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 12
187 ; CHECK-NEXT: ret i1 [[TMP2]]
190 %t2 = icmp ne i32 %t1, 0
192 %t6 = icmp ne i32 %t5, 0
193 %or = select i1 %t2, i1 %t6, i1 false
197 define <2 x i1> @or_consts_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
198 ; CHECK-LABEL: @or_consts_vector(
199 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[K:%.*]], <i32 12, i32 12>
200 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 12, i32 12>
201 ; CHECK-NEXT: ret <2 x i1> [[TMP2]]
203 %t1 = and <2 x i32> <i32 4, i32 4>, %k
204 %t2 = icmp ne <2 x i32> %t1, zeroinitializer
205 %t5 = and <2 x i32> <i32 8, i32 8>, %k
206 %t6 = icmp ne <2 x i32> %t5, zeroinitializer
207 %or = and <2 x i1> %t2, %t6
211 define i1 @foo1_or(i32 %k, i32 %c1, i32 %c2) {
212 ; CHECK-LABEL: @foo1_or(
213 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
214 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
215 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T]], [[T4]]
216 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
217 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], [[TMP1]]
218 ; CHECK-NEXT: ret i1 [[TMP3]]
223 %t2 = icmp ne i32 %t1, 0
224 %t5 = and i32 %t4, %k
225 %t6 = icmp ne i32 %t5, 0
226 %or = and i1 %t2, %t6
230 define i1 @foo1_or_logical(i32 %k, i32 %c1, i32 %c2) {
231 ; CHECK-LABEL: @foo1_or_logical(
232 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
233 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
234 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T4]]
235 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T]], [[TMP1]]
236 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K:%.*]]
237 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP3]], [[TMP2]]
238 ; CHECK-NEXT: ret i1 [[TMP4]]
243 %t2 = icmp ne i32 %t1, 0
244 %t5 = and i32 %t4, %k
245 %t6 = icmp ne i32 %t5, 0
246 %or = select i1 %t2, i1 %t6, i1 false
250 define <2 x i1> @foo1_or_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
251 ; CHECK-LABEL: @foo1_or_vector(
252 ; CHECK-NEXT: [[T:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C1:%.*]]
253 ; CHECK-NEXT: [[T4:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C2:%.*]]
254 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[T]], [[T4]]
255 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], [[K:%.*]]
256 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <2 x i32> [[TMP2]], [[TMP1]]
257 ; CHECK-NEXT: ret <2 x i1> [[TMP3]]
259 %t = shl <2 x i32> <i32 1, i32 1>, %c1
260 %t4 = shl <2 x i32> <i32 1, i32 1>, %c2
261 %t1 = and <2 x i32> %t, %k
262 %t2 = icmp ne <2 x i32> %t1, zeroinitializer
263 %t5 = and <2 x i32> %t4, %k
264 %t6 = icmp ne <2 x i32> %t5, zeroinitializer
265 %or = and <2 x i1> %t2, %t6
269 ; Same as above but with operands commuted one of the ors, but not the other.
270 define i1 @foo1_or_commuted(i32 %k, i32 %c1, i32 %c2) {
271 ; CHECK-LABEL: @foo1_or_commuted(
272 ; CHECK-NEXT: [[K2:%.*]] = mul i32 [[K:%.*]], [[K]]
273 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
274 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
275 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T]], [[T4]]
276 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[K2]], [[TMP1]]
277 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], [[TMP1]]
278 ; CHECK-NEXT: ret i1 [[TMP3]]
280 %k2 = mul i32 %k, %k ; to trick the complexity sorting
283 %t1 = and i32 %k2, %t
284 %t2 = icmp ne i32 %t1, 0
285 %t5 = and i32 %t4, %k2
286 %t6 = icmp ne i32 %t5, 0
287 %or = and i1 %t2, %t6
291 define i1 @foo1_or_commuted_logical(i32 %k, i32 %c1, i32 %c2) {
292 ; CHECK-LABEL: @foo1_or_commuted_logical(
293 ; CHECK-NEXT: [[K2:%.*]] = mul i32 [[K:%.*]], [[K]]
294 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
295 ; CHECK-NEXT: [[T4:%.*]] = shl i32 1, [[C2:%.*]]
296 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T4]]
297 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T]], [[TMP1]]
298 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[K2]], [[TMP2]]
299 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP3]], [[TMP2]]
300 ; CHECK-NEXT: ret i1 [[TMP4]]
302 %k2 = mul i32 %k, %k ; to trick the complexity sorting
305 %t1 = and i32 %k2, %t
306 %t2 = icmp ne i32 %t1, 0
307 %t5 = and i32 %t4, %k2
308 %t6 = icmp ne i32 %t5, 0
309 %or = select i1 %t2, i1 %t6, i1 false
313 define <2 x i1> @foo1_or_commuted_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
314 ; CHECK-LABEL: @foo1_or_commuted_vector(
315 ; CHECK-NEXT: [[K2:%.*]] = mul <2 x i32> [[K:%.*]], [[K]]
316 ; CHECK-NEXT: [[T:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C1:%.*]]
317 ; CHECK-NEXT: [[T4:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C2:%.*]]
318 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[T]], [[T4]]
319 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[K2]], [[TMP1]]
320 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <2 x i32> [[TMP2]], [[TMP1]]
321 ; CHECK-NEXT: ret <2 x i1> [[TMP3]]
323 %k2 = mul <2 x i32> %k, %k ; to trick the complexity sorting
324 %t = shl <2 x i32> <i32 1, i32 1>, %c1
325 %t4 = shl <2 x i32> <i32 1, i32 1>, %c2
326 %t1 = and <2 x i32> %k2, %t
327 %t2 = icmp ne <2 x i32> %t1, zeroinitializer
328 %t5 = and <2 x i32> %t4, %k2
329 %t6 = icmp ne <2 x i32> %t5, zeroinitializer
330 %or = and <2 x i1> %t2, %t6
334 define i1 @foo1_and_signbit_lshr(i32 %k, i32 %c1, i32 %c2) {
335 ; CHECK-LABEL: @foo1_and_signbit_lshr(
336 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
337 ; CHECK-NEXT: [[T4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
338 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T]], [[T4]]
339 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
340 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
341 ; CHECK-NEXT: ret i1 [[TMP3]]
344 %t4 = lshr i32 -2147483648, %c2
346 %t2 = icmp eq i32 %t1, 0
347 %t5 = and i32 %t4, %k
348 %t6 = icmp eq i32 %t5, 0
353 define i1 @foo1_and_signbit_lshr_logical(i32 %k, i32 %c1, i32 %c2) {
354 ; CHECK-LABEL: @foo1_and_signbit_lshr_logical(
355 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
356 ; CHECK-NEXT: [[T4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
357 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T4]]
358 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T]], [[TMP1]]
359 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K:%.*]]
360 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
361 ; CHECK-NEXT: ret i1 [[TMP4]]
364 %t4 = lshr i32 -2147483648, %c2
366 %t2 = icmp eq i32 %t1, 0
367 %t5 = and i32 %t4, %k
368 %t6 = icmp eq i32 %t5, 0
369 %or = select i1 %t2, i1 true, i1 %t6
373 define <2 x i1> @foo1_and_signbit_lshr_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
374 ; CHECK-LABEL: @foo1_and_signbit_lshr_vector(
375 ; CHECK-NEXT: [[T:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C1:%.*]]
376 ; CHECK-NEXT: [[T4:%.*]] = lshr <2 x i32> <i32 -2147483648, i32 -2147483648>, [[C2:%.*]]
377 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[T]], [[T4]]
378 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], [[K:%.*]]
379 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], [[TMP1]]
380 ; CHECK-NEXT: ret <2 x i1> [[TMP3]]
382 %t = shl <2 x i32> <i32 1, i32 1>, %c1
383 %t4 = lshr <2 x i32> <i32 -2147483648, i32 -2147483648>, %c2
384 %t1 = and <2 x i32> %t, %k
385 %t2 = icmp eq <2 x i32> %t1, zeroinitializer
386 %t5 = and <2 x i32> %t4, %k
387 %t6 = icmp eq <2 x i32> %t5, zeroinitializer
388 %or = or <2 x i1> %t2, %t6
392 define i1 @foo1_or_signbit_lshr(i32 %k, i32 %c1, i32 %c2) {
393 ; CHECK-LABEL: @foo1_or_signbit_lshr(
394 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
395 ; CHECK-NEXT: [[T4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
396 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T]], [[T4]]
397 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
398 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], [[TMP1]]
399 ; CHECK-NEXT: ret i1 [[TMP3]]
402 %t4 = lshr i32 -2147483648, %c2
404 %t2 = icmp ne i32 %t1, 0
405 %t5 = and i32 %t4, %k
406 %t6 = icmp ne i32 %t5, 0
407 %or = and i1 %t2, %t6
411 define i1 @foo1_or_signbit_lshr_logical(i32 %k, i32 %c1, i32 %c2) {
412 ; CHECK-LABEL: @foo1_or_signbit_lshr_logical(
413 ; CHECK-NEXT: [[T:%.*]] = shl i32 1, [[C1:%.*]]
414 ; CHECK-NEXT: [[T4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
415 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T4]]
416 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T]], [[TMP1]]
417 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K:%.*]]
418 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP3]], [[TMP2]]
419 ; CHECK-NEXT: ret i1 [[TMP4]]
422 %t4 = lshr i32 -2147483648, %c2
424 %t2 = icmp ne i32 %t1, 0
425 %t5 = and i32 %t4, %k
426 %t6 = icmp ne i32 %t5, 0
427 %or = select i1 %t2, i1 %t6, i1 false
431 define <2 x i1> @foo1_or_signbit_lshr_vector(<2 x i32> %k, <2 x i32> %c1, <2 x i32> %c2) {
432 ; CHECK-LABEL: @foo1_or_signbit_lshr_vector(
433 ; CHECK-NEXT: [[T:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[C1:%.*]]
434 ; CHECK-NEXT: [[T4:%.*]] = lshr <2 x i32> <i32 -2147483648, i32 -2147483648>, [[C2:%.*]]
435 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[T]], [[T4]]
436 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], [[K:%.*]]
437 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <2 x i32> [[TMP2]], [[TMP1]]
438 ; CHECK-NEXT: ret <2 x i1> [[TMP3]]
440 %t = shl <2 x i32> <i32 1, i32 1>, %c1
441 %t4 = lshr <2 x i32> <i32 -2147483648, i32 -2147483648>, %c2
442 %t1 = and <2 x i32> %t, %k
443 %t2 = icmp ne <2 x i32> %t1, zeroinitializer
444 %t5 = and <2 x i32> %t4, %k
445 %t6 = icmp ne <2 x i32> %t5, zeroinitializer
446 %or = and <2 x i1> %t2, %t6
450 ; Same as last two, but shift-of-signbit replaced with 'icmp s*'
451 define i1 @foo1_and_signbit_lshr_without_shifting_signbit(i32 %k, i32 %c1, i32 %c2) {
452 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit(
453 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
454 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
455 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
456 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
457 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
458 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
459 ; CHECK-NEXT: ret i1 [[OR]]
462 %t1 = and i32 %t0, %k
463 %t2 = icmp eq i32 %t1, 0
464 %t3 = shl i32 %k, %c2
465 %t4 = icmp sgt i32 %t3, -1
470 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_logical(i32 %k, i32 %c1, i32 %c2) {
471 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_logical(
472 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
473 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
474 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
475 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
476 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
477 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
478 ; CHECK-NEXT: ret i1 [[OR]]
481 %t1 = and i32 %t0, %k
482 %t2 = icmp eq i32 %t1, 0
483 %t3 = shl i32 %k, %c2
484 %t4 = icmp sgt i32 %t3, -1
485 %or = select i1 %t2, i1 true, i1 %t4
489 define i1 @foo1_or_signbit_lshr_without_shifting_signbit(i32 %k, i32 %c1, i32 %c2) {
490 ; CHECK-LABEL: @foo1_or_signbit_lshr_without_shifting_signbit(
491 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
492 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
493 ; CHECK-NEXT: [[T2:%.*]] = icmp ne i32 [[T1]], 0
494 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
495 ; CHECK-NEXT: [[T4:%.*]] = icmp slt i32 [[T3]], 0
496 ; CHECK-NEXT: [[OR:%.*]] = and i1 [[T2]], [[T4]]
497 ; CHECK-NEXT: ret i1 [[OR]]
500 %t1 = and i32 %t0, %k
501 %t2 = icmp ne i32 %t1, 0
502 %t3 = shl i32 %k, %c2
503 %t4 = icmp slt i32 %t3, 0
504 %or = and i1 %t2, %t4
508 define i1 @foo1_or_signbit_lshr_without_shifting_signbit_logical(i32 %k, i32 %c1, i32 %c2) {
509 ; CHECK-LABEL: @foo1_or_signbit_lshr_without_shifting_signbit_logical(
510 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
511 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
512 ; CHECK-NEXT: [[T2:%.*]] = icmp ne i32 [[T1]], 0
513 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
514 ; CHECK-NEXT: [[T4:%.*]] = icmp slt i32 [[T3]], 0
515 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 [[T4]], i1 false
516 ; CHECK-NEXT: ret i1 [[OR]]
519 %t1 = and i32 %t0, %k
520 %t2 = icmp ne i32 %t1, 0
521 %t3 = shl i32 %k, %c2
522 %t4 = icmp slt i32 %t3, 0
523 %or = select i1 %t2, i1 %t4, i1 false
527 ; Shift-of-signbit replaced with 'icmp s*' for both sides
528 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_both_sides(i32 %k, i32 %c1, i32 %c2) {
529 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_both_sides(
530 ; CHECK-NEXT: [[T0:%.*]] = shl i32 [[K:%.*]], [[C1:%.*]]
531 ; CHECK-NEXT: [[T2:%.*]] = shl i32 [[K]], [[C2:%.*]]
532 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[T0]], [[T2]]
533 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], -1
534 ; CHECK-NEXT: ret i1 [[TMP2]]
536 %t0 = shl i32 %k, %c1
537 %t1 = icmp sgt i32 %t0, -1
538 %t2 = shl i32 %k, %c2
539 %t3 = icmp sgt i32 %t2, -1
544 ; %t2 can be poison where as %t0 isn't; merging these two is unsafe.
545 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_both_sides_logical(i32 %k, i32 %c1, i32 %c2) {
546 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_both_sides_logical(
547 ; CHECK-NEXT: [[T0:%.*]] = shl i32 [[K:%.*]], [[C1:%.*]]
548 ; CHECK-NEXT: [[T1:%.*]] = icmp sgt i32 [[T0]], -1
549 ; CHECK-NEXT: [[T2:%.*]] = shl i32 [[K]], [[C2:%.*]]
550 ; CHECK-NEXT: [[T3:%.*]] = icmp sgt i32 [[T2]], -1
551 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T1]], i1 true, i1 [[T3]]
552 ; CHECK-NEXT: ret i1 [[OR]]
554 %t0 = shl i32 %k, %c1
555 %t1 = icmp sgt i32 %t0, -1
556 %t2 = shl i32 %k, %c2
557 %t3 = icmp sgt i32 %t2, -1
558 %or = select i1 %t1, i1 true, i1 %t3
562 define i1 @foo1_or_signbit_lshr_without_shifting_signbit_both_sides(i32 %k, i32 %c1, i32 %c2) {
563 ; CHECK-LABEL: @foo1_or_signbit_lshr_without_shifting_signbit_both_sides(
564 ; CHECK-NEXT: [[T0:%.*]] = shl i32 [[K:%.*]], [[C1:%.*]]
565 ; CHECK-NEXT: [[T2:%.*]] = shl i32 [[K]], [[C2:%.*]]
566 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[T0]], [[T2]]
567 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
568 ; CHECK-NEXT: ret i1 [[TMP2]]
570 %t0 = shl i32 %k, %c1
571 %t1 = icmp slt i32 %t0, 0
572 %t2 = shl i32 %k, %c2
573 %t3 = icmp slt i32 %t2, 0
574 %or = and i1 %t1, %t3
578 ; %t2 can be poison where as %t0 isn't; merging these two is unsafe.
579 define i1 @foo1_or_signbit_lshr_without_shifting_signbit_both_sides_logical(i32 %k, i32 %c1, i32 %c2) {
580 ; CHECK-LABEL: @foo1_or_signbit_lshr_without_shifting_signbit_both_sides_logical(
581 ; CHECK-NEXT: [[T0:%.*]] = shl i32 [[K:%.*]], [[C1:%.*]]
582 ; CHECK-NEXT: [[T1:%.*]] = icmp slt i32 [[T0]], 0
583 ; CHECK-NEXT: [[T2:%.*]] = shl i32 [[K]], [[C2:%.*]]
584 ; CHECK-NEXT: [[T3:%.*]] = icmp slt i32 [[T2]], 0
585 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T1]], i1 [[T3]], i1 false
586 ; CHECK-NEXT: ret i1 [[OR]]
588 %t0 = shl i32 %k, %c1
589 %t1 = icmp slt i32 %t0, 0
590 %t2 = shl i32 %k, %c2
591 %t3 = icmp slt i32 %t2, 0
592 %or = select i1 %t1, i1 %t3, i1 false
599 define i1 @foo1_and_extra_use_shl(i32 %k, i32 %c1, i32 %c2, i32* %p) {
600 ; CHECK-LABEL: @foo1_and_extra_use_shl(
601 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
602 ; CHECK-NEXT: store i32 [[T0]], i32* [[P:%.*]], align 4
603 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
604 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T0]], [[T1]]
605 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
606 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
607 ; CHECK-NEXT: ret i1 [[TMP3]]
610 store i32 %t0, i32* %p ; extra use of shl
612 %t2 = and i32 %t0, %k
613 %t3 = icmp eq i32 %t2, 0
614 %t4 = and i32 %t1, %k
615 %t5 = icmp eq i32 %t4, 0
620 define i1 @foo1_and_extra_use_shl_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
621 ; CHECK-LABEL: @foo1_and_extra_use_shl_logical(
622 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
623 ; CHECK-NEXT: store i32 [[T0]], i32* [[P:%.*]], align 4
624 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
625 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T1]]
626 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T0]], [[TMP1]]
627 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K:%.*]]
628 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
629 ; CHECK-NEXT: ret i1 [[TMP4]]
632 store i32 %t0, i32* %p ; extra use of shl
634 %t2 = and i32 %t0, %k
635 %t3 = icmp eq i32 %t2, 0
636 %t4 = and i32 %t1, %k
637 %t5 = icmp eq i32 %t4, 0
638 %or = select i1 %t3, i1 true, i1 %t5
643 define i1 @foo1_and_extra_use_and(i32 %k, i32 %c1, i32 %c2, i32* %p) {
644 ; CHECK-LABEL: @foo1_and_extra_use_and(
645 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
646 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
647 ; CHECK-NEXT: [[T2:%.*]] = and i32 [[T0]], [[K:%.*]]
648 ; CHECK-NEXT: store i32 [[T2]], i32* [[P:%.*]], align 4
649 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T0]], [[T1]]
650 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K]]
651 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
652 ; CHECK-NEXT: ret i1 [[TMP3]]
656 %t2 = and i32 %t0, %k
657 store i32 %t2, i32* %p ; extra use of and
658 %t3 = icmp eq i32 %t2, 0
659 %t4 = and i32 %t1, %k
660 %t5 = icmp eq i32 %t4, 0
665 define i1 @foo1_and_extra_use_and_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
666 ; CHECK-LABEL: @foo1_and_extra_use_and_logical(
667 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
668 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
669 ; CHECK-NEXT: [[T2:%.*]] = and i32 [[T0]], [[K:%.*]]
670 ; CHECK-NEXT: store i32 [[T2]], i32* [[P:%.*]], align 4
671 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T1]]
672 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T0]], [[TMP1]]
673 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K]]
674 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
675 ; CHECK-NEXT: ret i1 [[TMP4]]
679 %t2 = and i32 %t0, %k
680 store i32 %t2, i32* %p ; extra use of and
681 %t3 = icmp eq i32 %t2, 0
682 %t4 = and i32 %t1, %k
683 %t5 = icmp eq i32 %t4, 0
684 %or = select i1 %t3, i1 true, i1 %t5
689 define i1 @foo1_and_extra_use_cmp(i32 %k, i32 %c1, i32 %c2, i1* %p) {
690 ; CHECK-LABEL: @foo1_and_extra_use_cmp(
691 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
692 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
693 ; CHECK-NEXT: [[T2:%.*]] = and i32 [[T0]], [[K:%.*]]
694 ; CHECK-NEXT: [[T3:%.*]] = icmp eq i32 [[T2]], 0
695 ; CHECK-NEXT: store i1 [[T3]], i1* [[P:%.*]], align 1
696 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T0]], [[T1]]
697 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K]]
698 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
699 ; CHECK-NEXT: ret i1 [[TMP3]]
703 %t2 = and i32 %t0, %k
704 %t3 = icmp eq i32 %t2, 0
705 store i1 %t3, i1* %p ; extra use of cmp
706 %t4 = and i32 %t1, %k
707 %t5 = icmp eq i32 %t4, 0
712 define i1 @foo1_and_extra_use_cmp_logical(i32 %k, i32 %c1, i32 %c2, i1* %p) {
713 ; CHECK-LABEL: @foo1_and_extra_use_cmp_logical(
714 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
715 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
716 ; CHECK-NEXT: [[T2:%.*]] = and i32 [[T0]], [[K:%.*]]
717 ; CHECK-NEXT: [[T3:%.*]] = icmp eq i32 [[T2]], 0
718 ; CHECK-NEXT: store i1 [[T3]], i1* [[P:%.*]], align 1
719 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T1]]
720 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T0]], [[TMP1]]
721 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K]]
722 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
723 ; CHECK-NEXT: ret i1 [[TMP4]]
727 %t2 = and i32 %t0, %k
728 %t3 = icmp eq i32 %t2, 0
729 store i1 %t3, i1* %p ; extra use of cmp
730 %t4 = and i32 %t1, %k
731 %t5 = icmp eq i32 %t4, 0
732 %or = select i1 %t3, i1 true, i1 %t5
737 define i1 @foo1_and_extra_use_shl2(i32 %k, i32 %c1, i32 %c2, i32* %p) {
738 ; CHECK-LABEL: @foo1_and_extra_use_shl2(
739 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
740 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
741 ; CHECK-NEXT: store i32 [[T1]], i32* [[P:%.*]], align 4
742 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T0]], [[T1]]
743 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
744 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
745 ; CHECK-NEXT: ret i1 [[TMP3]]
749 store i32 %t1, i32* %p ; extra use of shl
750 %t2 = and i32 %t0, %k
751 %t3 = icmp eq i32 %t2, 0
752 %t4 = and i32 %t1, %k
753 %t5 = icmp eq i32 %t4, 0
758 define i1 @foo1_and_extra_use_shl2_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
759 ; CHECK-LABEL: @foo1_and_extra_use_shl2_logical(
760 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
761 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
762 ; CHECK-NEXT: store i32 [[T1]], i32* [[P:%.*]], align 4
763 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T1]]
764 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T0]], [[TMP1]]
765 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K:%.*]]
766 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
767 ; CHECK-NEXT: ret i1 [[TMP4]]
771 store i32 %t1, i32* %p ; extra use of shl
772 %t2 = and i32 %t0, %k
773 %t3 = icmp eq i32 %t2, 0
774 %t4 = and i32 %t1, %k
775 %t5 = icmp eq i32 %t4, 0
776 %or = select i1 %t3, i1 true, i1 %t5
781 define i1 @foo1_and_extra_use_and2(i32 %k, i32 %c1, i32 %c2, i32* %p) {
782 ; CHECK-LABEL: @foo1_and_extra_use_and2(
783 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
784 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
785 ; CHECK-NEXT: [[T4:%.*]] = and i32 [[T1]], [[K:%.*]]
786 ; CHECK-NEXT: store i32 [[T4]], i32* [[P:%.*]], align 4
787 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T0]], [[T1]]
788 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K]]
789 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
790 ; CHECK-NEXT: ret i1 [[TMP3]]
794 %t2 = and i32 %t0, %k
795 %t3 = icmp eq i32 %t2, 0
796 %t4 = and i32 %t1, %k
797 store i32 %t4, i32* %p ; extra use of and
798 %t5 = icmp eq i32 %t4, 0
803 define i1 @foo1_and_extra_use_and2_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
804 ; CHECK-LABEL: @foo1_and_extra_use_and2_logical(
805 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
806 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
807 ; CHECK-NEXT: [[T4:%.*]] = and i32 [[T1]], [[K:%.*]]
808 ; CHECK-NEXT: store i32 [[T4]], i32* [[P:%.*]], align 4
809 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T1]]
810 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T0]], [[TMP1]]
811 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K]]
812 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
813 ; CHECK-NEXT: ret i1 [[TMP4]]
817 %t2 = and i32 %t0, %k
818 %t3 = icmp eq i32 %t2, 0
819 %t4 = and i32 %t1, %k
820 store i32 %t4, i32* %p ; extra use of and
821 %t5 = icmp eq i32 %t4, 0
822 %or = select i1 %t3, i1 true, i1 %t5
827 define i1 @foo1_and_extra_use_cmp2(i32 %k, i32 %c1, i32 %c2, i1* %p) {
828 ; CHECK-LABEL: @foo1_and_extra_use_cmp2(
829 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
830 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
831 ; CHECK-NEXT: [[T4:%.*]] = and i32 [[T1]], [[K:%.*]]
832 ; CHECK-NEXT: [[T5:%.*]] = icmp eq i32 [[T4]], 0
833 ; CHECK-NEXT: store i1 [[T5]], i1* [[P:%.*]], align 1
834 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T0]], [[T1]]
835 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], [[K]]
836 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], [[TMP1]]
837 ; CHECK-NEXT: ret i1 [[TMP3]]
841 %t2 = and i32 %t0, %k
842 %t3 = icmp eq i32 %t2, 0
843 %t4 = and i32 %t1, %k
844 %t5 = icmp eq i32 %t4, 0
845 store i1 %t5, i1* %p ; extra use of cmp
850 define i1 @foo1_and_extra_use_cmp2_logical(i32 %k, i32 %c1, i32 %c2, i1* %p) {
851 ; CHECK-LABEL: @foo1_and_extra_use_cmp2_logical(
852 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
853 ; CHECK-NEXT: [[T1:%.*]] = shl i32 1, [[C2:%.*]]
854 ; CHECK-NEXT: [[T4:%.*]] = and i32 [[T1]], [[K:%.*]]
855 ; CHECK-NEXT: [[T5:%.*]] = icmp eq i32 [[T4]], 0
856 ; CHECK-NEXT: store i1 [[T5]], i1* [[P:%.*]], align 1
857 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[T1]]
858 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[T0]], [[TMP1]]
859 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[K]]
860 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], [[TMP2]]
861 ; CHECK-NEXT: ret i1 [[TMP4]]
865 %t2 = and i32 %t0, %k
866 %t3 = icmp eq i32 %t2, 0
867 %t4 = and i32 %t1, %k
868 %t5 = icmp eq i32 %t4, 0
869 store i1 %t5, i1* %p ; extra use of cmp
870 %or = select i1 %t3, i1 true, i1 %t5
874 ; Shift-of-signbit replaced with 'icmp s*'
876 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl1(i32 %k, i32 %c1, i32 %c2, i32* %p) {
877 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl1(
878 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
879 ; CHECK-NEXT: store i32 [[T0]], i32* [[P:%.*]], align 4
880 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
881 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
882 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
883 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
884 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
885 ; CHECK-NEXT: ret i1 [[OR]]
888 store i32 %t0, i32* %p ; extra use of shl
889 %t1 = and i32 %t0, %k
890 %t2 = icmp eq i32 %t1, 0
891 %t3 = shl i32 %k, %c2
892 %t4 = icmp sgt i32 %t3, -1
897 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl1_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
898 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl1_logical(
899 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
900 ; CHECK-NEXT: store i32 [[T0]], i32* [[P:%.*]], align 4
901 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
902 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
903 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
904 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
905 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
906 ; CHECK-NEXT: ret i1 [[OR]]
909 store i32 %t0, i32* %p ; extra use of shl
910 %t1 = and i32 %t0, %k
911 %t2 = icmp eq i32 %t1, 0
912 %t3 = shl i32 %k, %c2
913 %t4 = icmp sgt i32 %t3, -1
914 %or = select i1 %t2, i1 true, i1 %t4
919 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_and(i32 %k, i32 %c1, i32 %c2, i32* %p) {
920 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_and(
921 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
922 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
923 ; CHECK-NEXT: store i32 [[T1]], i32* [[P:%.*]], align 4
924 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
925 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
926 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
927 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
928 ; CHECK-NEXT: ret i1 [[OR]]
931 %t1 = and i32 %t0, %k
932 store i32 %t1, i32* %p ; extra use of and
933 %t2 = icmp eq i32 %t1, 0
934 %t3 = shl i32 %k, %c2
935 %t4 = icmp sgt i32 %t3, -1
940 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_and_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
941 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_and_logical(
942 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
943 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
944 ; CHECK-NEXT: store i32 [[T1]], i32* [[P:%.*]], align 4
945 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
946 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
947 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
948 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
949 ; CHECK-NEXT: ret i1 [[OR]]
952 %t1 = and i32 %t0, %k
953 store i32 %t1, i32* %p ; extra use of and
954 %t2 = icmp eq i32 %t1, 0
955 %t3 = shl i32 %k, %c2
956 %t4 = icmp sgt i32 %t3, -1
957 %or = select i1 %t2, i1 true, i1 %t4
962 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp1(i32 %k, i32 %c1, i32 %c2, i1* %p) {
963 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp1(
964 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
965 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
966 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
967 ; CHECK-NEXT: store i1 [[T2]], i1* [[P:%.*]], align 1
968 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
969 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
970 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
971 ; CHECK-NEXT: ret i1 [[OR]]
974 %t1 = and i32 %t0, %k
975 %t2 = icmp eq i32 %t1, 0
976 store i1 %t2, i1* %p ; extra use of cmp
977 %t3 = shl i32 %k, %c2
978 %t4 = icmp sgt i32 %t3, -1
983 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp1_logical(i32 %k, i32 %c1, i32 %c2, i1* %p) {
984 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp1_logical(
985 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
986 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
987 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
988 ; CHECK-NEXT: store i1 [[T2]], i1* [[P:%.*]], align 1
989 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
990 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
991 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
992 ; CHECK-NEXT: ret i1 [[OR]]
995 %t1 = and i32 %t0, %k
996 %t2 = icmp eq i32 %t1, 0
997 store i1 %t2, i1* %p ; extra use of cmp
998 %t3 = shl i32 %k, %c2
999 %t4 = icmp sgt i32 %t3, -1
1000 %or = select i1 %t2, i1 true, i1 %t4
1005 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl2(i32 %k, i32 %c1, i32 %c2, i32* %p) {
1006 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl2(
1007 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
1008 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
1009 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
1010 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
1011 ; CHECK-NEXT: store i32 [[T3]], i32* [[P:%.*]], align 4
1012 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
1013 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
1014 ; CHECK-NEXT: ret i1 [[OR]]
1016 %t0 = shl i32 1, %c1
1017 %t1 = and i32 %t0, %k
1018 %t2 = icmp eq i32 %t1, 0
1019 %t3 = shl i32 %k, %c2
1020 store i32 %t3, i32* %p ; extra use of shl
1021 %t4 = icmp sgt i32 %t3, -1
1022 %or = or i1 %t2, %t4
1026 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl2_logical(i32 %k, i32 %c1, i32 %c2, i32* %p) {
1027 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_shl2_logical(
1028 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
1029 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
1030 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
1031 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
1032 ; CHECK-NEXT: store i32 [[T3]], i32* [[P:%.*]], align 4
1033 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
1034 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
1035 ; CHECK-NEXT: ret i1 [[OR]]
1037 %t0 = shl i32 1, %c1
1038 %t1 = and i32 %t0, %k
1039 %t2 = icmp eq i32 %t1, 0
1040 %t3 = shl i32 %k, %c2
1041 store i32 %t3, i32* %p ; extra use of shl
1042 %t4 = icmp sgt i32 %t3, -1
1043 %or = select i1 %t2, i1 true, i1 %t4
1048 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp2(i32 %k, i32 %c1, i32 %c2, i1* %p) {
1049 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp2(
1050 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
1051 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
1052 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
1053 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
1054 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
1055 ; CHECK-NEXT: store i1 [[T4]], i1* [[P:%.*]], align 1
1056 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
1057 ; CHECK-NEXT: ret i1 [[OR]]
1059 %t0 = shl i32 1, %c1
1060 %t1 = and i32 %t0, %k
1061 %t2 = icmp eq i32 %t1, 0
1062 %t3 = shl i32 %k, %c2
1063 %t4 = icmp sgt i32 %t3, -1
1064 store i1 %t4, i1* %p ; extra use of cmp
1065 %or = or i1 %t2, %t4
1069 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp2_logical(i32 %k, i32 %c1, i32 %c2, i1* %p) {
1070 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_extra_use_cmp2_logical(
1071 ; CHECK-NEXT: [[T0:%.*]] = shl i32 1, [[C1:%.*]]
1072 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
1073 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
1074 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
1075 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
1076 ; CHECK-NEXT: store i1 [[T4]], i1* [[P:%.*]], align 1
1077 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
1078 ; CHECK-NEXT: ret i1 [[OR]]
1080 %t0 = shl i32 1, %c1
1081 %t1 = and i32 %t0, %k
1082 %t2 = icmp eq i32 %t1, 0
1083 %t3 = shl i32 %k, %c2
1084 %t4 = icmp sgt i32 %t3, -1
1085 store i1 %t4, i1* %p ; extra use of cmp
1086 %or = select i1 %t2, i1 true, i1 %t4
1092 ; This test checks that we are not creating additional shift instruction when fold fails.
1093 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_not_pwr2(i32 %k, i32 %c1, i32 %c2) {
1094 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_not_pwr2(
1095 ; CHECK-NEXT: [[T0:%.*]] = shl i32 3, [[C1:%.*]]
1096 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
1097 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
1098 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
1099 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
1100 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T2]], [[T4]]
1101 ; CHECK-NEXT: ret i1 [[OR]]
1103 %t0 = shl i32 3, %c1
1104 %t1 = and i32 %t0, %k
1105 %t2 = icmp eq i32 %t1, 0
1106 %t3 = shl i32 %k, %c2
1107 %t4 = icmp sgt i32 %t3, -1
1108 %or = or i1 %t2, %t4
1112 define i1 @foo1_and_signbit_lshr_without_shifting_signbit_not_pwr2_logical(i32 %k, i32 %c1, i32 %c2) {
1113 ; CHECK-LABEL: @foo1_and_signbit_lshr_without_shifting_signbit_not_pwr2_logical(
1114 ; CHECK-NEXT: [[T0:%.*]] = shl i32 3, [[C1:%.*]]
1115 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], [[K:%.*]]
1116 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
1117 ; CHECK-NEXT: [[T3:%.*]] = shl i32 [[K]], [[C2:%.*]]
1118 ; CHECK-NEXT: [[T4:%.*]] = icmp sgt i32 [[T3]], -1
1119 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T2]], i1 true, i1 [[T4]]
1120 ; CHECK-NEXT: ret i1 [[OR]]
1122 %t0 = shl i32 3, %c1
1123 %t1 = and i32 %t0, %k
1124 %t2 = icmp eq i32 %t1, 0
1125 %t3 = shl i32 %k, %c2
1126 %t4 = icmp sgt i32 %t3, -1
1127 %or = select i1 %t2, i1 true, i1 %t4