1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6 declare void @use16(i16)
9 define i8 @testi16i8(i16 %add) {
10 ; CHECK-LABEL: @testi16i8(
11 ; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.smax.i16(i16 [[ADD:%.*]], i16 -128)
12 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.smin.i16(i16 [[TMP1]], i16 127)
13 ; CHECK-NEXT: [[COND_I:%.*]] = trunc i16 [[TMP2]] to i8
14 ; CHECK-NEXT: ret i8 [[COND_I]]
16 %sh = lshr i16 %add, 8
17 %conv.i = trunc i16 %sh to i8
18 %conv1.i = trunc i16 %add to i8
19 %shr2.i = ashr i8 %conv1.i, 7
20 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
21 %shr4.i = ashr i16 %add, 15
22 %conv5.i = trunc i16 %shr4.i to i8
23 %xor.i = xor i8 %conv5.i, 127
24 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
28 define i32 @testi64i32(i64 %add) {
29 ; CHECK-LABEL: @testi64i32(
30 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.smax.i64(i64 [[ADD:%.*]], i64 -2147483648)
31 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.smin.i64(i64 [[TMP1]], i64 2147483647)
32 ; CHECK-NEXT: [[COND_I:%.*]] = trunc i64 [[TMP2]] to i32
33 ; CHECK-NEXT: ret i32 [[COND_I]]
35 %sh = lshr i64 %add, 32
36 %conv.i = trunc i64 %sh to i32
37 %conv1.i = trunc i64 %add to i32
38 %shr2.i = ashr i32 %conv1.i, 31
39 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
40 %shr4.i = ashr i64 %add, 63
41 %conv5.i = trunc i64 %shr4.i to i32
42 %xor.i = xor i32 %conv5.i, 2147483647
43 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
47 define i16 @testi32i16i8(i32 %add) {
48 ; CHECK-LABEL: @testi32i16i8(
49 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.smax.i32(i32 [[ADD:%.*]], i32 -128)
50 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.smin.i32(i32 [[TMP1]], i32 127)
51 ; CHECK-NEXT: [[R:%.*]] = trunc i32 [[TMP2]] to i16
52 ; CHECK-NEXT: ret i16 [[R]]
54 %a = add i32 %add, 128
55 %cmp = icmp ult i32 %a, 256
56 %t = trunc i32 %add to i16
57 %c = icmp sgt i32 %add, -1
58 %f = select i1 %c, i16 127, i16 -128
59 %r = select i1 %cmp, i16 %t, i16 %f
63 define <4 x i16> @testv4i32i16i8(<4 x i32> %add) {
64 ; CHECK-LABEL: @testv4i32i16i8(
65 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.smax.v4i32(<4 x i32> [[ADD:%.*]], <4 x i32> <i32 -128, i32 -128, i32 -128, i32 -128>)
66 ; CHECK-NEXT: [[TMP2:%.*]] = call <4 x i32> @llvm.smin.v4i32(<4 x i32> [[TMP1]], <4 x i32> <i32 127, i32 127, i32 127, i32 127>)
67 ; CHECK-NEXT: [[R:%.*]] = trunc <4 x i32> [[TMP2]] to <4 x i16>
68 ; CHECK-NEXT: ret <4 x i16> [[R]]
70 %a = add <4 x i32> %add, <i32 128, i32 128, i32 128, i32 128>
71 %cmp = icmp ult <4 x i32> %a, <i32 256, i32 256, i32 256, i32 256>
72 %t = trunc <4 x i32> %add to <4 x i16>
73 %c = icmp sgt <4 x i32> %add, <i32 -1, i32 -1, i32 -1, i32 -1>
74 %f = select <4 x i1> %c, <4 x i16> <i16 127, i16 127, i16 127, i16 127>, <4 x i16> <i16 -128, i16 -128, i16 -128, i16 -128>
75 %r = select <4 x i1> %cmp, <4 x i16> %t, <4 x i16> %f
79 define i32 @testi32i32i8(i32 %add) {
80 ; CHECK-LABEL: @testi32i32i8(
81 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.smax.i32(i32 [[ADD:%.*]], i32 -128)
82 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.smin.i32(i32 [[TMP1]], i32 127)
83 ; CHECK-NEXT: ret i32 [[R]]
85 %a = add i32 %add, 128
86 %cmp = icmp ult i32 %a, 256
87 %c = icmp sgt i32 %add, -1
88 %f = select i1 %c, i32 127, i32 -128
89 %r = select i1 %cmp, i32 %add, i32 %f
93 define i16 @test_truncfirst(i32 %add) {
94 ; CHECK-LABEL: @test_truncfirst(
95 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[ADD:%.*]] to i16
96 ; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.smax.i16(i16 [[T]], i16 -128)
97 ; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.smin.i16(i16 [[TMP1]], i16 127)
98 ; CHECK-NEXT: ret i16 [[R]]
100 %t = trunc i32 %add to i16
102 %cmp = icmp ult i16 %a, 256
103 %c = icmp sgt i16 %t, -1
104 %f = select i1 %c, i16 127, i16 -128
105 %r = select i1 %cmp, i16 %t, i16 %f
109 define i16 @testtrunclowhigh(i32 %add, i16 %low, i16 %high) {
110 ; CHECK-LABEL: @testtrunclowhigh(
111 ; CHECK-NEXT: [[A:%.*]] = add i32 [[ADD:%.*]], 128
112 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A]], 256
113 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[ADD]] to i16
114 ; CHECK-NEXT: [[C1:%.*]] = icmp slt i32 [[ADD]], 0
115 ; CHECK-NEXT: [[F:%.*]] = select i1 [[C1]], i16 [[LOW:%.*]], i16 [[HIGH:%.*]]
116 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP]], i16 [[T]], i16 [[F]]
117 ; CHECK-NEXT: ret i16 [[R]]
119 %a = add i32 %add, 128
120 %cmp = icmp ult i32 %a, 256
121 %t = trunc i32 %add to i16
122 %c = icmp sgt i32 %add, -1
123 %f = select i1 %c, i16 %high, i16 %low
124 %r = select i1 %cmp, i16 %t, i16 %f
128 define i32 @testi64i32addsat(i32 %a, i32 %b) {
129 ; CHECK-LABEL: @testi64i32addsat(
130 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[A:%.*]], i32 [[B:%.*]])
131 ; CHECK-NEXT: ret i32 [[TMP1]]
133 %sa = sext i32 %a to i64
134 %sb = sext i32 %b to i64
135 %add = add i64 %sa, %sb
136 %sh = lshr i64 %add, 32
137 %conv.i = trunc i64 %sh to i32
138 %conv1.i = trunc i64 %add to i32
139 %shr2.i = ashr i32 %conv1.i, 31
140 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
141 %shr4.i = ashr i64 %add, 63
142 %conv5.i = trunc i64 %shr4.i to i32
143 %xor.i = xor i32 %conv5.i, 2147483647
144 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
148 define <4 x i8> @testv4i16i8(<4 x i16> %add) {
149 ; CHECK-LABEL: @testv4i16i8(
150 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i16> @llvm.smax.v4i16(<4 x i16> [[ADD:%.*]], <4 x i16> <i16 -128, i16 -128, i16 -128, i16 -128>)
151 ; CHECK-NEXT: [[TMP2:%.*]] = call <4 x i16> @llvm.smin.v4i16(<4 x i16> [[TMP1]], <4 x i16> <i16 127, i16 127, i16 127, i16 127>)
152 ; CHECK-NEXT: [[COND_I:%.*]] = trunc <4 x i16> [[TMP2]] to <4 x i8>
153 ; CHECK-NEXT: ret <4 x i8> [[COND_I]]
155 %sh = lshr <4 x i16> %add, <i16 8, i16 8, i16 8, i16 8>
156 %conv.i = trunc <4 x i16> %sh to <4 x i8>
157 %conv1.i = trunc <4 x i16> %add to <4 x i8>
158 %shr2.i = ashr <4 x i8> %conv1.i, <i8 7, i8 7, i8 7, i8 7>
159 %cmp.not.i = icmp eq <4 x i8> %shr2.i, %conv.i
160 %shr4.i = ashr <4 x i16> %add, <i16 15, i16 15, i16 15, i16 15>
161 %conv5.i = trunc <4 x i16> %shr4.i to <4 x i8>
162 %xor.i = xor <4 x i8> %conv5.i, <i8 127, i8 127, i8 127, i8 127>
163 %cond.i = select <4 x i1> %cmp.not.i, <4 x i8> %conv1.i, <4 x i8> %xor.i
167 define <4 x i8> @testv4i16i8add(<4 x i8> %a, <4 x i8> %b) {
168 ; CHECK-LABEL: @testv4i16i8add(
169 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> [[A:%.*]], <4 x i8> [[B:%.*]])
170 ; CHECK-NEXT: ret <4 x i8> [[TMP1]]
172 %sa = sext <4 x i8> %a to <4 x i16>
173 %sb = sext <4 x i8> %b to <4 x i16>
174 %add = add <4 x i16> %sa, %sb
175 %sh = lshr <4 x i16> %add, <i16 8, i16 8, i16 8, i16 8>
176 %conv.i = trunc <4 x i16> %sh to <4 x i8>
177 %conv1.i = trunc <4 x i16> %add to <4 x i8>
178 %shr2.i = ashr <4 x i8> %conv1.i, <i8 7, i8 7, i8 7, i8 7>
179 %cmp.not.i = icmp eq <4 x i8> %shr2.i, %conv.i
180 %shr4.i = ashr <4 x i16> %add, <i16 15, i16 15, i16 15, i16 15>
181 %conv5.i = trunc <4 x i16> %shr4.i to <4 x i8>
182 %xor.i = xor <4 x i8> %conv5.i, <i8 127, i8 127, i8 127, i8 127>
183 %cond.i = select <4 x i1> %cmp.not.i, <4 x i8> %conv1.i, <4 x i8> %xor.i
187 define i8 @testi16i8_revcmp(i16 %add) {
188 ; CHECK-LABEL: @testi16i8_revcmp(
189 ; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.smax.i16(i16 [[ADD:%.*]], i16 -128)
190 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.smin.i16(i16 [[TMP1]], i16 127)
191 ; CHECK-NEXT: [[COND_I:%.*]] = trunc i16 [[TMP2]] to i8
192 ; CHECK-NEXT: ret i8 [[COND_I]]
194 %sh = lshr i16 %add, 8
195 %conv.i = trunc i16 %sh to i8
196 %conv1.i = trunc i16 %add to i8
197 %shr2.i = ashr i8 %conv1.i, 7
198 %cmp.not.i = icmp eq i8 %conv.i, %shr2.i
199 %shr4.i = ashr i16 %add, 15
200 %conv5.i = trunc i16 %shr4.i to i8
201 %xor.i = xor i8 %conv5.i, 127
202 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
206 define i8 @testi16i8_revselect(i16 %add) {
207 ; CHECK-LABEL: @testi16i8_revselect(
208 ; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.smax.i16(i16 [[ADD:%.*]], i16 -128)
209 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.smin.i16(i16 [[TMP1]], i16 127)
210 ; CHECK-NEXT: [[COND_I:%.*]] = trunc i16 [[TMP2]] to i8
211 ; CHECK-NEXT: ret i8 [[COND_I]]
213 %sh = lshr i16 %add, 8
214 %conv.i = trunc i16 %sh to i8
215 %conv1.i = trunc i16 %add to i8
216 %shr2.i = ashr i8 %conv1.i, 7
217 %cmp.not.i = icmp ne i8 %conv.i, %shr2.i
218 %shr4.i = ashr i16 %add, 15
219 %conv5.i = trunc i16 %shr4.i to i8
220 %xor.i = xor i8 %conv5.i, 127
221 %cond.i = select i1 %cmp.not.i, i8 %xor.i, i8 %conv1.i
225 define i8 @testi32i8(i32 %add) {
226 ; CHECK-LABEL: @testi32i8(
227 ; CHECK-NEXT: [[SH:%.*]] = lshr i32 [[ADD:%.*]], 8
228 ; CHECK-NEXT: [[CONV_I:%.*]] = trunc i32 [[SH]] to i8
229 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i32 [[ADD]] to i8
230 ; CHECK-NEXT: [[SHR2_I:%.*]] = ashr i8 [[CONV1_I]], 7
231 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp eq i8 [[SHR2_I]], [[CONV_I]]
232 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[ADD]], 15
233 ; CHECK-NEXT: [[CONV5_I:%.*]] = trunc i32 [[TMP1]] to i8
234 ; CHECK-NEXT: [[XOR_I:%.*]] = xor i8 [[CONV5_I]], 127
235 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
236 ; CHECK-NEXT: ret i8 [[COND_I]]
238 %sh = lshr i32 %add, 8
239 %conv.i = trunc i32 %sh to i8
240 %conv1.i = trunc i32 %add to i8
241 %shr2.i = ashr i8 %conv1.i, 7
242 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
243 %shr4.i = ashr i32 %add, 15
244 %conv5.i = trunc i32 %shr4.i to i8
245 %xor.i = xor i8 %conv5.i, 127
246 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
250 define i16 @differentconsts(i32 %x, i16 %replacement_low, i16 %replacement_high) {
251 ; CHECK-LABEL: @differentconsts(
252 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], -16
253 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[X]], 127
254 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[X]] to i16
255 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], i16 256, i16 [[TMP3]]
256 ; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP2]], i16 -1, i16 [[TMP4]]
257 ; CHECK-NEXT: ret i16 [[R]]
259 %t0 = icmp slt i32 %x, 128
260 %t1 = select i1 %t0, i16 256, i16 65535
262 %t3 = icmp ult i32 %t2, 144
263 %t4 = trunc i32 %x to i16
264 %r = select i1 %t3, i16 %t4, i16 %t1
268 define i8 @badimm1(i16 %add) {
269 ; CHECK-LABEL: @badimm1(
270 ; CHECK-NEXT: [[SH:%.*]] = lshr i16 [[ADD:%.*]], 9
271 ; CHECK-NEXT: [[CONV_I:%.*]] = trunc i16 [[SH]] to i8
272 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i16 [[ADD]] to i8
273 ; CHECK-NEXT: [[SHR2_I:%.*]] = ashr i8 [[CONV1_I]], 7
274 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp eq i8 [[SHR2_I]], [[CONV_I]]
275 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[ADD]], -1
276 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP1]], i8 127, i8 -128
277 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
278 ; CHECK-NEXT: ret i8 [[COND_I]]
280 %sh = lshr i16 %add, 9
281 %conv.i = trunc i16 %sh to i8
282 %conv1.i = trunc i16 %add to i8
283 %shr2.i = ashr i8 %conv1.i, 7
284 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
285 %shr4.i = ashr i16 %add, 15
286 %conv5.i = trunc i16 %shr4.i to i8
287 %xor.i = xor i8 %conv5.i, 127
288 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
292 define i8 @badimm2(i16 %add) {
293 ; CHECK-LABEL: @badimm2(
294 ; CHECK-NEXT: [[SH:%.*]] = lshr i16 [[ADD:%.*]], 8
295 ; CHECK-NEXT: [[CONV_I:%.*]] = trunc i16 [[SH]] to i8
296 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i16 [[ADD]] to i8
297 ; CHECK-NEXT: [[SHR2_I:%.*]] = ashr i8 [[CONV1_I]], 6
298 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp eq i8 [[SHR2_I]], [[CONV_I]]
299 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[ADD]], -1
300 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP1]], i8 127, i8 -128
301 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
302 ; CHECK-NEXT: ret i8 [[COND_I]]
304 %sh = lshr i16 %add, 8
305 %conv.i = trunc i16 %sh to i8
306 %conv1.i = trunc i16 %add to i8
307 %shr2.i = ashr i8 %conv1.i, 6
308 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
309 %shr4.i = ashr i16 %add, 15
310 %conv5.i = trunc i16 %shr4.i to i8
311 %xor.i = xor i8 %conv5.i, 127
312 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
316 define i8 @badimm3(i16 %add) {
317 ; CHECK-LABEL: @badimm3(
318 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i16 [[ADD:%.*]] to i8
319 ; CHECK-NEXT: [[TMP1:%.*]] = add i16 [[ADD]], 128
320 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i16 [[TMP1]], 256
321 ; CHECK-NEXT: [[SHR4_I:%.*]] = ashr i16 [[ADD]], 14
322 ; CHECK-NEXT: [[CONV5_I:%.*]] = trunc i16 [[SHR4_I]] to i8
323 ; CHECK-NEXT: [[XOR_I:%.*]] = xor i8 [[CONV5_I]], 127
324 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
325 ; CHECK-NEXT: ret i8 [[COND_I]]
327 %sh = lshr i16 %add, 8
328 %conv.i = trunc i16 %sh to i8
329 %conv1.i = trunc i16 %add to i8
330 %shr2.i = ashr i8 %conv1.i, 7
331 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
332 %shr4.i = ashr i16 %add, 14
333 %conv5.i = trunc i16 %shr4.i to i8
334 %xor.i = xor i8 %conv5.i, 127
335 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
339 define i8 @badimm4(i16 %add) {
340 ; CHECK-LABEL: @badimm4(
341 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i16 [[ADD:%.*]], -128
342 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i16 [[ADD]], 127
343 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i16 [[ADD]] to i8
344 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], i8 -127, i8 [[TMP3]]
345 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[TMP2]], i8 126, i8 [[TMP4]]
346 ; CHECK-NEXT: ret i8 [[COND_I]]
348 %sh = lshr i16 %add, 8
349 %conv.i = trunc i16 %sh to i8
350 %conv1.i = trunc i16 %add to i8
351 %shr2.i = ashr i8 %conv1.i, 7
352 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
353 %shr4.i = ashr i16 %add, 15
354 %conv5.i = trunc i16 %shr4.i to i8
355 %xor.i = xor i8 %conv5.i, 126
356 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
362 define i32 @oneusexor(i64 %add) {
363 ; CHECK-LABEL: @oneusexor(
364 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
365 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
366 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
367 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
368 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
369 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
370 ; CHECK-NEXT: call void @use(i32 [[XOR_I]])
371 ; CHECK-NEXT: ret i32 [[COND_I]]
373 %sh = lshr i64 %add, 32
374 %conv.i = trunc i64 %sh to i32
375 %conv1.i = trunc i64 %add to i32
376 %shr2.i = ashr i32 %conv1.i, 31
377 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
378 %shr4.i = ashr i64 %add, 63
379 %conv5.i = trunc i64 %shr4.i to i32
380 %xor.i = xor i32 %conv5.i, 2147483647
381 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
382 call void @use(i32 %xor.i)
386 define i32 @oneuseconv(i64 %add) {
387 ; CHECK-LABEL: @oneuseconv(
388 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
389 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
390 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
391 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
392 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
393 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
394 ; CHECK-NEXT: call void @use(i32 [[CONV1_I]])
395 ; CHECK-NEXT: ret i32 [[COND_I]]
397 %sh = lshr i64 %add, 32
398 %conv.i = trunc i64 %sh to i32
399 %conv1.i = trunc i64 %add to i32
400 %shr2.i = ashr i32 %conv1.i, 31
401 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
402 %shr4.i = ashr i64 %add, 63
403 %conv5.i = trunc i64 %shr4.i to i32
404 %xor.i = xor i32 %conv5.i, 2147483647
405 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
406 call void @use(i32 %conv1.i)
410 define i32 @oneusecmp(i64 %add) {
411 ; CHECK-LABEL: @oneusecmp(
412 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
413 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
414 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
415 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
416 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
417 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
418 ; CHECK-NEXT: call void @use1(i1 [[CMP_NOT_I]])
419 ; CHECK-NEXT: ret i32 [[COND_I]]
421 %sh = lshr i64 %add, 32
422 %conv.i = trunc i64 %sh to i32
423 %conv1.i = trunc i64 %add to i32
424 %shr2.i = ashr i32 %conv1.i, 31
425 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
426 %shr4.i = ashr i64 %add, 63
427 %conv5.i = trunc i64 %shr4.i to i32
428 %xor.i = xor i32 %conv5.i, 2147483647
429 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
430 call void @use1(i1 %cmp.not.i)
434 define i32 @oneuseboth(i64 %add) {
435 ; CHECK-LABEL: @oneuseboth(
436 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
437 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
438 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
439 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
440 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
441 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
442 ; CHECK-NEXT: call void @use(i32 [[XOR_I]])
443 ; CHECK-NEXT: call void @use(i32 [[CONV1_I]])
444 ; CHECK-NEXT: ret i32 [[COND_I]]
446 %sh = lshr i64 %add, 32
447 %conv.i = trunc i64 %sh to i32
448 %conv1.i = trunc i64 %add to i32
449 %shr2.i = ashr i32 %conv1.i, 31
450 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
451 %shr4.i = ashr i64 %add, 63
452 %conv5.i = trunc i64 %shr4.i to i32
453 %xor.i = xor i32 %conv5.i, 2147483647
454 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
455 call void @use(i32 %xor.i)
456 call void @use(i32 %conv1.i)
460 define i32 @oneusethree(i64 %add) {
461 ; CHECK-LABEL: @oneusethree(
462 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
463 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
464 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
465 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
466 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
467 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
468 ; CHECK-NEXT: call void @use(i32 [[XOR_I]])
469 ; CHECK-NEXT: call void @use(i32 [[CONV1_I]])
470 ; CHECK-NEXT: call void @use1(i1 [[CMP_NOT_I]])
471 ; CHECK-NEXT: ret i32 [[COND_I]]
473 %sh = lshr i64 %add, 32
474 %conv.i = trunc i64 %sh to i32
475 %conv1.i = trunc i64 %add to i32
476 %shr2.i = ashr i32 %conv1.i, 31
477 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
478 %shr4.i = ashr i64 %add, 63
479 %conv5.i = trunc i64 %shr4.i to i32
480 %xor.i = xor i32 %conv5.i, 2147483647
481 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
482 call void @use(i32 %xor.i)
483 call void @use(i32 %conv1.i)
484 call void @use1(i1 %cmp.not.i)
488 define i16 @differentconsts_usetrunc(i32 %x, i16 %replacement_low, i16 %replacement_high) {
489 ; CHECK-LABEL: @differentconsts_usetrunc(
490 ; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[X:%.*]], 128
491 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i16 256, i16 -1
492 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[X]], 16
493 ; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 144
494 ; CHECK-NEXT: [[T4:%.*]] = trunc i32 [[X]] to i16
495 ; CHECK-NEXT: [[R:%.*]] = select i1 [[T3]], i16 [[T4]], i16 [[T1]]
496 ; CHECK-NEXT: call void @use16(i16 [[T4]])
497 ; CHECK-NEXT: ret i16 [[R]]
499 %t0 = icmp slt i32 %x, 128
500 %t1 = select i1 %t0, i16 256, i16 65535
502 %t3 = icmp ult i32 %t2, 144
503 %t4 = trunc i32 %x to i16
504 %r = select i1 %t3, i16 %t4, i16 %t1
505 call void @use16(i16 %t4)
509 define i16 @differentconsts_useadd(i32 %x, i16 %replacement_low, i16 %replacement_high) {
510 ; CHECK-LABEL: @differentconsts_useadd(
511 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[X:%.*]], 16
512 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X]], -16
513 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[X]], 127
514 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[X]] to i16
515 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], i16 256, i16 [[TMP3]]
516 ; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP2]], i16 -1, i16 [[TMP4]]
517 ; CHECK-NEXT: call void @use(i32 [[T2]])
518 ; CHECK-NEXT: ret i16 [[R]]
520 %t0 = icmp slt i32 %x, 128
521 %t1 = select i1 %t0, i16 256, i16 65535
523 %t3 = icmp ult i32 %t2, 144
524 %t4 = trunc i32 %x to i16
525 %r = select i1 %t3, i16 %t4, i16 %t1
526 call void @use(i32 %t2)
530 define i16 @differentconsts_useaddtrunc(i32 %x, i16 %replacement_low, i16 %replacement_high) {
531 ; CHECK-LABEL: @differentconsts_useaddtrunc(
532 ; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[X:%.*]], 128
533 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i16 256, i16 -1
534 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[X]], 16
535 ; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 144
536 ; CHECK-NEXT: [[T4:%.*]] = trunc i32 [[X]] to i16
537 ; CHECK-NEXT: [[R:%.*]] = select i1 [[T3]], i16 [[T4]], i16 [[T1]]
538 ; CHECK-NEXT: call void @use16(i16 [[T4]])
539 ; CHECK-NEXT: call void @use(i32 [[T2]])
540 ; CHECK-NEXT: ret i16 [[R]]
542 %t0 = icmp slt i32 %x, 128
543 %t1 = select i1 %t0, i16 256, i16 65535
545 %t3 = icmp ult i32 %t2, 144
546 %t4 = trunc i32 %x to i16
547 %r = select i1 %t3, i16 %t4, i16 %t1
548 call void @use16(i16 %t4)
549 call void @use(i32 %t2)
554 define i8 @C0zero(i8 %X, i8 %y, i8 %z) {
555 ; CHECK-LABEL: @C0zero(
556 ; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], -10
557 ; CHECK-NEXT: [[F:%.*]] = select i1 [[C]], i8 [[Y:%.*]], i8 [[Z:%.*]]
558 ; CHECK-NEXT: ret i8 [[F]]
561 %cmp = icmp ult i8 %a, 0
562 %c = icmp slt i8 %X, -10
563 %f = select i1 %c, i8 %y, i8 %z
564 %r = select i1 %cmp, i8 %X, i8 %f
568 define <2 x i8> @C0zeroV(<2 x i8> %X, <2 x i8> %y, <2 x i8> %z) {
569 ; CHECK-LABEL: @C0zeroV(
570 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 -10, i8 -10>
571 ; CHECK-NEXT: [[F:%.*]] = select <2 x i1> [[C]], <2 x i8> [[Y:%.*]], <2 x i8> [[Z:%.*]]
572 ; CHECK-NEXT: ret <2 x i8> [[F]]
574 %a = add <2 x i8> %X, <i8 10, i8 10>
575 %cmp = icmp ult <2 x i8> %a, zeroinitializer
576 %c = icmp slt <2 x i8> %X, <i8 -10, i8 -10>
577 %f = select <2 x i1> %c, <2 x i8> %y, <2 x i8> %z
578 %r = select <2 x i1> %cmp, <2 x i8> %X, <2 x i8> %f
582 define <2 x i8> @C0zeroVu(<2 x i8> %X, <2 x i8> %y, <2 x i8> %z) {
583 ; CHECK-LABEL: @C0zeroVu(
584 ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 10, i8 10>
585 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[A]], <i8 0, i8 10>
586 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i8> [[X]], <i8 -10, i8 -10>
587 ; CHECK-NEXT: [[F:%.*]] = select <2 x i1> [[C]], <2 x i8> [[Y:%.*]], <2 x i8> [[Z:%.*]]
588 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[F]]
589 ; CHECK-NEXT: ret <2 x i8> [[R]]
591 %a = add <2 x i8> %X, <i8 10, i8 10>
592 %cmp = icmp ult <2 x i8> %a, <i8 0, i8 10>
593 %c = icmp slt <2 x i8> %X, <i8 -10, i8 -10>
594 %f = select <2 x i1> %c, <2 x i8> %y, <2 x i8> %z
595 %r = select <2 x i1> %cmp, <2 x i8> %X, <2 x i8> %f
599 define i8 @f(i32 %value, i8 %call.i) {
602 ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[VALUE:%.*]], 0
603 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], i8 [[CALL_I:%.*]], i8 0
604 ; CHECK-NEXT: [[CMP_I_I:%.*]] = icmp ult i32 [[VALUE]], 256
605 ; CHECK-NEXT: [[CONV4:%.*]] = trunc i32 [[VALUE]] to i8
606 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP_I_I]], i8 [[CONV4]], i8 [[COND_I]]
607 ; CHECK-NEXT: ret i8 [[COND]]
610 %cmp.i = icmp slt i32 %value, 0
611 %cond.i = select i1 %cmp.i, i8 %call.i, i8 0
612 %cmp.i.i = icmp ult i32 %value, 256
613 %conv4 = trunc i32 %value to i8
614 %cond = select i1 %cmp.i.i, i8 %conv4, i8 %cond.i