1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
6 define i32 @and_signbit_select_shl(i32 %x, i1 %cond) {
7 ; CHECK-LABEL: @and_signbit_select_shl(
8 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
9 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -16777216
10 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
11 ; CHECK-NEXT: ret i32 [[R]]
13 %t0 = and i32 %x, 4294901760 ; 0xFFFF0000
14 %t1 = select i1 %cond, i32 %t0, i32 %x
18 define i32 @and_nosignbit_select_shl(i32 %x, i1 %cond) {
19 ; CHECK-LABEL: @and_nosignbit_select_shl(
20 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
21 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -16777216
22 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
23 ; CHECK-NEXT: ret i32 [[R]]
25 %t0 = and i32 %x, 2147418112 ; 0x7FFF0000
26 %t1 = select i1 %cond, i32 %t0, i32 %x
31 define i32 @or_signbit_select_shl(i32 %x, i1 %cond) {
32 ; CHECK-LABEL: @or_signbit_select_shl(
33 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
34 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], -16777216
35 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
36 ; CHECK-NEXT: ret i32 [[R]]
38 %t0 = or i32 %x, 4294901760 ; 0xFFFF0000
39 %t1 = select i1 %cond, i32 %t0, i32 %x
43 define i32 @or_nosignbit_select_shl(i32 %x, i1 %cond) {
44 ; CHECK-LABEL: @or_nosignbit_select_shl(
45 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
46 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], -16777216
47 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
48 ; CHECK-NEXT: ret i32 [[R]]
50 %t0 = or i32 %x, 2147418112 ; 0x7FFF0000
51 %t1 = select i1 %cond, i32 %t0, i32 %x
56 define i32 @xor_signbit_select_shl(i32 %x, i1 %cond) {
57 ; CHECK-LABEL: @xor_signbit_select_shl(
58 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
59 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], -16777216
60 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
61 ; CHECK-NEXT: ret i32 [[R]]
63 %t0 = xor i32 %x, 4294901760 ; 0xFFFF0000
64 %t1 = select i1 %cond, i32 %t0, i32 %x
68 define i32 @xor_nosignbit_select_shl(i32 %x, i1 %cond) {
69 ; CHECK-LABEL: @xor_nosignbit_select_shl(
70 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
71 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], -16777216
72 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
73 ; CHECK-NEXT: ret i32 [[R]]
75 %t0 = xor i32 %x, 2147418112 ; 0x7FFF0000
76 %t1 = select i1 %cond, i32 %t0, i32 %x
81 define i32 @add_signbit_select_shl(i32 %x, i1 %cond) {
82 ; CHECK-LABEL: @add_signbit_select_shl(
83 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
84 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], -16777216
85 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
86 ; CHECK-NEXT: ret i32 [[R]]
88 %t0 = add i32 %x, 4294901760 ; 0xFFFF0000
89 %t1 = select i1 %cond, i32 %t0, i32 %x
93 define i32 @add_nosignbit_select_shl(i32 %x, i1 %cond) {
94 ; CHECK-LABEL: @add_nosignbit_select_shl(
95 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 8
96 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], -16777216
97 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
98 ; CHECK-NEXT: ret i32 [[R]]
100 %t0 = add i32 %x, 2147418112 ; 0x7FFF0000
101 %t1 = select i1 %cond, i32 %t0, i32 %x
106 ; logical shift right
108 define i32 @and_signbit_select_lshr(i32 %x, i1 %cond) {
109 ; CHECK-LABEL: @and_signbit_select_lshr(
110 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 8
111 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 16776960
112 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
113 ; CHECK-NEXT: ret i32 [[R]]
115 %t0 = and i32 %x, 4294901760 ; 0xFFFF0000
116 %t1 = select i1 %cond, i32 %t0, i32 %x
120 define i32 @and_nosignbit_select_lshr(i32 %x, i1 %cond) {
121 ; CHECK-LABEL: @and_nosignbit_select_lshr(
122 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 8
123 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 8388352
124 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
125 ; CHECK-NEXT: ret i32 [[R]]
127 %t0 = and i32 %x, 2147418112 ; 0x7FFF0000
128 %t1 = select i1 %cond, i32 %t0, i32 %x
133 define i32 @or_signbit_select_lshr(i32 %x, i1 %cond) {
134 ; CHECK-LABEL: @or_signbit_select_lshr(
135 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 8
136 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 16776960
137 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
138 ; CHECK-NEXT: ret i32 [[R]]
140 %t0 = or i32 %x, 4294901760 ; 0xFFFF0000
141 %t1 = select i1 %cond, i32 %t0, i32 %x
145 define i32 @or_nosignbit_select_lshr(i32 %x, i1 %cond) {
146 ; CHECK-LABEL: @or_nosignbit_select_lshr(
147 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 8
148 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 8388352
149 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
150 ; CHECK-NEXT: ret i32 [[R]]
152 %t0 = or i32 %x, 2147418112 ; 0x7FFF0000
153 %t1 = select i1 %cond, i32 %t0, i32 %x
158 define i32 @xor_signbit_select_lshr(i32 %x, i1 %cond) {
159 ; CHECK-LABEL: @xor_signbit_select_lshr(
160 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 8
161 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 16776960
162 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
163 ; CHECK-NEXT: ret i32 [[R]]
165 %t0 = xor i32 %x, 4294901760 ; 0xFFFF0000
166 %t1 = select i1 %cond, i32 %t0, i32 %x
170 define i32 @xor_nosignbit_select_lshr(i32 %x, i1 %cond) {
171 ; CHECK-LABEL: @xor_nosignbit_select_lshr(
172 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 8
173 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 8388352
174 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
175 ; CHECK-NEXT: ret i32 [[R]]
177 %t0 = xor i32 %x, 2147418112 ; 0x7FFF0000
178 %t1 = select i1 %cond, i32 %t0, i32 %x
183 define i32 @add_signbit_select_lshr(i32 %x, i1 %cond) {
184 ; CHECK-LABEL: @add_signbit_select_lshr(
185 ; CHECK-NEXT: [[T0:%.*]] = add i32 [[X:%.*]], -65536
186 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[COND:%.*]], i32 [[T0]], i32 [[X]]
187 ; CHECK-NEXT: [[R:%.*]] = lshr i32 [[T1]], 8
188 ; CHECK-NEXT: ret i32 [[R]]
190 %t0 = add i32 %x, 4294901760 ; 0xFFFF0000
191 %t1 = select i1 %cond, i32 %t0, i32 %x
195 define i32 @add_nosignbit_select_lshr(i32 %x, i1 %cond) {
196 ; CHECK-LABEL: @add_nosignbit_select_lshr(
197 ; CHECK-NEXT: [[T0:%.*]] = add i32 [[X:%.*]], 2147418112
198 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[COND:%.*]], i32 [[T0]], i32 [[X]]
199 ; CHECK-NEXT: [[R:%.*]] = lshr i32 [[T1]], 8
200 ; CHECK-NEXT: ret i32 [[R]]
202 %t0 = add i32 %x, 2147418112 ; 0x7FFF0000
203 %t1 = select i1 %cond, i32 %t0, i32 %x
208 ; arithmetic shift right
210 define i32 @and_signbit_select_ashr(i32 %x, i1 %cond) {
211 ; CHECK-LABEL: @and_signbit_select_ashr(
212 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 8
213 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -256
214 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
215 ; CHECK-NEXT: ret i32 [[R]]
217 %t0 = and i32 %x, 4294901760 ; 0xFFFF0000
218 %t1 = select i1 %cond, i32 %t0, i32 %x
222 define i32 @and_nosignbit_select_ashr(i32 %x, i1 %cond) {
223 ; CHECK-LABEL: @and_nosignbit_select_ashr(
224 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 8
225 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 8388352
226 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
227 ; CHECK-NEXT: ret i32 [[R]]
229 %t0 = and i32 %x, 2147418112 ; 0x7FFF0000
230 %t1 = select i1 %cond, i32 %t0, i32 %x
235 define i32 @or_signbit_select_ashr(i32 %x, i1 %cond) {
236 ; CHECK-LABEL: @or_signbit_select_ashr(
237 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 8
238 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], -256
239 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
240 ; CHECK-NEXT: ret i32 [[R]]
242 %t0 = or i32 %x, 4294901760 ; 0xFFFF0000
243 %t1 = select i1 %cond, i32 %t0, i32 %x
247 define i32 @or_nosignbit_select_ashr(i32 %x, i1 %cond) {
248 ; CHECK-LABEL: @or_nosignbit_select_ashr(
249 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 8
250 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 8388352
251 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
252 ; CHECK-NEXT: ret i32 [[R]]
254 %t0 = or i32 %x, 2147418112 ; 0x7FFF0000
255 %t1 = select i1 %cond, i32 %t0, i32 %x
260 define i32 @xor_signbit_select_ashr(i32 %x, i1 %cond) {
261 ; CHECK-LABEL: @xor_signbit_select_ashr(
262 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 8
263 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], -256
264 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
265 ; CHECK-NEXT: ret i32 [[R]]
267 %t0 = xor i32 %x, 4294901760 ; 0xFFFF0000
268 %t1 = select i1 %cond, i32 %t0, i32 %x
272 define i32 @xor_nosignbit_select_ashr(i32 %x, i1 %cond) {
273 ; CHECK-LABEL: @xor_nosignbit_select_ashr(
274 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 8
275 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 8388352
276 ; CHECK-NEXT: [[R:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
277 ; CHECK-NEXT: ret i32 [[R]]
279 %t0 = xor i32 %x, 2147418112 ; 0x7FFF0000
280 %t1 = select i1 %cond, i32 %t0, i32 %x
285 define i32 @add_signbit_select_ashr(i32 %x, i1 %cond) {
286 ; CHECK-LABEL: @add_signbit_select_ashr(
287 ; CHECK-NEXT: [[T0:%.*]] = add i32 [[X:%.*]], -65536
288 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[COND:%.*]], i32 [[T0]], i32 [[X]]
289 ; CHECK-NEXT: [[R:%.*]] = ashr i32 [[T1]], 8
290 ; CHECK-NEXT: ret i32 [[R]]
292 %t0 = add i32 %x, 4294901760 ; 0xFFFF0000
293 %t1 = select i1 %cond, i32 %t0, i32 %x
297 define i32 @add_nosignbit_select_ashr(i32 %x, i1 %cond) {
298 ; CHECK-LABEL: @add_nosignbit_select_ashr(
299 ; CHECK-NEXT: [[T0:%.*]] = add i32 [[X:%.*]], 2147418112
300 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[COND:%.*]], i32 [[T0]], i32 [[X]]
301 ; CHECK-NEXT: [[R:%.*]] = ashr i32 [[T1]], 8
302 ; CHECK-NEXT: ret i32 [[R]]
304 %t0 = add i32 %x, 2147418112 ; 0x7FFF0000
305 %t1 = select i1 %cond, i32 %t0, i32 %x