1 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 define i32 @or_and_shifts1(i32 %x) {
4 ; CHECK-LABEL: @or_and_shifts1(
5 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 3
6 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 8
7 ; CHECK-NEXT: [[TMP3:%.*]] = shl i32 %x, 5
8 ; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], 32
9 ; CHECK-NEXT: [[TMP5:%.*]] = or i32 [[TMP2]], [[TMP4]]
10 ; CHECK-NEXT: ret i32 [[TMP5]]
20 define i32 @or_and_shifts2(i32 %x) {
21 ; CHECK-LABEL: @or_and_shifts2(
22 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 3
23 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 896
24 ; CHECK-NEXT: [[TMP3:%.*]] = lshr i32 %x, 4
25 ; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], 7
26 ; CHECK-NEXT: [[TMP5:%.*]] = or i32 [[TMP2]], [[TMP4]]
27 ; CHECK-NEXT: ret i32 [[TMP5]]
37 define i32 @or_and_shift_shift_and(i32 %x) {
38 ; CHECK-LABEL: @or_and_shift_shift_and(
39 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 3
40 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 56
41 ; CHECK-NEXT: [[TMP3:%.*]] = shl i32 %x, 2
42 ; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], 28
43 ; CHECK-NEXT: [[TMP5:%.*]] = or i32 [[TMP2]], [[TMP4]]
44 ; CHECK-NEXT: ret i32 [[TMP5]]
54 define i32 @multiuse1(i32 %x) {
55 ; CHECK-LABEL: @multiuse1(
56 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 6
57 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 384
58 ; CHECK-NEXT: [[TMP3:%.*]] = lshr i32 %x, 1
59 ; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], 3
60 ; CHECK-NEXT: [[TMP5:%.*]] = or i32 [[TMP4]], [[TMP2]]
61 ; CHECK-NEXT: ret i32 [[TMP5]]
65 %3 = shl nuw nsw i32 %1, 6
66 %4 = lshr exact i32 %1, 1
67 %5 = shl nuw nsw i32 %2, 6
68 %6 = lshr exact i32 %2, 1
75 define i32 @multiuse2(i32 %x) {
76 ; CHECK-LABEL: @multiuse2(
77 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 1
78 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 12
79 ; CHECK-NEXT: [[TMP3:%.*]] = shl i32 %x, 8
80 ; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], 24576
81 ; CHECK-NEXT: [[TMP5:%.*]] = shl i32 %x, 8
82 ; CHECK-NEXT: [[TMP6:%.*]] = and i32 [[TMP5]], 7680
83 ; CHECK-NEXT: [[TMP7:%.*]] = or i32 [[TMP4]], [[TMP6]]
84 ; CHECK-NEXT: [[TMP8:%.*]] = shl i32 %x, 1
85 ; CHECK-NEXT: [[TMP9:%.*]] = and i32 [[TMP8]], 240
86 ; CHECK-NEXT: [[TMP10:%.*]] = or i32 [[TMP2]], [[TMP9]]
87 ; CHECK-NEXT: [[TMP11:%.*]] = or i32 [[TMP7]], [[TMP10]]
88 ; CHECK-NEXT: ret i32 [[TMP11]]
91 %2 = shl nuw nsw i32 %1, 8
92 %3 = shl nuw nsw i32 %1, 1
94 %5 = shl nuw nsw i32 %4, 8
95 %6 = shl nuw nsw i32 %4, 1
97 %8 = shl nuw nsw i32 %7, 8
98 %9 = shl nuw nsw i32 %7, 1
103 %14 = or i32 %11, %13
107 define i32 @multiuse3(i32 %x) {
108 ; CHECK-LABEL: @multiuse3(
109 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %x, 96
110 ; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 6
111 ; CHECK-NEXT: [[TMP3:%.*]] = lshr exact i32 [[TMP1]], 1
112 ; CHECK-NEXT: [[TMP4:%.*]] = shl i32 %x, 6
113 ; CHECK-NEXT: [[TMP5:%.*]] = and i32 [[TMP4]], 1920
114 ; CHECK-NEXT: [[TMP6:%.*]] = or i32 [[TMP2]], [[TMP5]]
115 ; CHECK-NEXT: [[TMP7:%.*]] = lshr i32 %x, 1
116 ; CHECK-NEXT: [[TMP8:%.*]] = and i32 [[TMP7]], 15
117 ; CHECK-NEXT: [[TMP9:%.*]] = or i32 [[TMP3]], [[TMP8]]
118 ; CHECK-NEXT: [[TMP10:%.*]] = or i32 [[TMP9]], [[TMP6]]
119 ; CHECK-NEXT: ret i32 [[TMP10]]
122 %2 = shl nuw nsw i32 %1, 6
123 %3 = lshr exact i32 %1, 1
125 %5 = and i32 %4, 1920
134 define i32 @multiuse4(i32 %x) local_unnamed_addr #0 {
135 ; CHECK-LABEL: @multiuse4(
136 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %x, 100663296
137 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 %x, -1
138 ; CHECK-NEXT: br i1 [[TMP2]], label %if, label %else
139 ; CHECK: {{.*}}if:{{.*}}
140 ; CHECK-NEXT: [[TMP3:%.*]] = lshr exact i32 [[TMP1]], 22
141 ; CHECK-NEXT: [[TMP4:%.*]] = lshr i32 %x, 22
142 ; CHECK-NEXT: [[TMP5:%.*]] = and i32 [[TMP4]], 480
143 ; CHECK-NEXT: [[TMP6:%.*]] = or i32 [[TMP5]], [[TMP3]]
144 ; CHECK-NEXT: br label %end
145 ; CHECK: {{.*}}else:{{.*}}
146 ; CHECK-NEXT: [[TMP7:%.*]] = lshr exact i32 [[TMP1]], 17
147 ; CHECK-NEXT: [[TMP8:%.*]] = lshr i32 %x, 17
148 ; CHECK-NEXT: [[TMP9:%.*]] = and i32 [[TMP8]], 15360
149 ; CHECK-NEXT: [[TMP10:%.*]] = or i32 [[TMP9]], [[TMP7]]
150 ; CHECK-NEXT: br label %end
151 ; CHECK: {{.*}}end{{.*}}
152 ; CHECK-NEXT: [[TMP11:%.*]] = phi i32 [ [[TMP6]], %if ], [ [[TMP10]], %else ]
153 ; CHECK-NEXT: ret i32 [[TMP11]]
155 %1 = and i32 %x, 100663296
156 %2 = icmp sgt i32 %x, -1
157 br i1 %2, label %if, label %else
160 %3 = lshr exact i32 %1, 22
167 %7 = lshr exact i32 %1, 17
169 %9 = and i32 %8, 15360
174 %11 = phi i32 [ %6, %if ], [ %10, %else ]
178 define i32 @multiuse5(i32 %x) local_unnamed_addr #0 {
179 ; CHECK-LABEL: @multiuse5(
180 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 5
181 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 %x, -1
182 ; CHECK-NEXT: br i1 [[TMP2]], label %if, label %else
183 ; CHECK: {{.*}}if:{{.*}}
184 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP1]], 21760
185 ; CHECK-NEXT: [[TMP4:%.*]] = shl i32 %x, 5
186 ; CHECK-NEXT: [[TMP5:%.*]] = and i32 [[TMP4]], 43520
187 ; CHECK-NEXT: [[TMP6:%.*]] = or i32 [[TMP5]], [[TMP3]]
188 ; CHECK-NEXT: br label %end
189 ; CHECK: {{.*}}else:{{.*}}
190 ; CHECK-NEXT: [[TMP7:%.*]] = and i32 [[TMP1]], 5570560
191 ; CHECK-NEXT: [[TMP8:%.*]] = shl i32 %x, 5
192 ; CHECK-NEXT: [[TMP9:%.*]] = and i32 [[TMP8]], 11141120
193 ; CHECK-NEXT: [[TMP10:%.*]] = or i32 [[TMP9]], [[TMP7]]
194 ; CHECK-NEXT: br label %end
195 ; CHECK: {{.*}}end{{.*}}
196 ; CHECK-NEXT: [[TMP11:%.*]] = phi i32 [ [[TMP6]], %if ], [ [[TMP10]], %else ]
197 ; CHECK-NEXT: ret i32 [[TMP11]]
200 %2 = icmp sgt i32 %x, -1
201 br i1 %2, label %if, label %else
204 %3 = and i32 %1, 21760
205 %4 = and i32 %x, 1360
206 %5 = shl nuw nsw i32 %4, 5
211 %7 = and i32 %1, 5570560
212 %8 = and i32 %x, 348160
213 %9 = shl nuw nsw i32 %8, 5
218 %11 = phi i32 [ %6, %if ], [ %10, %else ]