1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4 define i16 @sext_shl_trunc_same_size(i16 %x, i32 %y) {
5 ; CHECK-LABEL: @sext_shl_trunc_same_size(
6 ; CHECK-NEXT: [[CONV1:%.*]] = zext i16 [[X:%.*]] to i32
7 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV1]], [[Y:%.*]]
8 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i16
9 ; CHECK-NEXT: ret i16 [[T]]
11 %conv = sext i16 %x to i32
12 %shl = shl i32 %conv, %y
13 %t = trunc i32 %shl to i16
17 define i5 @sext_shl_trunc_smaller(i16 %x, i32 %y) {
18 ; CHECK-LABEL: @sext_shl_trunc_smaller(
19 ; CHECK-NEXT: [[CONV1:%.*]] = zext i16 [[X:%.*]] to i32
20 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV1]], [[Y:%.*]]
21 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i5
22 ; CHECK-NEXT: ret i5 [[T]]
24 %conv = sext i16 %x to i32
25 %shl = shl i32 %conv, %y
26 %t = trunc i32 %shl to i5
30 ; negative test - demanding 1 high-bit too many to change the extend
32 define i17 @sext_shl_trunc_larger(i16 %x, i32 %y) {
33 ; CHECK-LABEL: @sext_shl_trunc_larger(
34 ; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32
35 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]]
36 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[SHL]] to i17
37 ; CHECK-NEXT: ret i17 [[T]]
39 %conv = sext i16 %x to i32
40 %shl = shl i32 %conv, %y
41 %t = trunc i32 %shl to i17
45 define i32 @sext_shl_mask(i16 %x, i32 %y) {
46 ; CHECK-LABEL: @sext_shl_mask(
47 ; CHECK-NEXT: [[CONV1:%.*]] = zext i16 [[X:%.*]] to i32
48 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV1]], [[Y:%.*]]
49 ; CHECK-NEXT: [[T:%.*]] = and i32 [[SHL]], 65535
50 ; CHECK-NEXT: ret i32 [[T]]
52 %conv = sext i16 %x to i32
53 %shl = shl i32 %conv, %y
54 %t = and i32 %shl, 65535
58 ; negative test - demanding a bit that could change with sext
60 define i32 @sext_shl_mask_higher(i16 %x, i32 %y) {
61 ; CHECK-LABEL: @sext_shl_mask_higher(
62 ; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[X:%.*]] to i32
63 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV]], [[Y:%.*]]
64 ; CHECK-NEXT: [[T:%.*]] = and i32 [[SHL]], 65536
65 ; CHECK-NEXT: ret i32 [[T]]
67 %conv = sext i16 %x to i32
68 %shl = shl i32 %conv, %y
69 %t = and i32 %shl, 65536
73 ; May need some, but not all of the bits set by the 'or'.
75 define i32 @set_shl_mask(i32 %x, i32 %y) {
76 ; CHECK-LABEL: @set_shl_mask(
77 ; CHECK-NEXT: [[Z:%.*]] = or i32 [[X:%.*]], 65537
78 ; CHECK-NEXT: [[S:%.*]] = shl i32 [[Z]], [[Y:%.*]]
79 ; CHECK-NEXT: [[R:%.*]] = and i32 [[S]], 65536
80 ; CHECK-NEXT: ret i32 [[R]]
82 %z = or i32 %x, 196609
84 %r = and i32 %s, 65536
90 define i8 @must_drop_poison(i32 %x, i32 %y) {
91 ; CHECK-LABEL: @must_drop_poison(
92 ; CHECK-NEXT: [[S:%.*]] = shl i32 [[X:%.*]], [[Y:%.*]]
93 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[S]] to i8
94 ; CHECK-NEXT: ret i8 [[T]]
97 %s = shl nuw nsw i32 %a, %y
98 %t = trunc i32 %s to i8
102 ; This would infinite loop with D110170 / bb9333c3504a
104 define i32 @f_t15_t01_t09(i40 %t2) {
105 ; CHECK-LABEL: @f_t15_t01_t09(
106 ; CHECK-NEXT: [[SH_DIFF:%.*]] = ashr i40 [[T2:%.*]], 15
107 ; CHECK-NEXT: [[TR_SH_DIFF:%.*]] = trunc i40 [[SH_DIFF]] to i32
108 ; CHECK-NEXT: [[SHL1:%.*]] = and i32 [[TR_SH_DIFF]], -65536
109 ; CHECK-NEXT: ret i32 [[SHL1]]
111 %downscale = ashr i40 %t2, 31
112 %resize = trunc i40 %downscale to i32
113 %shl1 = shl i32 %resize, 16
114 %resize1 = ashr i32 %shl1, 16
115 %r = shl i32 %resize1, 31