1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Tests to make sure elimination of casts is working correctly
3 ; RUN: opt < %s -passes=instcombine -S -data-layout="E-p:64:64:64-p1:32:32:32-p2:64:64:64-p3:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64" | FileCheck %s --check-prefixes=ALL,BE
4 ; RUN: opt < %s -passes=instcombine -S -data-layout="e-p:64:64:64-p1:32:32:32-p2:64:64:64-p3:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64" | FileCheck %s --check-prefixes=ALL,LE
6 declare void @use_i32(i32)
7 declare void @use_v2i32(<2 x i32>)
9 @inbuf = external global [32832 x i8]
11 define i32 @test1(i32 %A) {
13 ; ALL-NEXT: ret i32 [[A:%.*]]
15 %c1 = bitcast i32 %A to i32
16 %c2 = bitcast i32 %c1 to i32
20 define i64 @test2(i8 %A) {
22 ; ALL-NEXT: [[RET:%.*]] = zext i8 [[A:%.*]] to i64
23 ; ALL-NEXT: ret i64 [[RET]]
25 %c1 = zext i8 %A to i16
26 %c2 = zext i16 %c1 to i32
27 %Ret = zext i32 %c2 to i64
31 define i64 @test3(i64 %A) {
33 ; ALL-NEXT: [[C2:%.*]] = and i64 [[A:%.*]], 255
34 ; ALL-NEXT: ret i64 [[C2]]
36 %c1 = trunc i64 %A to i8
37 %c2 = zext i8 %c1 to i64
41 define i32 @test4(i32 %A, i32 %B) {
43 ; ALL-NEXT: [[COND:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]
44 ; ALL-NEXT: [[RESULT:%.*]] = zext i1 [[COND]] to i32
45 ; ALL-NEXT: ret i32 [[RESULT]]
47 %COND = icmp slt i32 %A, %B
48 %c = zext i1 %COND to i8
49 %result = zext i8 %c to i32
53 define i32 @test5(i1 %B) {
55 ; ALL-NEXT: [[RESULT:%.*]] = zext i1 [[B:%.*]] to i32
56 ; ALL-NEXT: ret i32 [[RESULT]]
59 %result = zext i8 %c to i32
63 define i32 @test6(i64 %A) {
65 ; ALL-NEXT: [[C1:%.*]] = trunc i64 [[A:%.*]] to i32
66 ; ALL-NEXT: ret i32 [[C1]]
68 %c1 = trunc i64 %A to i32
69 %res = bitcast i32 %c1 to i32
73 define i64 @test7(i1 %A) {
75 ; ALL-NEXT: [[RES:%.*]] = zext i1 [[A:%.*]] to i64
76 ; ALL-NEXT: ret i64 [[RES]]
78 %c1 = zext i1 %A to i32
79 %res = sext i32 %c1 to i64
83 define i64 @test8(i8 %A) {
85 ; ALL-NEXT: [[C1:%.*]] = sext i8 [[A:%.*]] to i64
86 ; ALL-NEXT: ret i64 [[C1]]
88 %c1 = sext i8 %A to i64
89 %res = bitcast i64 %c1 to i64
93 define i16 @test9(i16 %A) {
95 ; ALL-NEXT: ret i16 [[A:%.*]]
97 %c1 = sext i16 %A to i32
98 %c2 = trunc i32 %c1 to i16
102 define i16 @test10(i16 %A) {
103 ; ALL-LABEL: @test10(
104 ; ALL-NEXT: ret i16 [[A:%.*]]
106 %c1 = sext i16 %A to i32
107 %c2 = trunc i32 %c1 to i16
111 declare void @varargs(i32, ...)
113 define void @test11(ptr %P) {
114 ; ALL-LABEL: @test11(
115 ; ALL-NEXT: call void (i32, ...) @varargs(i32 5, ptr [[P:%.*]])
118 call void (i32, ...) @varargs( i32 5, ptr %P )
122 declare i32 @__gxx_personality_v0(...)
123 define void @test_invoke_vararg_cast(ptr %a, ptr %b) personality ptr @__gxx_personality_v0 {
124 ; ALL-LABEL: @test_invoke_vararg_cast(
126 ; ALL-NEXT: invoke void (i32, ...) @varargs(i32 1, ptr [[B:%.*]], ptr [[A:%.*]])
127 ; ALL-NEXT: to label [[INVOKE_CONT:%.*]] unwind label [[LPAD:%.*]]
131 ; ALL-NEXT: [[TMP0:%.*]] = landingpad { ptr, i32 }
136 invoke void (i32, ...) @varargs(i32 1, ptr %b, ptr %a)
137 to label %invoke.cont unwind label %lpad
143 %0 = landingpad { ptr, i32 }
148 define ptr @test13(i64 %A) {
149 ; ALL-LABEL: @test13(
150 ; ALL-NEXT: [[C:%.*]] = getelementptr [0 x i8], ptr @inbuf, i64 0, i64 [[A:%.*]]
151 ; ALL-NEXT: ret ptr [[C]]
153 %c = getelementptr [0 x i8], ptr @inbuf, i64 0, i64 %A
157 define i1 @test14(i8 %A) {
158 ; ALL-LABEL: @test14(
159 ; ALL-NEXT: [[X:%.*]] = icmp sgt i8 [[A:%.*]], -1
160 ; ALL-NEXT: ret i1 [[X]]
162 %c = bitcast i8 %A to i8
163 %X = icmp ult i8 %c, -128
168 ; This just won't occur when there's no difference between ubyte and sbyte
169 ;bool %test15(ubyte %A) {
170 ; %c = cast ubyte %A to sbyte
171 ; %X = setlt sbyte %c, 0 ; setgt %A, 127
175 define i1 @test16(ptr %P) {
176 ; ALL-LABEL: @test16(
177 ; ALL-NEXT: [[C:%.*]] = icmp ne ptr [[P:%.*]], null
178 ; ALL-NEXT: ret i1 [[C]]
180 %c = icmp ne ptr %P, null
184 define i16 @test17(i1 %x) {
185 ; ALL-LABEL: @test17(
186 ; ALL-NEXT: [[T86:%.*]] = zext i1 [[X:%.*]] to i16
187 ; ALL-NEXT: ret i16 [[T86]]
189 %c = zext i1 %x to i32
190 %t86 = trunc i32 %c to i16
194 define i16 @test18(i8 %x) {
195 ; ALL-LABEL: @test18(
196 ; ALL-NEXT: [[T86:%.*]] = sext i8 [[X:%.*]] to i16
197 ; ALL-NEXT: ret i16 [[T86]]
199 %c = sext i8 %x to i32
200 %t86 = trunc i32 %c to i16
204 define i1 @test19(i32 %X) {
205 ; ALL-LABEL: @test19(
206 ; ALL-NEXT: [[Z:%.*]] = icmp slt i32 [[X:%.*]], 12345
207 ; ALL-NEXT: ret i1 [[Z]]
209 %c = sext i32 %X to i64
210 %Z = icmp slt i64 %c, 12345
214 define <2 x i1> @test19vec(<2 x i32> %X) {
215 ; ALL-LABEL: @test19vec(
216 ; ALL-NEXT: [[Z:%.*]] = icmp slt <2 x i32> [[X:%.*]], <i32 12345, i32 2147483647>
217 ; ALL-NEXT: ret <2 x i1> [[Z]]
219 %c = sext <2 x i32> %X to <2 x i64>
220 %Z = icmp slt <2 x i64> %c, <i64 12345, i64 2147483647>
224 define <3 x i1> @test19vec2(<3 x i1> %X) {
225 ; ALL-LABEL: @test19vec2(
226 ; ALL-NEXT: [[CMPEQ:%.*]] = xor <3 x i1> [[X:%.*]], splat (i1 true)
227 ; ALL-NEXT: ret <3 x i1> [[CMPEQ]]
229 %sext = sext <3 x i1> %X to <3 x i32>
230 %cmpeq = icmp eq <3 x i32> %sext, zeroinitializer
234 define i1 @test20(i1 %B) {
235 ; ALL-LABEL: @test20(
236 ; ALL-NEXT: ret i1 false
238 %c = zext i1 %B to i32
239 %D = icmp slt i32 %c, -1
243 define i32 @test21(i32 %X) {
244 ; ALL-LABEL: @test21(
245 ; ALL-NEXT: [[SEXT:%.*]] = and i32 [[X:%.*]], 255
246 ; ALL-NEXT: ret i32 [[SEXT]]
248 %c1 = trunc i32 %X to i8
249 %c2 = sext i8 %c1 to i32
250 %RV = and i32 %c2, 255
254 define i32 @test22(i32 %X) {
255 ; ALL-LABEL: @test22(
256 ; ALL-NEXT: [[SEXT:%.*]] = shl i32 [[X:%.*]], 24
257 ; ALL-NEXT: ret i32 [[SEXT]]
259 %c1 = trunc i32 %X to i8
260 %c2 = sext i8 %c1 to i32
261 %RV = shl i32 %c2, 24
265 define i32 @test23(i32 %X) {
266 ; ALL-LABEL: @test23(
267 ; ALL-NEXT: [[C2:%.*]] = and i32 [[X:%.*]], 65535
268 ; ALL-NEXT: ret i32 [[C2]]
270 %c1 = trunc i32 %X to i16
271 %c2 = zext i16 %c1 to i32
275 define i1 @test24(i1 %C) {
276 ; ALL-LABEL: @test24(
277 ; ALL-NEXT: ret i1 true
279 %X = select i1 %C, i32 14, i32 1234
280 %c = icmp ne i32 %X, 0
284 define i32 @test26(float %F) {
285 ; ALL-LABEL: @test26(
286 ; ALL-NEXT: [[D:%.*]] = fptosi float [[F:%.*]] to i32
287 ; ALL-NEXT: ret i32 [[D]]
289 %c = fpext float %F to double
290 %D = fptosi double %c to i32
294 define ptr @test27(ptr %A) {
295 ; ALL-LABEL: @test27(
296 ; ALL-NEXT: ret ptr [[A:%.*]]
301 define ptr @test28(ptr %A) {
302 ; ALL-LABEL: @test28(
303 ; ALL-NEXT: ret ptr [[A:%.*]]
308 define i32 @test29(i32 %c1, i32 %c2) {
309 ; ALL-LABEL: @test29(
310 ; ALL-NEXT: [[T21:%.*]] = or i32 [[C2:%.*]], [[C1:%.*]]
311 ; ALL-NEXT: [[T10:%.*]] = and i32 [[T21]], 255
312 ; ALL-NEXT: ret i32 [[T10]]
314 %t1 = trunc i32 %c1 to i8
315 %tmask = trunc i32 %c2 to i8
316 %t2 = or i8 %tmask, %t1
317 %t10 = zext i8 %t2 to i32
321 define i32 @test30(i32 %c1) {
322 ; ALL-LABEL: @test30(
323 ; ALL-NEXT: [[C3:%.*]] = and i32 [[C1:%.*]], 255
324 ; ALL-NEXT: [[C4:%.*]] = xor i32 [[C3]], 1
325 ; ALL-NEXT: ret i32 [[C4]]
327 %c2 = trunc i32 %c1 to i8
329 %c4 = zext i8 %c3 to i32
333 define i1 @test31(i64 %A) {
334 ; ALL-LABEL: @test31(
335 ; ALL-NEXT: [[C1:%.*]] = and i64 [[A:%.*]], 42
336 ; ALL-NEXT: [[D:%.*]] = icmp eq i64 [[C1]], 10
337 ; ALL-NEXT: ret i1 [[D]]
339 %B = trunc i64 %A to i32
341 %D = icmp eq i32 %C, 10
345 ; FIXME: Vectors should fold too...or not?
346 ; Does this depend on the whether the source/dest types of the trunc are legal in the data layout?
347 define <2 x i1> @test31vec(<2 x i64> %A) {
348 ; ALL-LABEL: @test31vec(
349 ; ALL-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
350 ; ALL-NEXT: [[C:%.*]] = and <2 x i32> [[B]], splat (i32 42)
351 ; ALL-NEXT: [[D:%.*]] = icmp eq <2 x i32> [[C]], splat (i32 10)
352 ; ALL-NEXT: ret <2 x i1> [[D]]
354 %B = trunc <2 x i64> %A to <2 x i32>
355 %C = and <2 x i32> %B, <i32 42, i32 42>
356 %D = icmp eq <2 x i32> %C, <i32 10, i32 10>
360 ; Verify that the 'and' was narrowed, the zext was eliminated, and the compare was narrowed
361 ; even for vectors. Earlier folds should ensure that the icmp(and(zext)) pattern never occurs.
363 define <2 x i1> @test32vec(<2 x i8> %A) {
364 ; ALL-LABEL: @test32vec(
365 ; ALL-NEXT: [[TMP1:%.*]] = and <2 x i8> [[A:%.*]], splat (i8 42)
366 ; ALL-NEXT: [[D:%.*]] = icmp eq <2 x i8> [[TMP1]], splat (i8 10)
367 ; ALL-NEXT: ret <2 x i1> [[D]]
369 %B = zext <2 x i8> %A to <2 x i16>
370 %C = and <2 x i16> %B, <i16 42, i16 42>
371 %D = icmp eq <2 x i16> %C, <i16 10, i16 10>
375 define i32 @test33(i32 %c1) {
376 ; ALL-LABEL: @test33(
377 ; ALL-NEXT: ret i32 [[C1:%.*]]
379 %x = bitcast i32 %c1 to float
380 %y = bitcast float %x to i32
384 define i16 @test34(i16 %a) {
385 ; ALL-LABEL: @test34(
386 ; ALL-NEXT: [[TMP1:%.*]] = lshr i16 [[A:%.*]], 8
387 ; ALL-NEXT: ret i16 [[TMP1]]
389 %c1 = zext i16 %a to i32
390 %t21 = lshr i32 %c1, 8
391 %c2 = trunc i32 %t21 to i16
395 define i16 @test35(i16 %a) {
396 ; ALL-LABEL: @test35(
397 ; ALL-NEXT: [[T2:%.*]] = lshr i16 [[A:%.*]], 8
398 ; ALL-NEXT: ret i16 [[T2]]
400 %c1 = bitcast i16 %a to i16
401 %t2 = lshr i16 %c1, 8
402 %c2 = bitcast i16 %t2 to i16
407 define i1 @test36(i32 %a) {
408 ; ALL-LABEL: @test36(
409 ; ALL-NEXT: [[D:%.*]] = icmp sgt i32 [[A:%.*]], -1
410 ; ALL-NEXT: ret i1 [[D]]
413 %c = trunc i32 %b to i8
414 %d = icmp eq i8 %c, 0
418 define <2 x i1> @test36vec(<2 x i32> %a) {
419 ; ALL-LABEL: @test36vec(
420 ; ALL-NEXT: [[D:%.*]] = icmp sgt <2 x i32> [[A:%.*]], splat (i32 -1)
421 ; ALL-NEXT: ret <2 x i1> [[D]]
423 %b = lshr <2 x i32> %a, <i32 31, i32 31>
424 %c = trunc <2 x i32> %b to <2 x i8>
425 %d = icmp eq <2 x i8> %c, zeroinitializer
429 define i1 @test37(i32 %a) {
430 ; ALL-LABEL: @test37(
431 ; ALL-NEXT: ret i1 false
435 %d = trunc i32 %c to i8
436 %e = icmp eq i8 %d, 11
440 define i64 @test38(i32 %a) {
441 ; ALL-LABEL: @test38(
442 ; ALL-NEXT: [[TMP1:%.*]] = icmp ne i32 [[A:%.*]], -2
443 ; ALL-NEXT: [[TMP2:%.*]] = zext i1 [[TMP1]] to i64
444 ; ALL-NEXT: ret i64 [[TMP2]]
446 %1 = icmp eq i32 %a, -2
447 %2 = zext i1 %1 to i8
449 %4 = zext i8 %3 to i64
453 define i16 @test39(i16 %a) {
454 ; ALL-LABEL: @test39(
455 ; ALL-NEXT: [[T32:%.*]] = call i16 @llvm.bswap.i16(i16 [[A:%.*]])
456 ; ALL-NEXT: ret i16 [[T32]]
458 %t = zext i16 %a to i32
459 %t21 = lshr i32 %t, 8
461 %t32 = or i32 %t21, %t5
462 %r = trunc i32 %t32 to i16
466 define i16 @test40(i16 %a) {
467 ; ALL-LABEL: @test40(
468 ; ALL-NEXT: [[T21:%.*]] = lshr i16 [[A:%.*]], 9
469 ; ALL-NEXT: [[T5:%.*]] = shl i16 [[A]], 8
470 ; ALL-NEXT: [[T32:%.*]] = or disjoint i16 [[T21]], [[T5]]
471 ; ALL-NEXT: ret i16 [[T32]]
473 %t = zext i16 %a to i32
474 %t21 = lshr i32 %t, 9
476 %t32 = or i32 %t21, %t5
477 %r = trunc i32 %t32 to i16
481 define <2 x i16> @test40vec(<2 x i16> %a) {
482 ; ALL-LABEL: @test40vec(
483 ; ALL-NEXT: [[T21:%.*]] = lshr <2 x i16> [[A:%.*]], splat (i16 9)
484 ; ALL-NEXT: [[T5:%.*]] = shl <2 x i16> [[A]], splat (i16 8)
485 ; ALL-NEXT: [[T32:%.*]] = or disjoint <2 x i16> [[T21]], [[T5]]
486 ; ALL-NEXT: ret <2 x i16> [[T32]]
488 %t = zext <2 x i16> %a to <2 x i32>
489 %t21 = lshr <2 x i32> %t, <i32 9, i32 9>
490 %t5 = shl <2 x i32> %t, <i32 8, i32 8>
491 %t32 = or <2 x i32> %t21, %t5
492 %r = trunc <2 x i32> %t32 to <2 x i16>
496 define <2 x i16> @test40vec_nonuniform(<2 x i16> %a) {
497 ; ALL-LABEL: @test40vec_nonuniform(
498 ; ALL-NEXT: [[T21:%.*]] = lshr <2 x i16> [[A:%.*]], <i16 9, i16 10>
499 ; ALL-NEXT: [[T5:%.*]] = shl <2 x i16> [[A]], <i16 8, i16 9>
500 ; ALL-NEXT: [[T32:%.*]] = or disjoint <2 x i16> [[T21]], [[T5]]
501 ; ALL-NEXT: ret <2 x i16> [[T32]]
503 %t = zext <2 x i16> %a to <2 x i32>
504 %t21 = lshr <2 x i32> %t, <i32 9, i32 10>
505 %t5 = shl <2 x i32> %t, <i32 8, i32 9>
506 %t32 = or <2 x i32> %t21, %t5
507 %r = trunc <2 x i32> %t32 to <2 x i16>
511 define <2 x i16> @test40vec_poison(<2 x i16> %a) {
512 ; ALL-LABEL: @test40vec_poison(
513 ; ALL-NEXT: [[T21:%.*]] = lshr <2 x i16> [[A:%.*]], <i16 9, i16 poison>
514 ; ALL-NEXT: [[T5:%.*]] = shl <2 x i16> [[A]], <i16 8, i16 poison>
515 ; ALL-NEXT: [[T32:%.*]] = or disjoint <2 x i16> [[T21]], [[T5]]
516 ; ALL-NEXT: ret <2 x i16> [[T32]]
518 %t = zext <2 x i16> %a to <2 x i32>
519 %t21 = lshr <2 x i32> %t, <i32 9, i32 poison>
520 %t5 = shl <2 x i32> %t, <i32 8, i32 poison>
521 %t32 = or <2 x i32> %t21, %t5
522 %r = trunc <2 x i32> %t32 to <2 x i16>
527 define ptr @test41(ptr %t1) {
528 ; ALL-LABEL: @test41(
529 ; ALL-NEXT: ret ptr [[T1:%.*]]
534 define ptr addrspace(1) @test41_addrspacecast_smaller(ptr %t1) {
535 ; ALL-LABEL: @test41_addrspacecast_smaller(
536 ; ALL-NEXT: [[T64:%.*]] = addrspacecast ptr [[T1:%.*]] to ptr addrspace(1)
537 ; ALL-NEXT: ret ptr addrspace(1) [[T64]]
539 %t64 = addrspacecast ptr %t1 to ptr addrspace(1)
540 ret ptr addrspace(1) %t64
543 define ptr @test41_addrspacecast_larger(ptr addrspace(1) %t1) {
544 ; ALL-LABEL: @test41_addrspacecast_larger(
545 ; ALL-NEXT: [[T64:%.*]] = addrspacecast ptr addrspace(1) [[T1:%.*]] to ptr
546 ; ALL-NEXT: ret ptr [[T64]]
548 %t64 = addrspacecast ptr addrspace(1) %t1 to ptr
552 define i32 @test42(i32 %X) {
553 ; ALL-LABEL: @test42(
554 ; ALL-NEXT: [[Z:%.*]] = and i32 [[X:%.*]], 255
555 ; ALL-NEXT: ret i32 [[Z]]
557 %Y = trunc i32 %X to i8
558 %Z = zext i8 %Y to i32
563 define zeroext i64 @test43(i8 zeroext %on_off) {
564 ; ALL-LABEL: @test43(
565 ; ALL-NEXT: [[A:%.*]] = zext i8 [[ON_OFF:%.*]] to i64
566 ; ALL-NEXT: [[B:%.*]] = add nsw i64 [[A]], -1
567 ; ALL-NEXT: ret i64 [[B]]
569 %A = zext i8 %on_off to i32
571 %C = sext i32 %B to i64
572 ret i64 %C ;; Should be (add (zext i8 -> i64), -1)
575 define i64 @test44(i8 %T) {
576 ; ALL-LABEL: @test44(
577 ; ALL-NEXT: [[A:%.*]] = zext i8 [[T:%.*]] to i64
578 ; ALL-NEXT: [[B:%.*]] = or i64 [[A]], 1234
579 ; ALL-NEXT: ret i64 [[B]]
581 %A = zext i8 %T to i16
583 %C = zext i16 %B to i64
587 define i64 @test45(i8 %A, i64 %Q) {
588 ; ALL-LABEL: @test45(
589 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i64
590 ; ALL-NEXT: [[C:%.*]] = or i64 [[Q:%.*]], [[B]]
591 ; ALL-NEXT: [[E:%.*]] = and i64 [[C]], 4294967295
592 ; ALL-NEXT: ret i64 [[E]]
594 %D = trunc i64 %Q to i32 ;; should be removed
595 %B = sext i8 %A to i32
597 %E = zext i32 %C to i64
602 define i64 @test46(i64 %A) {
603 ; ALL-LABEL: @test46(
604 ; ALL-NEXT: [[C:%.*]] = shl i64 [[A:%.*]], 8
605 ; ALL-NEXT: [[D:%.*]] = and i64 [[C]], 10752
606 ; ALL-NEXT: ret i64 [[D]]
608 %B = trunc i64 %A to i32
611 %E = zext i32 %D to i64
615 define <2 x i64> @test46vec(<2 x i64> %A) {
616 ; ALL-LABEL: @test46vec(
617 ; ALL-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
618 ; ALL-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], splat (i32 8)
619 ; ALL-NEXT: [[D:%.*]] = and <2 x i32> [[C]], splat (i32 10752)
620 ; ALL-NEXT: [[E:%.*]] = zext nneg <2 x i32> [[D]] to <2 x i64>
621 ; ALL-NEXT: ret <2 x i64> [[E]]
623 %B = trunc <2 x i64> %A to <2 x i32>
624 %C = and <2 x i32> %B, <i32 42, i32 42>
625 %D = shl <2 x i32> %C, <i32 8, i32 8>
626 %E = zext <2 x i32> %D to <2 x i64>
630 define i64 @test47(i8 %A) {
631 ; ALL-LABEL: @test47(
632 ; ALL-NEXT: [[TMP1:%.*]] = or i8 [[A:%.*]], 42
633 ; ALL-NEXT: [[C:%.*]] = sext i8 [[TMP1]] to i64
634 ; ALL-NEXT: [[E:%.*]] = and i64 [[C]], 4294967295
635 ; ALL-NEXT: ret i64 [[E]]
637 %B = sext i8 %A to i32
639 %E = zext i32 %C to i64
643 define i64 @test48(i8 %A1, i8 %a2) {
644 ; ALL-LABEL: @test48(
645 ; ALL-NEXT: [[Z2:%.*]] = zext i8 [[A1:%.*]] to i32
646 ; ALL-NEXT: [[C:%.*]] = shl nuw nsw i32 [[Z2]], 8
647 ; ALL-NEXT: [[D:%.*]] = or disjoint i32 [[C]], [[Z2]]
648 ; ALL-NEXT: [[E:%.*]] = zext nneg i32 [[D]] to i64
649 ; ALL-NEXT: ret i64 [[E]]
651 %Z1 = zext i8 %a2 to i32
652 %Z2 = zext i8 %A1 to i32
655 %E = zext i32 %D to i64
659 define i64 @test49(i64 %A) {
660 ; ALL-LABEL: @test49(
661 ; ALL-NEXT: [[C:%.*]] = shl i64 [[A:%.*]], 32
662 ; ALL-NEXT: [[SEXT:%.*]] = ashr exact i64 [[C]], 32
663 ; ALL-NEXT: [[D:%.*]] = or i64 [[SEXT]], 1
664 ; ALL-NEXT: ret i64 [[D]]
666 %B = trunc i64 %A to i32
668 %D = sext i32 %C to i64
672 define i64 @test50(i64 %x) {
673 ; ALL-LABEL: @test50(
674 ; ALL-NEXT: [[TMP1:%.*]] = shl i64 [[X:%.*]], 30
675 ; ALL-NEXT: [[SEXT:%.*]] = add i64 [[TMP1]], -4294967296
676 ; ALL-NEXT: [[E:%.*]] = ashr i64 [[SEXT]], 32
677 ; ALL-NEXT: ret i64 [[E]]
680 %B = trunc i64 %a to i32
682 %E = sext i32 %D to i64
686 define i64 @test51(i64 %A, i1 %cond) {
687 ; ALL-LABEL: @test51(
688 ; ALL-NEXT: [[C:%.*]] = and i64 [[A:%.*]], 4294967294
689 ; ALL-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND:%.*]], true
690 ; ALL-NEXT: [[MASKSEL:%.*]] = zext i1 [[NOT_COND]] to i64
691 ; ALL-NEXT: [[E:%.*]] = or disjoint i64 [[C]], [[MASKSEL]]
692 ; ALL-NEXT: [[SEXT:%.*]] = shl nuw i64 [[E]], 32
693 ; ALL-NEXT: [[F:%.*]] = ashr exact i64 [[SEXT]], 32
694 ; ALL-NEXT: ret i64 [[F]]
696 %B = trunc i64 %A to i32
699 %E = select i1 %cond, i32 %C, i32 %D
700 %F = sext i32 %E to i64
704 define i32 @test52(i64 %A) {
705 ; ALL-LABEL: @test52(
706 ; ALL-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
707 ; ALL-NEXT: [[C:%.*]] = and i32 [[B]], 7224
708 ; ALL-NEXT: [[D:%.*]] = or disjoint i32 [[C]], 32962
709 ; ALL-NEXT: ret i32 [[D]]
711 %B = trunc i64 %A to i16
712 %C = or i16 %B, -32574
713 %D = and i16 %C, -25350
714 %E = zext i16 %D to i32
718 define i64 @test53(i32 %A) {
719 ; ALL-LABEL: @test53(
720 ; ALL-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 7224
721 ; ALL-NEXT: [[TMP2:%.*]] = or disjoint i32 [[TMP1]], 32962
722 ; ALL-NEXT: [[D:%.*]] = zext nneg i32 [[TMP2]] to i64
723 ; ALL-NEXT: ret i64 [[D]]
725 %B = trunc i32 %A to i16
726 %C = or i16 %B, -32574
727 %D = and i16 %C, -25350
728 %E = zext i16 %D to i64
732 define i32 @test54(i64 %A) {
733 ; ALL-LABEL: @test54(
734 ; ALL-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
735 ; ALL-NEXT: [[C:%.*]] = and i32 [[B]], 7224
736 ; ALL-NEXT: [[D:%.*]] = or disjoint i32 [[C]], -32574
737 ; ALL-NEXT: ret i32 [[D]]
739 %B = trunc i64 %A to i16
740 %C = or i16 %B, -32574
741 %D = and i16 %C, -25350
742 %E = sext i16 %D to i32
746 define i64 @test55(i32 %A) {
747 ; ALL-LABEL: @test55(
748 ; ALL-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 7224
749 ; ALL-NEXT: [[TMP2:%.*]] = or disjoint i32 [[TMP1]], -32574
750 ; ALL-NEXT: [[D:%.*]] = sext i32 [[TMP2]] to i64
751 ; ALL-NEXT: ret i64 [[D]]
753 %B = trunc i32 %A to i16
754 %C = or i16 %B, -32574
755 %D = and i16 %C, -25350
756 %E = sext i16 %D to i64
760 define i64 @test56(i16 %A) {
761 ; ALL-LABEL: @test56(
762 ; ALL-NEXT: [[P353:%.*]] = sext i16 [[A:%.*]] to i64
763 ; ALL-NEXT: [[P354:%.*]] = lshr i64 [[P353]], 5
764 ; ALL-NEXT: [[P355:%.*]] = and i64 [[P354]], 134217727
765 ; ALL-NEXT: ret i64 [[P355]]
767 %p353 = sext i16 %A to i32
768 %p354 = lshr i32 %p353, 5
769 %p355 = zext i32 %p354 to i64
773 define <2 x i64> @test56vec(<2 x i16> %A) {
774 ; ALL-LABEL: @test56vec(
775 ; ALL-NEXT: [[P353:%.*]] = sext <2 x i16> [[A:%.*]] to <2 x i32>
776 ; ALL-NEXT: [[P354:%.*]] = lshr <2 x i32> [[P353]], splat (i32 5)
777 ; ALL-NEXT: [[P355:%.*]] = zext nneg <2 x i32> [[P354]] to <2 x i64>
778 ; ALL-NEXT: ret <2 x i64> [[P355]]
780 %p353 = sext <2 x i16> %A to <2 x i32>
781 %p354 = lshr <2 x i32> %p353, <i32 5, i32 5>
782 %p355 = zext <2 x i32> %p354 to <2 x i64>
786 define i64 @test57(i64 %A) {
787 ; ALL-LABEL: @test57(
788 ; ALL-NEXT: [[C:%.*]] = lshr i64 [[A:%.*]], 8
789 ; ALL-NEXT: [[E:%.*]] = and i64 [[C]], 16777215
790 ; ALL-NEXT: ret i64 [[E]]
792 %B = trunc i64 %A to i32
794 %E = zext i32 %C to i64
798 define <2 x i64> @test57vec(<2 x i64> %A) {
799 ; ALL-LABEL: @test57vec(
800 ; ALL-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
801 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 8)
802 ; ALL-NEXT: [[E:%.*]] = zext nneg <2 x i32> [[C]] to <2 x i64>
803 ; ALL-NEXT: ret <2 x i64> [[E]]
805 %B = trunc <2 x i64> %A to <2 x i32>
806 %C = lshr <2 x i32> %B, <i32 8, i32 8>
807 %E = zext <2 x i32> %C to <2 x i64>
811 define i64 @test58(i64 %A) {
812 ; ALL-LABEL: @test58(
813 ; ALL-NEXT: [[C:%.*]] = lshr i64 [[A:%.*]], 8
814 ; ALL-NEXT: [[D:%.*]] = and i64 [[C]], 16777087
815 ; ALL-NEXT: [[E:%.*]] = or disjoint i64 [[D]], 128
816 ; ALL-NEXT: ret i64 [[E]]
818 %B = trunc i64 %A to i32
821 %E = zext i32 %D to i64
826 define i64 @test59(i8 %A, i8 %B) {
827 ; ALL-LABEL: @test59(
828 ; ALL-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i64
829 ; ALL-NEXT: [[D:%.*]] = shl nuw nsw i64 [[C]], 4
830 ; ALL-NEXT: [[E:%.*]] = and i64 [[D]], 48
831 ; ALL-NEXT: [[TMP1:%.*]] = lshr i8 [[B:%.*]], 4
832 ; ALL-NEXT: [[G:%.*]] = zext nneg i8 [[TMP1]] to i64
833 ; ALL-NEXT: [[H:%.*]] = or disjoint i64 [[E]], [[G]]
834 ; ALL-NEXT: ret i64 [[H]]
836 %C = zext i8 %A to i32
839 %F = zext i8 %B to i32
842 %I = zext i32 %H to i64
846 define <3 x i32> @test60(<4 x i32> %call4) {
848 ; BE-NEXT: [[P10:%.*]] = shufflevector <4 x i32> [[CALL4:%.*]], <4 x i32> poison, <3 x i32> <i32 1, i32 2, i32 3>
849 ; BE-NEXT: ret <3 x i32> [[P10]]
852 ; LE-NEXT: [[P10:%.*]] = shufflevector <4 x i32> [[CALL4:%.*]], <4 x i32> poison, <3 x i32> <i32 0, i32 1, i32 2>
853 ; LE-NEXT: ret <3 x i32> [[P10]]
855 %p11 = bitcast <4 x i32> %call4 to i128
856 %p9 = trunc i128 %p11 to i96
857 %p10 = bitcast i96 %p9 to <3 x i32>
862 define <4 x i32> @test61(<3 x i32> %call4) {
864 ; BE-NEXT: [[P10:%.*]] = shufflevector <3 x i32> [[CALL4:%.*]], <3 x i32> <i32 0, i32 poison, i32 poison>, <4 x i32> <i32 3, i32 0, i32 1, i32 2>
865 ; BE-NEXT: ret <4 x i32> [[P10]]
868 ; LE-NEXT: [[P10:%.*]] = shufflevector <3 x i32> [[CALL4:%.*]], <3 x i32> <i32 0, i32 poison, i32 poison>, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
869 ; LE-NEXT: ret <4 x i32> [[P10]]
871 %p11 = bitcast <3 x i32> %call4 to i96
872 %p9 = zext i96 %p11 to i128
873 %p10 = bitcast i128 %p9 to <4 x i32>
877 define <4 x i32> @test62(<3 x float> %call4) {
879 ; BE-NEXT: [[TMP1:%.*]] = bitcast <3 x float> [[CALL4:%.*]] to <3 x i32>
880 ; BE-NEXT: [[P10:%.*]] = shufflevector <3 x i32> [[TMP1]], <3 x i32> <i32 0, i32 poison, i32 poison>, <4 x i32> <i32 3, i32 0, i32 1, i32 2>
881 ; BE-NEXT: ret <4 x i32> [[P10]]
884 ; LE-NEXT: [[TMP1:%.*]] = bitcast <3 x float> [[CALL4:%.*]] to <3 x i32>
885 ; LE-NEXT: [[P10:%.*]] = shufflevector <3 x i32> [[TMP1]], <3 x i32> <i32 0, i32 poison, i32 poison>, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
886 ; LE-NEXT: ret <4 x i32> [[P10]]
888 %p11 = bitcast <3 x float> %call4 to i96
889 %p9 = zext i96 %p11 to i128
890 %p10 = bitcast i128 %p9 to <4 x i32>
894 ; PR7311 - Don't create invalid IR on scalar->vector cast.
895 define <2 x float> @test63(i64 %t8) {
896 ; ALL-LABEL: @test63(
897 ; ALL-NEXT: [[A:%.*]] = bitcast i64 [[T8:%.*]] to <2 x i32>
898 ; ALL-NEXT: [[VCVT_I:%.*]] = uitofp <2 x i32> [[A]] to <2 x float>
899 ; ALL-NEXT: ret <2 x float> [[VCVT_I]]
901 %a = bitcast i64 %t8 to <2 x i32>
902 %vcvt.i = uitofp <2 x i32> %a to <2 x float>
903 ret <2 x float> %vcvt.i
906 define <4 x float> @test64(<4 x float> %c) {
907 ; ALL-LABEL: @test64(
908 ; ALL-NEXT: ret <4 x float> [[C:%.*]]
910 %t0 = bitcast <4 x float> %c to <4 x i32>
911 %t1 = bitcast <4 x i32> %t0 to <4 x float>
915 define <4 x float> @test65(<4 x float> %c) {
916 ; ALL-LABEL: @test65(
917 ; ALL-NEXT: ret <4 x float> [[C:%.*]]
919 %t0 = bitcast <4 x float> %c to <2 x double>
920 %t1 = bitcast <2 x double> %t0 to <4 x float>
924 define <2 x float> @test66(<2 x float> %c) {
925 ; ALL-LABEL: @test66(
926 ; ALL-NEXT: ret <2 x float> [[C:%.*]]
928 %t0 = bitcast <2 x float> %c to double
929 %t1 = bitcast double %t0 to <2 x float>
933 define float @test2c() {
934 ; ALL-LABEL: @test2c(
935 ; ALL-NEXT: ret float -1.000000e+00
937 ret float extractelement (<2 x float> bitcast (double bitcast (<2 x float> <float -1.000000e+00, float -1.000000e+00> to double) to <2 x float>), i32 0)
941 define i1 @test67(i1 %a, i32 %b) {
942 ; ALL-LABEL: @test67(
943 ; ALL-NEXT: ret i1 false
945 %t2 = zext i1 %a to i32
946 %conv6 = xor i32 %t2, 1
947 %and = and i32 %b, %conv6
948 %sext = shl nuw nsw i32 %and, 24
949 %neg.i = xor i32 %sext, -16777216
950 %conv.i.i = ashr exact i32 %neg.i, 24
951 %trunc = trunc i32 %conv.i.i to i8
952 %tobool.i = icmp eq i8 %trunc, 0
956 %s = type { i32, i32, i16 }
958 define %s @test68(ptr %p, i64 %i) {
959 ; ALL-LABEL: @test68(
960 ; ALL-NEXT: [[O:%.*]] = mul i64 [[I:%.*]], 12
961 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O]]
962 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr [[PP]], align 4
963 ; ALL-NEXT: ret [[S]] [[L]]
966 %pp = getelementptr inbounds i8, ptr %p, i64 %o
967 %l = load %s, ptr %pp
971 ; addrspacecasts should be eliminated.
972 define %s @test68_addrspacecast(ptr %p, i64 %i) {
973 ; ALL-LABEL: @test68_addrspacecast(
974 ; ALL-NEXT: [[O:%.*]] = mul i64 [[I:%.*]], 12
975 ; ALL-NEXT: [[Q:%.*]] = addrspacecast ptr [[P:%.*]] to ptr addrspace(2)
976 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr addrspace(2) [[Q]], i64 [[O]]
977 ; ALL-NEXT: [[R:%.*]] = addrspacecast ptr addrspace(2) [[PP]] to ptr
978 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr [[R]], align 4
979 ; ALL-NEXT: ret [[S]] [[L]]
982 %q = addrspacecast ptr %p to ptr addrspace(2)
983 %pp = getelementptr inbounds i8, ptr addrspace(2) %q, i64 %o
984 %r = addrspacecast ptr addrspace(2) %pp to ptr
989 define %s @test68_addrspacecast_2(ptr %p, i64 %i) {
990 ; ALL-LABEL: @test68_addrspacecast_2(
991 ; ALL-NEXT: [[O:%.*]] = mul i64 [[I:%.*]], 12
992 ; ALL-NEXT: [[Q:%.*]] = addrspacecast ptr [[P:%.*]] to ptr addrspace(2)
993 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr addrspace(2) [[Q]], i64 [[O]]
994 ; ALL-NEXT: [[R:%.*]] = addrspacecast ptr addrspace(2) [[PP]] to ptr addrspace(1)
995 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr addrspace(1) [[R]], align 4
996 ; ALL-NEXT: ret [[S]] [[L]]
999 %q = addrspacecast ptr %p to ptr addrspace(2)
1000 %pp = getelementptr inbounds i8, ptr addrspace(2) %q, i64 %o
1001 %r = addrspacecast ptr addrspace(2) %pp to ptr addrspace(1)
1002 %l = load %s, ptr addrspace(1) %r
1006 define %s @test68_as1(ptr addrspace(1) %p, i32 %i) {
1007 ; ALL-LABEL: @test68_as1(
1008 ; ALL-NEXT: [[O:%.*]] = mul i32 [[I:%.*]], 12
1009 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[P:%.*]], i32 [[O]]
1010 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr addrspace(1) [[PP]], align 4
1011 ; ALL-NEXT: ret [[S]] [[L]]
1014 %pp = getelementptr inbounds i8, ptr addrspace(1) %p, i32 %o
1015 %l = load %s, ptr addrspace(1) %pp
1019 define double @test69(ptr %p, i64 %i) {
1020 ; ALL-LABEL: @test69(
1021 ; ALL-NEXT: [[O:%.*]] = shl nsw i64 [[I:%.*]], 3
1022 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O]]
1023 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1024 ; ALL-NEXT: ret double [[L]]
1026 %o = shl nsw i64 %i, 3
1027 %pp = getelementptr inbounds i8, ptr %p, i64 %o
1028 %l = load double, ptr %pp
1032 define %s @test70(ptr %p, i64 %i) {
1033 ; ALL-LABEL: @test70(
1034 ; ALL-NEXT: [[O:%.*]] = mul nsw i64 [[I:%.*]], 36
1035 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O]]
1036 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr [[PP]], align 4
1037 ; ALL-NEXT: ret [[S]] [[L]]
1039 %o = mul nsw i64 %i, 36
1040 %pp = getelementptr inbounds i8, ptr %p, i64 %o
1041 %l = load %s, ptr %pp
1045 define double @test71(ptr %p, i64 %i) {
1046 ; ALL-LABEL: @test71(
1047 ; ALL-NEXT: [[O:%.*]] = shl i64 [[I:%.*]], 5
1048 ; ALL-NEXT: [[PP:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[O]]
1049 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1050 ; ALL-NEXT: ret double [[L]]
1053 %pp = getelementptr i8, ptr %p, i64 %o
1054 %l = load double, ptr %pp
1058 define double @test72(ptr %p, i32 %i) {
1059 ; ALL-LABEL: @test72(
1060 ; ALL-NEXT: [[SO:%.*]] = shl nsw i32 [[I:%.*]], 3
1061 ; ALL-NEXT: [[O:%.*]] = sext i32 [[SO]] to i64
1062 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O]]
1063 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1064 ; ALL-NEXT: ret double [[L]]
1066 %so = shl nsw i32 %i, 3
1067 %o = sext i32 %so to i64
1068 %pp = getelementptr inbounds i8, ptr %p, i64 %o
1069 %l = load double, ptr %pp
1073 define double @test73(ptr %p, i128 %i) {
1074 ; ALL-LABEL: @test73(
1075 ; ALL-NEXT: [[I_TR:%.*]] = trunc i128 [[I:%.*]] to i64
1076 ; ALL-NEXT: [[O:%.*]] = shl i64 [[I_TR]], 3
1077 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O]]
1078 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1079 ; ALL-NEXT: ret double [[L]]
1081 %lo = shl nsw i128 %i, 3
1082 %o = trunc i128 %lo to i64
1083 %pp = getelementptr inbounds i8, ptr %p, i64 %o
1084 %l = load double, ptr %pp
1088 define double @test74(ptr %p, i64 %i) {
1089 ; ALL-LABEL: @test74(
1090 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i64, ptr [[P:%.*]], i64 [[I:%.*]]
1091 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1092 ; ALL-NEXT: ret double [[L]]
1094 %pp = getelementptr inbounds i64, ptr %p, i64 %i
1095 %l = load double, ptr %pp
1099 define ptr @test75(ptr %p, i32 %x) {
1100 ; ALL-LABEL: @test75(
1101 ; ALL-NEXT: [[Y:%.*]] = shl i32 [[X:%.*]], 3
1102 ; ALL-NEXT: [[Z:%.*]] = sext i32 [[Y]] to i64
1103 ; ALL-NEXT: [[R:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[Z]]
1104 ; ALL-NEXT: ret ptr [[R]]
1107 %z = sext i32 %y to i64
1108 %r = getelementptr i8, ptr %p, i64 %z
1112 define %s @test76(ptr %p, i64 %i, i64 %j) {
1113 ; ALL-LABEL: @test76(
1114 ; ALL-NEXT: [[O:%.*]] = mul i64 [[I:%.*]], 12
1115 ; ALL-NEXT: [[O2:%.*]] = mul nsw i64 [[O]], [[J:%.*]]
1116 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O2]]
1117 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr [[PP]], align 4
1118 ; ALL-NEXT: ret [[S]] [[L]]
1121 %o2 = mul nsw i64 %o, %j
1122 %pp = getelementptr inbounds i8, ptr %p, i64 %o2
1123 %l = load %s, ptr %pp
1127 define %s @test77(ptr %p, i64 %i, i64 %j) {
1128 ; ALL-LABEL: @test77(
1129 ; ALL-NEXT: [[O:%.*]] = mul nsw i64 [[I:%.*]], 36
1130 ; ALL-NEXT: [[O2:%.*]] = mul nsw i64 [[O]], [[J:%.*]]
1131 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[O2]]
1132 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr [[PP]], align 4
1133 ; ALL-NEXT: ret [[S]] [[L]]
1135 %o = mul nsw i64 %i, 36
1136 %o2 = mul nsw i64 %o, %j
1137 %pp = getelementptr inbounds i8, ptr %p, i64 %o2
1138 %l = load %s, ptr %pp
1142 define %s @test78(ptr %p, i64 %i, i64 %j, i32 %k, i32 %l, i128 %m, i128 %n) {
1143 ; ALL-LABEL: @test78(
1144 ; ALL-NEXT: [[A:%.*]] = mul nsw i32 [[K:%.*]], 36
1145 ; ALL-NEXT: [[B:%.*]] = mul nsw i32 [[A]], [[L:%.*]]
1146 ; ALL-NEXT: [[C:%.*]] = sext i32 [[B]] to i128
1147 ; ALL-NEXT: [[D:%.*]] = mul nsw i128 [[M:%.*]], [[C]]
1148 ; ALL-NEXT: [[E:%.*]] = mul i128 [[D]], [[N:%.*]]
1149 ; ALL-NEXT: [[F:%.*]] = trunc i128 [[E]] to i64
1150 ; ALL-NEXT: [[G:%.*]] = mul nsw i64 [[I:%.*]], [[F]]
1151 ; ALL-NEXT: [[H:%.*]] = mul nsw i64 [[G]], [[J:%.*]]
1152 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[H]]
1153 ; ALL-NEXT: [[LOAD:%.*]] = load [[S:%.*]], ptr [[PP]], align 4
1154 ; ALL-NEXT: ret [[S]] [[LOAD]]
1156 %a = mul nsw i32 %k, 36
1157 %b = mul nsw i32 %a, %l
1158 %c = sext i32 %b to i128
1159 %d = mul nsw i128 %c, %m
1160 %e = mul i128 %d, %n
1161 %f = trunc i128 %e to i64
1162 %g = mul nsw i64 %f, %i
1163 %h = mul nsw i64 %g, %j
1164 %pp = getelementptr inbounds i8, ptr %p, i64 %h
1165 %load = load %s, ptr %pp
1169 define %s @test79(ptr %p, i64 %i, i32 %j) {
1170 ; ALL-LABEL: @test79(
1171 ; ALL-NEXT: [[TMP1:%.*]] = trunc i64 [[I:%.*]] to i32
1172 ; ALL-NEXT: [[B:%.*]] = mul i32 [[TMP1]], 36
1173 ; ALL-NEXT: [[C:%.*]] = mul i32 [[B]], [[J:%.*]]
1174 ; ALL-NEXT: [[TMP2:%.*]] = sext i32 [[C]] to i64
1175 ; ALL-NEXT: [[PP:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[TMP2]]
1176 ; ALL-NEXT: [[L:%.*]] = load [[S:%.*]], ptr [[PP]], align 4
1177 ; ALL-NEXT: ret [[S]] [[L]]
1179 %a = mul nsw i64 %i, 36
1180 %b = trunc i64 %a to i32
1182 %pp = getelementptr inbounds i8, ptr %p, i32 %c
1183 %l = load %s, ptr %pp
1187 define double @test80(ptr %p, i32 %i) {
1188 ; ALL-LABEL: @test80(
1189 ; ALL-NEXT: [[T:%.*]] = shl nsw i32 [[I:%.*]], 3
1190 ; ALL-NEXT: [[TMP1:%.*]] = sext i32 [[T]] to i64
1191 ; ALL-NEXT: [[PP:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[TMP1]]
1192 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1193 ; ALL-NEXT: ret double [[L]]
1195 %t = shl nsw i32 %i, 3
1196 %pp = getelementptr i8, ptr %p, i32 %t
1197 %l = load double, ptr %pp
1201 define double @test80_addrspacecast(ptr addrspace(1) %p, i32 %i) {
1202 ; ALL-LABEL: @test80_addrspacecast(
1203 ; ALL-NEXT: [[T:%.*]] = shl nsw i32 [[I:%.*]], 3
1204 ; ALL-NEXT: [[Q:%.*]] = addrspacecast ptr addrspace(1) [[P:%.*]] to ptr addrspace(2)
1205 ; ALL-NEXT: [[TMP1:%.*]] = sext i32 [[T]] to i64
1206 ; ALL-NEXT: [[PP:%.*]] = getelementptr i8, ptr addrspace(2) [[Q]], i64 [[TMP1]]
1207 ; ALL-NEXT: [[R:%.*]] = addrspacecast ptr addrspace(2) [[PP]] to ptr addrspace(1)
1208 ; ALL-NEXT: [[L:%.*]] = load double, ptr addrspace(1) [[R]], align 8
1209 ; ALL-NEXT: ret double [[L]]
1211 %t = shl nsw i32 %i, 3
1212 %q = addrspacecast ptr addrspace(1) %p to ptr addrspace(2)
1213 %pp = getelementptr i8, ptr addrspace(2) %q, i32 %t
1214 %r = addrspacecast ptr addrspace(2) %pp to ptr addrspace(1)
1215 %l = load double, ptr addrspace(1) %r
1219 define double @test80_addrspacecast_2(ptr addrspace(1) %p, i32 %i) {
1220 ; ALL-LABEL: @test80_addrspacecast_2(
1221 ; ALL-NEXT: [[T:%.*]] = shl nsw i32 [[I:%.*]], 3
1222 ; ALL-NEXT: [[Q:%.*]] = addrspacecast ptr addrspace(1) [[P:%.*]] to ptr addrspace(2)
1223 ; ALL-NEXT: [[TMP1:%.*]] = sext i32 [[T]] to i64
1224 ; ALL-NEXT: [[PP:%.*]] = getelementptr i8, ptr addrspace(2) [[Q]], i64 [[TMP1]]
1225 ; ALL-NEXT: [[R:%.*]] = addrspacecast ptr addrspace(2) [[PP]] to ptr addrspace(3)
1226 ; ALL-NEXT: [[L:%.*]] = load double, ptr addrspace(3) [[R]], align 8
1227 ; ALL-NEXT: ret double [[L]]
1229 %t = shl nsw i32 %i, 3
1230 %q = addrspacecast ptr addrspace(1) %p to ptr addrspace(2)
1231 %pp = getelementptr i8, ptr addrspace(2) %q, i32 %t
1232 %r = addrspacecast ptr addrspace(2) %pp to ptr addrspace(3)
1233 %l = load double, ptr addrspace(3) %r
1237 define double @test80_as1(ptr addrspace(1) %p, i16 %i) {
1238 ; ALL-LABEL: @test80_as1(
1239 ; ALL-NEXT: [[T:%.*]] = shl nsw i16 [[I:%.*]], 3
1240 ; ALL-NEXT: [[TMP1:%.*]] = sext i16 [[T]] to i32
1241 ; ALL-NEXT: [[PP:%.*]] = getelementptr i8, ptr addrspace(1) [[P:%.*]], i32 [[TMP1]]
1242 ; ALL-NEXT: [[L:%.*]] = load double, ptr addrspace(1) [[PP]], align 8
1243 ; ALL-NEXT: ret double [[L]]
1245 %t = shl nsw i16 %i, 3
1246 %pp = getelementptr i8, ptr addrspace(1) %p, i16 %t
1247 %l = load double, ptr addrspace(1) %pp
1251 define double @test81(ptr %p, float %f) {
1252 ; ALL-LABEL: @test81(
1253 ; ALL-NEXT: [[I:%.*]] = fptosi float [[F:%.*]] to i64
1254 ; ALL-NEXT: [[PP:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[I]]
1255 ; ALL-NEXT: [[L:%.*]] = load double, ptr [[PP]], align 8
1256 ; ALL-NEXT: ret double [[L]]
1258 %i = fptosi float %f to i64
1259 %pp = getelementptr i8, ptr %p, i64 %i
1260 %l = load double, ptr %pp
1264 define i64 @test82(i64 %A) {
1265 ; ALL-LABEL: @test82(
1266 ; ALL-NEXT: [[TMP1:%.*]] = shl i64 [[A:%.*]], 1
1267 ; ALL-NEXT: [[D:%.*]] = and i64 [[TMP1]], 4294966784
1268 ; ALL-NEXT: ret i64 [[D]]
1270 %B = trunc i64 %A to i32
1273 %E = zext i32 %D to i64
1278 define i64 @test83(i16 %a, i64 %k) {
1279 ; ALL-LABEL: @test83(
1280 ; ALL-NEXT: [[CONV:%.*]] = sext i16 [[A:%.*]] to i32
1281 ; ALL-NEXT: [[TMP1:%.*]] = trunc i64 [[K:%.*]] to i32
1282 ; ALL-NEXT: [[SH_PROM:%.*]] = add i32 [[TMP1]], -1
1283 ; ALL-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[SH_PROM]]
1284 ; ALL-NEXT: [[SH_PROM1:%.*]] = zext i32 [[SHL]] to i64
1285 ; ALL-NEXT: ret i64 [[SH_PROM1]]
1287 %conv = sext i16 %a to i32
1288 %sub = add nsw i64 %k, -1
1289 %sh_prom = trunc i64 %sub to i32
1290 %shl = shl i32 %conv, %sh_prom
1291 %sh_prom1 = zext i32 %shl to i64
1295 define i8 @test84(i32 %a) {
1296 ; ALL-LABEL: @test84(
1297 ; ALL-NEXT: [[ADD:%.*]] = add i32 [[A:%.*]], 2130706432
1298 ; ALL-NEXT: [[SHR:%.*]] = lshr i32 [[ADD]], 23
1299 ; ALL-NEXT: [[TRUNC:%.*]] = trunc i32 [[SHR]] to i8
1300 ; ALL-NEXT: ret i8 [[TRUNC]]
1302 %add = add nsw i32 %a, -16777216
1303 %shr = lshr exact i32 %add, 23
1304 %trunc = trunc i32 %shr to i8
1308 define i8 @test85(i32 %a) {
1309 ; ALL-LABEL: @test85(
1310 ; ALL-NEXT: [[ADD:%.*]] = add i32 [[A:%.*]], 2130706432
1311 ; ALL-NEXT: [[SHR:%.*]] = lshr i32 [[ADD]], 23
1312 ; ALL-NEXT: [[TRUNC:%.*]] = trunc i32 [[SHR]] to i8
1313 ; ALL-NEXT: ret i8 [[TRUNC]]
1315 %add = add nuw i32 %a, -16777216
1316 %shr = lshr exact i32 %add, 23
1317 %trunc = trunc i32 %shr to i8
1321 define i16 @test86(i16 %v) {
1322 ; ALL-LABEL: @test86(
1323 ; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[V:%.*]], 4
1324 ; ALL-NEXT: ret i16 [[TMP1]]
1326 %a = sext i16 %v to i32
1328 %t = trunc i32 %s to i16
1332 define i16 @test87(i16 %v) {
1333 ; ALL-LABEL: @test87(
1334 ; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[V:%.*]], 12
1335 ; ALL-NEXT: ret i16 [[TMP1]]
1337 %c = sext i16 %v to i32
1338 %m = mul nsw i32 %c, 16
1339 %a = ashr i32 %m, 16
1340 %t = trunc i32 %a to i16
1344 define i16 @test88(i16 %v) {
1345 ; ALL-LABEL: @test88(
1346 ; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[V:%.*]], 15
1347 ; ALL-NEXT: ret i16 [[TMP1]]
1349 %a = sext i16 %v to i32
1350 %s = ashr i32 %a, 18
1351 %t = trunc i32 %s to i16
1355 define i32 @PR21388(ptr %v) {
1356 ; ALL-LABEL: @PR21388(
1357 ; ALL-NEXT: [[ICMP:%.*]] = icmp slt ptr [[V:%.*]], null
1358 ; ALL-NEXT: [[SEXT:%.*]] = sext i1 [[ICMP]] to i32
1359 ; ALL-NEXT: ret i32 [[SEXT]]
1361 %icmp = icmp slt ptr %v, null
1362 %sext = sext i1 %icmp to i32
1366 define float @sitofp_zext(i16 %a) {
1367 ; ALL-LABEL: @sitofp_zext(
1368 ; ALL-NEXT: [[SITOFP:%.*]] = uitofp i16 [[A:%.*]] to float
1369 ; ALL-NEXT: ret float [[SITOFP]]
1371 %zext = zext i16 %a to i32
1372 %sitofp = sitofp i32 %zext to float
1376 define i1 @PR23309(i32 %A, i32 %B) {
1377 ; ALL-LABEL: @PR23309(
1378 ; ALL-NEXT: [[SUB:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]
1379 ; ALL-NEXT: [[TRUNC:%.*]] = trunc i32 [[SUB]] to i1
1380 ; ALL-NEXT: ret i1 [[TRUNC]]
1382 %add = add i32 %A, -4
1383 %sub = sub nsw i32 %add, %B
1384 %trunc = trunc i32 %sub to i1
1388 define i1 @PR23309v2(i32 %A, i32 %B) {
1389 ; ALL-LABEL: @PR23309v2(
1390 ; ALL-NEXT: [[SUB:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
1391 ; ALL-NEXT: [[TRUNC:%.*]] = trunc i32 [[SUB]] to i1
1392 ; ALL-NEXT: ret i1 [[TRUNC]]
1394 %add = add i32 %A, -4
1395 %sub = add nuw i32 %add, %B
1396 %trunc = trunc i32 %sub to i1
1400 define i16 @PR24763(i8 %V) {
1401 ; ALL-LABEL: @PR24763(
1402 ; ALL-NEXT: [[TMP1:%.*]] = ashr i8 [[V:%.*]], 1
1403 ; ALL-NEXT: [[T:%.*]] = sext i8 [[TMP1]] to i16
1404 ; ALL-NEXT: ret i16 [[T]]
1406 %conv = sext i8 %V to i32
1407 %l = lshr i32 %conv, 1
1408 %t = trunc i32 %l to i16
1412 define i64 @PR28745() {
1413 ; BE-LABEL: @PR28745(
1414 ; BE-NEXT: ret i64 1
1416 ; LE-LABEL: @PR28745(
1417 ; LE-NEXT: ret i64 0
1419 %c = icmp eq i16 extractelement (<2 x i16> bitcast (<1 x i32> <i32 1> to <2 x i16>), i32 0), 0
1420 %s = select i1 %c, { i32 } { i32 1 }, { i32 } zeroinitializer
1421 %e = extractvalue { i32 } %s, 0
1422 %b = zext i32 %e to i64
1426 define i32 @test89() {
1427 ; BE-LABEL: @test89(
1428 ; BE-NEXT: ret i32 393216
1430 ; LE-LABEL: @test89(
1431 ; LE-NEXT: ret i32 6
1433 ret i32 bitcast (<2 x i16> <i16 6, i16 poison> to i32)
1436 define <2 x i32> @test90() {
1437 ; BE-LABEL: @test90(
1438 ; BE-NEXT: ret <2 x i32> <i32 0, i32 15360>
1440 ; LE-LABEL: @test90(
1441 ; LE-NEXT: ret <2 x i32> <i32 0, i32 1006632960>
1443 %t6 = bitcast <4 x half> <half poison, half poison, half poison, half 0xH3C00> to <2 x i32>
1447 ; Do not optimize to ashr i64 (shift by 48 > 96 - 64)
1448 define i64 @test91(i64 %A) {
1449 ; ALL-LABEL: @test91(
1450 ; ALL-NEXT: [[B:%.*]] = sext i64 [[A:%.*]] to i96
1451 ; ALL-NEXT: [[C:%.*]] = lshr i96 [[B]], 48
1452 ; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i96 [[C]] to i64
1453 ; ALL-NEXT: ret i64 [[D]]
1455 %B = sext i64 %A to i96
1456 %C = lshr i96 %B, 48
1457 %D = trunc i96 %C to i64
1461 ; Do optimize to ashr i64 (shift by 32 <= 96 - 64)
1462 define i64 @test92(i64 %A) {
1463 ; ALL-LABEL: @test92(
1464 ; ALL-NEXT: [[TMP1:%.*]] = ashr i64 [[A:%.*]], 32
1465 ; ALL-NEXT: ret i64 [[TMP1]]
1467 %B = sext i64 %A to i96
1468 %C = lshr i96 %B, 32
1469 %D = trunc i96 %C to i64
1473 ; When optimizing to ashr i32, don't shift by more than 31.
1474 define i32 @test93(i32 %A) {
1475 ; ALL-LABEL: @test93(
1476 ; ALL-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
1477 ; ALL-NEXT: ret i32 [[TMP1]]
1479 %B = sext i32 %A to i96
1480 %C = lshr i96 %B, 64
1481 %D = trunc i96 %C to i32
1485 define i8 @trunc_lshr_sext(i8 %A) {
1486 ; ALL-LABEL: @trunc_lshr_sext(
1487 ; ALL-NEXT: [[D:%.*]] = ashr i8 [[A:%.*]], 6
1488 ; ALL-NEXT: ret i8 [[D]]
1490 %B = sext i8 %A to i32
1492 %D = trunc i32 %C to i8
1496 define i8 @trunc_lshr_sext_exact(i8 %A) {
1497 ; ALL-LABEL: @trunc_lshr_sext_exact(
1498 ; ALL-NEXT: [[D:%.*]] = ashr exact i8 [[A:%.*]], 6
1499 ; ALL-NEXT: ret i8 [[D]]
1501 %B = sext i8 %A to i32
1502 %C = lshr exact i32 %B, 6
1503 %D = trunc i32 %C to i8
1507 define <2 x i8> @trunc_lshr_sext_uniform(<2 x i8> %A) {
1508 ; ALL-LABEL: @trunc_lshr_sext_uniform(
1509 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A:%.*]], splat (i8 6)
1510 ; ALL-NEXT: ret <2 x i8> [[D]]
1512 %B = sext <2 x i8> %A to <2 x i32>
1513 %C = lshr <2 x i32> %B, <i32 6, i32 6>
1514 %D = trunc <2 x i32> %C to <2 x i8>
1518 define <2 x i8> @trunc_lshr_sext_uniform_poison(<2 x i8> %A) {
1519 ; ALL-LABEL: @trunc_lshr_sext_uniform_poison(
1520 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A:%.*]], <i8 6, i8 poison>
1521 ; ALL-NEXT: ret <2 x i8> [[D]]
1523 %B = sext <2 x i8> %A to <2 x i32>
1524 %C = lshr <2 x i32> %B, <i32 6, i32 poison>
1525 %D = trunc <2 x i32> %C to <2 x i8>
1529 define <2 x i8> @trunc_lshr_sext_nonuniform(<2 x i8> %A) {
1530 ; ALL-LABEL: @trunc_lshr_sext_nonuniform(
1531 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A:%.*]], <i8 6, i8 2>
1532 ; ALL-NEXT: ret <2 x i8> [[D]]
1534 %B = sext <2 x i8> %A to <2 x i32>
1535 %C = lshr <2 x i32> %B, <i32 6, i32 2>
1536 %D = trunc <2 x i32> %C to <2 x i8>
1540 define <3 x i8> @trunc_lshr_sext_nonuniform_poison(<3 x i8> %A) {
1541 ; ALL-LABEL: @trunc_lshr_sext_nonuniform_poison(
1542 ; ALL-NEXT: [[D:%.*]] = ashr <3 x i8> [[A:%.*]], <i8 6, i8 2, i8 poison>
1543 ; ALL-NEXT: ret <3 x i8> [[D]]
1545 %B = sext <3 x i8> %A to <3 x i32>
1546 %C = lshr <3 x i32> %B, <i32 6, i32 2, i32 poison>
1547 %D = trunc <3 x i32> %C to <3 x i8>
1551 define <2 x i8> @trunc_lshr_sext_uses1(<2 x i8> %A) {
1552 ; ALL-LABEL: @trunc_lshr_sext_uses1(
1553 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1554 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
1555 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A]], splat (i8 6)
1556 ; ALL-NEXT: ret <2 x i8> [[D]]
1558 %B = sext <2 x i8> %A to <2 x i32>
1559 call void @use_v2i32(<2 x i32> %B)
1560 %C = lshr <2 x i32> %B, <i32 6, i32 6>
1561 %D = trunc <2 x i32> %C to <2 x i8>
1565 define i8 @trunc_lshr_sext_uses2(i8 %A) {
1566 ; ALL-LABEL: @trunc_lshr_sext_uses2(
1567 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1568 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 6
1569 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1570 ; ALL-NEXT: [[D:%.*]] = ashr i8 [[A]], 6
1571 ; ALL-NEXT: ret i8 [[D]]
1573 %B = sext i8 %A to i32
1575 call void @use_i32(i32 %C)
1576 %D = trunc i32 %C to i8
1580 define <2 x i8> @trunc_lshr_sext_uses3(<2 x i8> %A) {
1581 ; ALL-LABEL: @trunc_lshr_sext_uses3(
1582 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1583 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
1584 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 6)
1585 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1586 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A]], splat (i8 6)
1587 ; ALL-NEXT: ret <2 x i8> [[D]]
1589 %B = sext <2 x i8 >%A to <2 x i32>
1590 call void @use_v2i32(<2 x i32> %B)
1591 %C = lshr <2 x i32> %B, <i32 6, i32 6>
1592 call void @use_v2i32(<2 x i32> %C)
1593 %D = trunc <2 x i32 >%C to <2 x i8>
1597 define <2 x i8> @trunc_lshr_overshift_sext(<2 x i8> %A) {
1598 ; ALL-LABEL: @trunc_lshr_overshift_sext(
1599 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A:%.*]], splat (i8 7)
1600 ; ALL-NEXT: ret <2 x i8> [[D]]
1602 %B = sext <2 x i8> %A to <2 x i32>
1603 %C = lshr <2 x i32> %B, <i32 8, i32 8>
1604 %D = trunc <2 x i32> %C to <2 x i8>
1608 define i8 @trunc_lshr_overshift_sext_uses1(i8 %A) {
1609 ; ALL-LABEL: @trunc_lshr_overshift_sext_uses1(
1610 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1611 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1612 ; ALL-NEXT: [[D:%.*]] = ashr i8 [[A]], 7
1613 ; ALL-NEXT: ret i8 [[D]]
1615 %B = sext i8 %A to i32
1616 call void @use_i32(i32 %B)
1618 %D = trunc i32 %C to i8
1622 define <2 x i8> @trunc_lshr_overshift_sext_uses2(<2 x i8> %A) {
1623 ; ALL-LABEL: @trunc_lshr_overshift_sext_uses2(
1624 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1625 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 8)
1626 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1627 ; ALL-NEXT: [[D:%.*]] = ashr <2 x i8> [[A]], splat (i8 7)
1628 ; ALL-NEXT: ret <2 x i8> [[D]]
1630 %B = sext <2 x i8> %A to <2 x i32>
1631 %C = lshr <2 x i32> %B, <i32 8, i32 8>
1632 call void @use_v2i32(<2 x i32> %C)
1633 %D = trunc <2 x i32> %C to <2 x i8>
1637 define i8 @trunc_lshr_overshift_sext_uses3(i8 %A) {
1638 ; ALL-LABEL: @trunc_lshr_overshift_sext_uses3(
1639 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1640 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1641 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 8
1642 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1643 ; ALL-NEXT: [[D:%.*]] = ashr i8 [[A]], 7
1644 ; ALL-NEXT: ret i8 [[D]]
1646 %B = sext i8 %A to i32
1647 call void @use_i32(i32 %B)
1649 call void @use_i32(i32 %C)
1650 %D = trunc i32 %C to i8
1654 define i8 @trunc_lshr_sext_wide_input(i16 %A) {
1655 ; ALL-LABEL: @trunc_lshr_sext_wide_input(
1656 ; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[A:%.*]], 9
1657 ; ALL-NEXT: [[D:%.*]] = trunc nsw i16 [[TMP1]] to i8
1658 ; ALL-NEXT: ret i8 [[D]]
1660 %B = sext i16 %A to i32
1662 %D = trunc i32 %C to i8
1666 define i8 @trunc_lshr_sext_wide_input_exact(i16 %A) {
1667 ; ALL-LABEL: @trunc_lshr_sext_wide_input_exact(
1668 ; ALL-NEXT: [[TMP1:%.*]] = ashr exact i16 [[A:%.*]], 9
1669 ; ALL-NEXT: [[D:%.*]] = trunc nsw i16 [[TMP1]] to i8
1670 ; ALL-NEXT: ret i8 [[D]]
1672 %B = sext i16 %A to i32
1673 %C = lshr exact i32 %B, 9
1674 %D = trunc i32 %C to i8
1678 define <2 x i8> @trunc_lshr_sext_wide_input_uses1(<2 x i16> %A) {
1679 ; ALL-LABEL: @trunc_lshr_sext_wide_input_uses1(
1680 ; ALL-NEXT: [[B:%.*]] = sext <2 x i16> [[A:%.*]] to <2 x i32>
1681 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
1682 ; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i16> [[A]], splat (i16 9)
1683 ; ALL-NEXT: [[D:%.*]] = trunc nsw <2 x i16> [[TMP1]] to <2 x i8>
1684 ; ALL-NEXT: ret <2 x i8> [[D]]
1686 %B = sext <2 x i16> %A to <2 x i32>
1687 call void @use_v2i32(<2 x i32> %B)
1688 %C = lshr <2 x i32> %B, <i32 9, i32 9>
1689 %D = trunc <2 x i32> %C to <2 x i8>
1693 define i8 @trunc_lshr_sext_wide_input_uses2(i16 %A) {
1694 ; ALL-LABEL: @trunc_lshr_sext_wide_input_uses2(
1695 ; ALL-NEXT: [[B:%.*]] = sext i16 [[A:%.*]] to i32
1696 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 9
1697 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1698 ; ALL-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
1699 ; ALL-NEXT: ret i8 [[D]]
1701 %B = sext i16 %A to i32
1703 call void @use_i32(i32 %C)
1704 %D = trunc i32 %C to i8
1708 define <2 x i8> @trunc_lshr_sext_wide_input_uses3(<2 x i16> %A) {
1709 ; ALL-LABEL: @trunc_lshr_sext_wide_input_uses3(
1710 ; ALL-NEXT: [[B:%.*]] = sext <2 x i16> [[A:%.*]] to <2 x i32>
1711 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
1712 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 9)
1713 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1714 ; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
1715 ; ALL-NEXT: ret <2 x i8> [[D]]
1717 %B = sext <2 x i16 >%A to <2 x i32>
1718 call void @use_v2i32(<2 x i32> %B)
1719 %C = lshr <2 x i32> %B, <i32 9, i32 9>
1720 call void @use_v2i32(<2 x i32> %C)
1721 %D = trunc <2 x i32 >%C to <2 x i8>
1725 define <2 x i8> @trunc_lshr_overshift_wide_input_sext(<2 x i16> %A) {
1726 ; ALL-LABEL: @trunc_lshr_overshift_wide_input_sext(
1727 ; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i16> [[A:%.*]], splat (i16 15)
1728 ; ALL-NEXT: [[D:%.*]] = trunc nsw <2 x i16> [[TMP1]] to <2 x i8>
1729 ; ALL-NEXT: ret <2 x i8> [[D]]
1731 %B = sext <2 x i16> %A to <2 x i32>
1732 %C = lshr <2 x i32> %B, <i32 16, i32 16>
1733 %D = trunc <2 x i32> %C to <2 x i8>
1737 define i8 @trunc_lshr_overshift_sext_wide_input_uses1(i16 %A) {
1738 ; ALL-LABEL: @trunc_lshr_overshift_sext_wide_input_uses1(
1739 ; ALL-NEXT: [[B:%.*]] = sext i16 [[A:%.*]] to i32
1740 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1741 ; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[A]], 15
1742 ; ALL-NEXT: [[D:%.*]] = trunc nsw i16 [[TMP1]] to i8
1743 ; ALL-NEXT: ret i8 [[D]]
1745 %B = sext i16 %A to i32
1746 call void @use_i32(i32 %B)
1747 %C = lshr i32 %B, 16
1748 %D = trunc i32 %C to i8
1752 define <2 x i8> @trunc_lshr_overshift_sext_wide_input_uses2(<2 x i16> %A) {
1753 ; ALL-LABEL: @trunc_lshr_overshift_sext_wide_input_uses2(
1754 ; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i16> [[A:%.*]], splat (i16 15)
1755 ; ALL-NEXT: [[C:%.*]] = zext <2 x i16> [[TMP1]] to <2 x i32>
1756 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1757 ; ALL-NEXT: [[D:%.*]] = trunc nsw <2 x i16> [[TMP1]] to <2 x i8>
1758 ; ALL-NEXT: ret <2 x i8> [[D]]
1760 %B = sext <2 x i16> %A to <2 x i32>
1761 %C = lshr <2 x i32> %B, <i32 16, i32 16>
1762 call void @use_v2i32(<2 x i32> %C)
1763 %D = trunc <2 x i32> %C to <2 x i8>
1767 define i8 @trunc_lshr_overshift_sext_wide_input_uses3(i16 %A) {
1768 ; ALL-LABEL: @trunc_lshr_overshift_sext_wide_input_uses3(
1769 ; ALL-NEXT: [[B:%.*]] = sext i16 [[A:%.*]] to i32
1770 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1771 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 16
1772 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1773 ; ALL-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
1774 ; ALL-NEXT: ret i8 [[D]]
1776 %B = sext i16 %A to i32
1777 call void @use_i32(i32 %B)
1778 %C = lshr i32 %B, 16
1779 call void @use_i32(i32 %C)
1780 %D = trunc i32 %C to i8
1784 define i16 @trunc_lshr_sext_narrow_input(i8 %A) {
1785 ; ALL-LABEL: @trunc_lshr_sext_narrow_input(
1786 ; ALL-NEXT: [[TMP1:%.*]] = ashr i8 [[A:%.*]], 6
1787 ; ALL-NEXT: [[D:%.*]] = sext i8 [[TMP1]] to i16
1788 ; ALL-NEXT: ret i16 [[D]]
1790 %B = sext i8 %A to i32
1792 %D = trunc i32 %C to i16
1796 define <2 x i16> @trunc_lshr_sext_narrow_input_uses1(<2 x i8> %A) {
1797 ; ALL-LABEL: @trunc_lshr_sext_narrow_input_uses1(
1798 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1799 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
1800 ; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i8> [[A]], splat (i8 6)
1801 ; ALL-NEXT: [[D:%.*]] = sext <2 x i8> [[TMP1]] to <2 x i16>
1802 ; ALL-NEXT: ret <2 x i16> [[D]]
1804 %B = sext <2 x i8> %A to <2 x i32>
1805 call void @use_v2i32(<2 x i32> %B)
1806 %C = lshr <2 x i32> %B, <i32 6, i32 6>
1807 %D = trunc <2 x i32> %C to <2 x i16>
1811 define i16 @trunc_lshr_sext_narrow_input_uses2(i8 %A) {
1812 ; ALL-LABEL: @trunc_lshr_sext_narrow_input_uses2(
1813 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1814 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 6
1815 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1816 ; ALL-NEXT: [[D:%.*]] = trunc i32 [[C]] to i16
1817 ; ALL-NEXT: ret i16 [[D]]
1819 %B = sext i8 %A to i32
1821 call void @use_i32(i32 %C)
1822 %D = trunc i32 %C to i16
1826 define <2 x i16> @trunc_lshr_sext_narrow_input_uses3(<2 x i8> %A) {
1827 ; ALL-LABEL: @trunc_lshr_sext_narrow_input_uses3(
1828 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1829 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
1830 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 6)
1831 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1832 ; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i16>
1833 ; ALL-NEXT: ret <2 x i16> [[D]]
1835 %B = sext <2 x i8 >%A to <2 x i32>
1836 call void @use_v2i32(<2 x i32> %B)
1837 %C = lshr <2 x i32> %B, <i32 6, i32 6>
1838 call void @use_v2i32(<2 x i32> %C)
1839 %D = trunc <2 x i32 >%C to <2 x i16>
1843 define <2 x i16> @trunc_lshr_overshift_narrow_input_sext(<2 x i8> %A) {
1844 ; ALL-LABEL: @trunc_lshr_overshift_narrow_input_sext(
1845 ; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i8> [[A:%.*]], splat (i8 7)
1846 ; ALL-NEXT: [[D:%.*]] = sext <2 x i8> [[TMP1]] to <2 x i16>
1847 ; ALL-NEXT: ret <2 x i16> [[D]]
1849 %B = sext <2 x i8> %A to <2 x i32>
1850 %C = lshr <2 x i32> %B, <i32 8, i32 8>
1851 %D = trunc <2 x i32> %C to <2 x i16>
1855 define i16 @trunc_lshr_overshift_sext_narrow_input_uses1(i8 %A) {
1856 ; ALL-LABEL: @trunc_lshr_overshift_sext_narrow_input_uses1(
1857 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1858 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1859 ; ALL-NEXT: [[TMP1:%.*]] = ashr i8 [[A]], 7
1860 ; ALL-NEXT: [[D:%.*]] = sext i8 [[TMP1]] to i16
1861 ; ALL-NEXT: ret i16 [[D]]
1863 %B = sext i8 %A to i32
1864 call void @use_i32(i32 %B)
1866 %D = trunc i32 %C to i16
1870 define <2 x i16> @trunc_lshr_overshift_sext_narrow_input_uses2(<2 x i8> %A) {
1871 ; ALL-LABEL: @trunc_lshr_overshift_sext_narrow_input_uses2(
1872 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1873 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 8)
1874 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1875 ; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i16>
1876 ; ALL-NEXT: ret <2 x i16> [[D]]
1878 %B = sext <2 x i8> %A to <2 x i32>
1879 %C = lshr <2 x i32> %B, <i32 8, i32 8>
1880 call void @use_v2i32(<2 x i32> %C)
1881 %D = trunc <2 x i32> %C to <2 x i16>
1885 define i16 @trunc_lshr_overshift_sext_narrow_input_uses3(i8 %A) {
1886 ; ALL-LABEL: @trunc_lshr_overshift_sext_narrow_input_uses3(
1887 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1888 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1889 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 8
1890 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1891 ; ALL-NEXT: [[D:%.*]] = trunc i32 [[C]] to i16
1892 ; ALL-NEXT: ret i16 [[D]]
1894 %B = sext i8 %A to i32
1895 call void @use_i32(i32 %B)
1897 call void @use_i32(i32 %C)
1898 %D = trunc i32 %C to i16
1902 define <2 x i8> @trunc_lshr_overshift2_sext(<2 x i8> %A) {
1903 ; ALL-LABEL: @trunc_lshr_overshift2_sext(
1904 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1905 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 25)
1906 ; ALL-NEXT: [[D:%.*]] = trunc nuw nsw <2 x i32> [[C]] to <2 x i8>
1907 ; ALL-NEXT: ret <2 x i8> [[D]]
1909 %B = sext <2 x i8> %A to <2 x i32>
1910 %C = lshr <2 x i32> %B, <i32 25, i32 25>
1911 %D = trunc <2 x i32> %C to <2 x i8>
1915 define i8 @trunc_lshr_overshift2_sext_uses1(i8 %A) {
1916 ; ALL-LABEL: @trunc_lshr_overshift2_sext_uses1(
1917 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1918 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1919 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
1920 ; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i32 [[C]] to i8
1921 ; ALL-NEXT: ret i8 [[D]]
1923 %B = sext i8 %A to i32
1924 call void @use_i32(i32 %B)
1925 %C = lshr i32 %B, 25
1926 %D = trunc i32 %C to i8
1930 define <2 x i8> @trunc_lshr_overshift2_sext_uses2(<2 x i8> %A) {
1931 ; ALL-LABEL: @trunc_lshr_overshift2_sext_uses2(
1932 ; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
1933 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], splat (i32 25)
1934 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1935 ; ALL-NEXT: [[D:%.*]] = trunc nuw nsw <2 x i32> [[C]] to <2 x i8>
1936 ; ALL-NEXT: ret <2 x i8> [[D]]
1938 %B = sext <2 x i8> %A to <2 x i32>
1939 %C = lshr <2 x i32> %B, <i32 25, i32 25>
1940 call void @use_v2i32(<2 x i32> %C)
1941 %D = trunc <2 x i32> %C to <2 x i8>
1945 define i8 @trunc_lshr_overshift2_sext_uses3(i8 %A) {
1946 ; ALL-LABEL: @trunc_lshr_overshift2_sext_uses3(
1947 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
1948 ; ALL-NEXT: call void @use_i32(i32 [[B]])
1949 ; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
1950 ; ALL-NEXT: call void @use_i32(i32 [[C]])
1951 ; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i32 [[C]] to i8
1952 ; ALL-NEXT: ret i8 [[D]]
1954 %B = sext i8 %A to i32
1955 call void @use_i32(i32 %B)
1956 %C = lshr i32 %B, 25
1957 call void @use_i32(i32 %C)
1958 %D = trunc i32 %C to i8
1962 define i8 @trunc_lshr_zext(i8 %A) {
1963 ; ALL-LABEL: @trunc_lshr_zext(
1964 ; ALL-NEXT: [[TMP1:%.*]] = lshr i8 [[A:%.*]], 6
1965 ; ALL-NEXT: ret i8 [[TMP1]]
1967 %B = zext i8 %A to i32
1969 %D = trunc i32 %C to i8
1973 define i8 @trunc_lshr_zext_exact(i8 %A) {
1974 ; ALL-LABEL: @trunc_lshr_zext_exact(
1975 ; ALL-NEXT: [[TMP1:%.*]] = lshr i8 [[A:%.*]], 6
1976 ; ALL-NEXT: ret i8 [[TMP1]]
1978 %B = zext i8 %A to i32
1979 %C = lshr exact i32 %B, 6
1980 %D = trunc i32 %C to i8
1984 define <2 x i8> @trunc_lshr_zext_uniform(<2 x i8> %A) {
1985 ; ALL-LABEL: @trunc_lshr_zext_uniform(
1986 ; ALL-NEXT: [[TMP1:%.*]] = lshr <2 x i8> [[A:%.*]], splat (i8 6)
1987 ; ALL-NEXT: ret <2 x i8> [[TMP1]]
1989 %B = zext <2 x i8> %A to <2 x i32>
1990 %C = lshr <2 x i32> %B, <i32 6, i32 6>
1991 %D = trunc <2 x i32> %C to <2 x i8>
1995 define <2 x i8> @trunc_lshr_zext_uniform_poison(<2 x i8> %A) {
1996 ; ALL-LABEL: @trunc_lshr_zext_uniform_poison(
1997 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i8> [[A:%.*]], <i8 6, i8 poison>
1998 ; ALL-NEXT: ret <2 x i8> [[C]]
2000 %B = zext <2 x i8> %A to <2 x i32>
2001 %C = lshr <2 x i32> %B, <i32 6, i32 poison>
2002 %D = trunc <2 x i32> %C to <2 x i8>
2006 define <2 x i8> @trunc_lshr_zext_nonuniform(<2 x i8> %A) {
2007 ; ALL-LABEL: @trunc_lshr_zext_nonuniform(
2008 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i8> [[A:%.*]], <i8 6, i8 2>
2009 ; ALL-NEXT: ret <2 x i8> [[C]]
2011 %B = zext <2 x i8> %A to <2 x i32>
2012 %C = lshr <2 x i32> %B, <i32 6, i32 2>
2013 %D = trunc <2 x i32> %C to <2 x i8>
2017 define <3 x i8> @trunc_lshr_zext_nonuniform_poison(<3 x i8> %A) {
2018 ; ALL-LABEL: @trunc_lshr_zext_nonuniform_poison(
2019 ; ALL-NEXT: [[C:%.*]] = lshr <3 x i8> [[A:%.*]], <i8 6, i8 2, i8 poison>
2020 ; ALL-NEXT: ret <3 x i8> [[C]]
2022 %B = zext <3 x i8> %A to <3 x i32>
2023 %C = lshr <3 x i32> %B, <i32 6, i32 2, i32 poison>
2024 %D = trunc <3 x i32> %C to <3 x i8>
2028 define <2 x i8> @trunc_lshr_zext_uses1(<2 x i8> %A) {
2029 ; ALL-LABEL: @trunc_lshr_zext_uses1(
2030 ; ALL-NEXT: [[B:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
2031 ; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
2032 ; ALL-NEXT: [[C:%.*]] = lshr <2 x i8> [[A]], splat (i8 6)
2033 ; ALL-NEXT: ret <2 x i8> [[C]]
2035 %B = zext <2 x i8> %A to <2 x i32>
2036 call void @use_v2i32(<2 x i32> %B)
2037 %C = lshr <2 x i32> %B, <i32 6, i32 6>
2038 %D = trunc <2 x i32> %C to <2 x i8>
2042 ; The following four tests sext + lshr + trunc patterns.
2045 define i8 @pr33078_1(i8 %A) {
2046 ; ALL-LABEL: @pr33078_1(
2047 ; ALL-NEXT: [[TMP1:%.*]] = ashr i8 [[A:%.*]], 7
2048 ; ALL-NEXT: ret i8 [[TMP1]]
2050 %B = sext i8 %A to i16
2052 %D = trunc i16 %C to i8
2056 define i12 @pr33078_2(i8 %A) {
2057 ; ALL-LABEL: @pr33078_2(
2058 ; ALL-NEXT: [[TMP1:%.*]] = ashr i8 [[A:%.*]], 4
2059 ; ALL-NEXT: [[D:%.*]] = sext i8 [[TMP1]] to i12
2060 ; ALL-NEXT: ret i12 [[D]]
2062 %B = sext i8 %A to i16
2064 %D = trunc i16 %C to i12
2068 define i4 @pr33078_3(i8 %A) {
2069 ; ALL-LABEL: @pr33078_3(
2070 ; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i16
2071 ; ALL-NEXT: [[C:%.*]] = lshr i16 [[B]], 12
2072 ; ALL-NEXT: [[D:%.*]] = trunc nuw i16 [[C]] to i4
2073 ; ALL-NEXT: ret i4 [[D]]
2075 %B = sext i8 %A to i16
2076 %C = lshr i16 %B, 12
2077 %D = trunc i16 %C to i4
2081 define i8 @pr33078_4(i3 %x) {
2082 ; Don't turn this in an `ashr`. This was getting miscompiled
2083 ; ALL-LABEL: @pr33078_4(
2084 ; ALL-NEXT: [[B:%.*]] = sext i3 [[X:%.*]] to i16
2085 ; ALL-NEXT: [[C:%.*]] = lshr i16 [[B]], 13
2086 ; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i16 [[C]] to i8
2087 ; ALL-NEXT: ret i8 [[D]]
2089 %B = sext i3 %x to i16
2090 %C = lshr i16 %B, 13
2091 %D = trunc i16 %C to i8
2095 ; (sext (xor (cmp), -1)) -> (sext (!cmp))
2096 define i64 @test94(i32 %a) {
2097 ; ALL-LABEL: @test94(
2098 ; ALL-NEXT: [[TMP1:%.*]] = icmp ne i32 [[A:%.*]], -2
2099 ; ALL-NEXT: [[TMP2:%.*]] = sext i1 [[TMP1]] to i64
2100 ; ALL-NEXT: ret i64 [[TMP2]]
2102 %1 = icmp eq i32 %a, -2
2103 %2 = sext i1 %1 to i8
2105 %4 = sext i8 %3 to i64
2109 ; We should be able to remove the zext and trunc here.
2110 define i32 @test95(i32 %x) {
2111 ; ALL-LABEL: @test95(
2112 ; ALL-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 6
2113 ; ALL-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 2
2114 ; ALL-NEXT: [[TMP3:%.*]] = or disjoint i32 [[TMP2]], 40
2115 ; ALL-NEXT: ret i32 [[TMP3]]
2117 %1 = trunc i32 %x to i8
2121 %5 = zext i8 %4 to i32