1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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:%.*]] = icmp sgt i16 [[ADD:%.*]], -128
12 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i16 [[ADD]], i16 -128
13 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i16 [[TMP2]], 127
14 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i16 [[TMP2]], i16 127
15 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i16 [[TMP4]] to i8
16 ; CHECK-NEXT: ret i8 [[TMP5]]
18 %sh = lshr i16 %add, 8
19 %conv.i = trunc i16 %sh to i8
20 %conv1.i = trunc i16 %add to i8
21 %shr2.i = ashr i8 %conv1.i, 7
22 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
23 %shr4.i = ashr i16 %add, 15
24 %conv5.i = trunc i16 %shr4.i to i8
25 %xor.i = xor i8 %conv5.i, 127
26 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
30 define i32 @testi64i32(i64 %add) {
31 ; CHECK-LABEL: @testi64i32(
32 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i64 [[ADD:%.*]], -2147483648
33 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 [[ADD]], i64 -2147483648
34 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i64 [[TMP2]], 2147483647
35 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i64 [[TMP2]], i64 2147483647
36 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i64 [[TMP4]] to i32
37 ; CHECK-NEXT: ret i32 [[TMP5]]
39 %sh = lshr i64 %add, 32
40 %conv.i = trunc i64 %sh to i32
41 %conv1.i = trunc i64 %add to i32
42 %shr2.i = ashr i32 %conv1.i, 31
43 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
44 %shr4.i = ashr i64 %add, 63
45 %conv5.i = trunc i64 %shr4.i to i32
46 %xor.i = xor i32 %conv5.i, 2147483647
47 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
51 define i16 @testi32i16i8(i32 %add) {
52 ; CHECK-LABEL: @testi32i16i8(
53 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[ADD:%.*]], -128
54 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[ADD]], i32 -128
55 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP2]], 127
56 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 127
57 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i16
58 ; CHECK-NEXT: ret i16 [[TMP5]]
60 %a = add i32 %add, 128
61 %cmp = icmp ult i32 %a, 256
62 %t = trunc i32 %add to i16
63 %c = icmp sgt i32 %add, -1
64 %f = select i1 %c, i16 127, i16 -128
65 %r = select i1 %cmp, i16 %t, i16 %f
69 define <4 x i16> @testv4i32i16i8(<4 x i32> %add) {
70 ; CHECK-LABEL: @testv4i32i16i8(
71 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <4 x i32> [[ADD:%.*]], <i32 -128, i32 -128, i32 -128, i32 -128>
72 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x i32> [[ADD]], <4 x i32> <i32 -128, i32 -128, i32 -128, i32 -128>
73 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt <4 x i32> [[TMP2]], <i32 127, i32 127, i32 127, i32 127>
74 ; CHECK-NEXT: [[TMP4:%.*]] = select <4 x i1> [[TMP3]], <4 x i32> [[TMP2]], <4 x i32> <i32 127, i32 127, i32 127, i32 127>
75 ; CHECK-NEXT: [[TMP5:%.*]] = trunc <4 x i32> [[TMP4]] to <4 x i16>
76 ; CHECK-NEXT: ret <4 x i16> [[TMP5]]
78 %a = add <4 x i32> %add, <i32 128, i32 128, i32 128, i32 128>
79 %cmp = icmp ult <4 x i32> %a, <i32 256, i32 256, i32 256, i32 256>
80 %t = trunc <4 x i32> %add to <4 x i16>
81 %c = icmp sgt <4 x i32> %add, <i32 -1, i32 -1, i32 -1, i32 -1>
82 %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>
83 %r = select <4 x i1> %cmp, <4 x i16> %t, <4 x i16> %f
87 define i32 @testi32i32i8(i32 %add) {
88 ; CHECK-LABEL: @testi32i32i8(
89 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[ADD:%.*]], -128
90 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[ADD]], i32 -128
91 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP2]], 127
92 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 127
93 ; CHECK-NEXT: ret i32 [[TMP4]]
95 %a = add i32 %add, 128
96 %cmp = icmp ult i32 %a, 256
97 %c = icmp sgt i32 %add, -1
98 %f = select i1 %c, i32 127, i32 -128
99 %r = select i1 %cmp, i32 %add, i32 %f
103 define i16 @test_truncfirst(i32 %add) {
104 ; CHECK-LABEL: @test_truncfirst(
105 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[ADD:%.*]] to i16
106 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[T]], -128
107 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i16 [[T]], i16 -128
108 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i16 [[TMP2]], 127
109 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i16 [[TMP2]], i16 127
110 ; CHECK-NEXT: ret i16 [[TMP4]]
112 %t = trunc i32 %add to i16
114 %cmp = icmp ult i16 %a, 256
115 %c = icmp sgt i16 %t, -1
116 %f = select i1 %c, i16 127, i16 -128
117 %r = select i1 %cmp, i16 %t, i16 %f
121 define i16 @testtrunclowhigh(i32 %add, i16 %low, i16 %high) {
122 ; CHECK-LABEL: @testtrunclowhigh(
123 ; CHECK-NEXT: [[A:%.*]] = add i32 [[ADD:%.*]], 128
124 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A]], 256
125 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[ADD]] to i16
126 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[ADD]], -1
127 ; CHECK-NEXT: [[F:%.*]] = select i1 [[C]], i16 [[HIGH:%.*]], i16 [[LOW:%.*]]
128 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP]], i16 [[T]], i16 [[F]]
129 ; CHECK-NEXT: ret i16 [[R]]
131 %a = add i32 %add, 128
132 %cmp = icmp ult i32 %a, 256
133 %t = trunc i32 %add to i16
134 %c = icmp sgt i32 %add, -1
135 %f = select i1 %c, i16 %high, i16 %low
136 %r = select i1 %cmp, i16 %t, i16 %f
140 define i32 @testi64i32addsat(i32 %a, i32 %b) {
141 ; CHECK-LABEL: @testi64i32addsat(
142 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[A:%.*]], i32 [[B:%.*]])
143 ; CHECK-NEXT: ret i32 [[TMP1]]
145 %sa = sext i32 %a to i64
146 %sb = sext i32 %b to i64
147 %add = add i64 %sa, %sb
148 %sh = lshr i64 %add, 32
149 %conv.i = trunc i64 %sh to i32
150 %conv1.i = trunc i64 %add to i32
151 %shr2.i = ashr i32 %conv1.i, 31
152 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
153 %shr4.i = ashr i64 %add, 63
154 %conv5.i = trunc i64 %shr4.i to i32
155 %xor.i = xor i32 %conv5.i, 2147483647
156 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
160 define <4 x i8> @testv4i16i8(<4 x i16> %add) {
161 ; CHECK-LABEL: @testv4i16i8(
162 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <4 x i16> [[ADD:%.*]], <i16 -128, i16 -128, i16 -128, i16 -128>
163 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x i16> [[ADD]], <4 x i16> <i16 -128, i16 -128, i16 -128, i16 -128>
164 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt <4 x i16> [[TMP2]], <i16 127, i16 127, i16 127, i16 127>
165 ; CHECK-NEXT: [[TMP4:%.*]] = select <4 x i1> [[TMP3]], <4 x i16> [[TMP2]], <4 x i16> <i16 127, i16 127, i16 127, i16 127>
166 ; CHECK-NEXT: [[TMP5:%.*]] = trunc <4 x i16> [[TMP4]] to <4 x i8>
167 ; CHECK-NEXT: ret <4 x i8> [[TMP5]]
169 %sh = lshr <4 x i16> %add, <i16 8, i16 8, i16 8, i16 8>
170 %conv.i = trunc <4 x i16> %sh to <4 x i8>
171 %conv1.i = trunc <4 x i16> %add to <4 x i8>
172 %shr2.i = ashr <4 x i8> %conv1.i, <i8 7, i8 7, i8 7, i8 7>
173 %cmp.not.i = icmp eq <4 x i8> %shr2.i, %conv.i
174 %shr4.i = ashr <4 x i16> %add, <i16 15, i16 15, i16 15, i16 15>
175 %conv5.i = trunc <4 x i16> %shr4.i to <4 x i8>
176 %xor.i = xor <4 x i8> %conv5.i, <i8 127, i8 127, i8 127, i8 127>
177 %cond.i = select <4 x i1> %cmp.not.i, <4 x i8> %conv1.i, <4 x i8> %xor.i
181 define <4 x i8> @testv4i16i8add(<4 x i8> %a, <4 x i8> %b) {
182 ; CHECK-LABEL: @testv4i16i8add(
183 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> [[A:%.*]], <4 x i8> [[B:%.*]])
184 ; CHECK-NEXT: ret <4 x i8> [[TMP1]]
186 %sa = sext <4 x i8> %a to <4 x i16>
187 %sb = sext <4 x i8> %b to <4 x i16>
188 %add = add <4 x i16> %sa, %sb
189 %sh = lshr <4 x i16> %add, <i16 8, i16 8, i16 8, i16 8>
190 %conv.i = trunc <4 x i16> %sh to <4 x i8>
191 %conv1.i = trunc <4 x i16> %add to <4 x i8>
192 %shr2.i = ashr <4 x i8> %conv1.i, <i8 7, i8 7, i8 7, i8 7>
193 %cmp.not.i = icmp eq <4 x i8> %shr2.i, %conv.i
194 %shr4.i = ashr <4 x i16> %add, <i16 15, i16 15, i16 15, i16 15>
195 %conv5.i = trunc <4 x i16> %shr4.i to <4 x i8>
196 %xor.i = xor <4 x i8> %conv5.i, <i8 127, i8 127, i8 127, i8 127>
197 %cond.i = select <4 x i1> %cmp.not.i, <4 x i8> %conv1.i, <4 x i8> %xor.i
201 define i8 @testi16i8_revcmp(i16 %add) {
202 ; CHECK-LABEL: @testi16i8_revcmp(
203 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[ADD:%.*]], -128
204 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i16 [[ADD]], i16 -128
205 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i16 [[TMP2]], 127
206 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i16 [[TMP2]], i16 127
207 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i16 [[TMP4]] to i8
208 ; CHECK-NEXT: ret i8 [[TMP5]]
210 %sh = lshr i16 %add, 8
211 %conv.i = trunc i16 %sh to i8
212 %conv1.i = trunc i16 %add to i8
213 %shr2.i = ashr i8 %conv1.i, 7
214 %cmp.not.i = icmp eq i8 %conv.i, %shr2.i
215 %shr4.i = ashr i16 %add, 15
216 %conv5.i = trunc i16 %shr4.i to i8
217 %xor.i = xor i8 %conv5.i, 127
218 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
222 define i8 @testi16i8_revselect(i16 %add) {
223 ; CHECK-LABEL: @testi16i8_revselect(
224 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[ADD:%.*]], -128
225 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i16 [[ADD]], i16 -128
226 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i16 [[TMP2]], 127
227 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i16 [[TMP2]], i16 127
228 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i16 [[TMP4]] to i8
229 ; CHECK-NEXT: ret i8 [[TMP5]]
231 %sh = lshr i16 %add, 8
232 %conv.i = trunc i16 %sh to i8
233 %conv1.i = trunc i16 %add to i8
234 %shr2.i = ashr i8 %conv1.i, 7
235 %cmp.not.i = icmp ne i8 %conv.i, %shr2.i
236 %shr4.i = ashr i16 %add, 15
237 %conv5.i = trunc i16 %shr4.i to i8
238 %xor.i = xor i8 %conv5.i, 127
239 %cond.i = select i1 %cmp.not.i, i8 %xor.i, i8 %conv1.i
243 define i8 @testi32i8(i32 %add) {
244 ; CHECK-LABEL: @testi32i8(
245 ; CHECK-NEXT: [[SH:%.*]] = lshr i32 [[ADD:%.*]], 8
246 ; CHECK-NEXT: [[CONV_I:%.*]] = trunc i32 [[SH]] to i8
247 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i32 [[ADD]] to i8
248 ; CHECK-NEXT: [[SHR2_I:%.*]] = ashr i8 [[CONV1_I]], 7
249 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp eq i8 [[SHR2_I]], [[CONV_I]]
250 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[ADD]], 15
251 ; CHECK-NEXT: [[CONV5_I:%.*]] = trunc i32 [[TMP1]] to i8
252 ; CHECK-NEXT: [[XOR_I:%.*]] = xor i8 [[CONV5_I]], 127
253 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
254 ; CHECK-NEXT: ret i8 [[COND_I]]
256 %sh = lshr i32 %add, 8
257 %conv.i = trunc i32 %sh to i8
258 %conv1.i = trunc i32 %add to i8
259 %shr2.i = ashr i8 %conv1.i, 7
260 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
261 %shr4.i = ashr i32 %add, 15
262 %conv5.i = trunc i32 %shr4.i to i8
263 %xor.i = xor i8 %conv5.i, 127
264 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
268 define i16 @differentconsts(i32 %x, i16 %replacement_low, i16 %replacement_high) {
269 ; CHECK-LABEL: @differentconsts(
270 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], -16
271 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[X]], 127
272 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[X]] to i16
273 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], i16 256, i16 [[TMP3]]
274 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], i16 -1, i16 [[TMP4]]
275 ; CHECK-NEXT: ret i16 [[TMP5]]
277 %t0 = icmp slt i32 %x, 128
278 %t1 = select i1 %t0, i16 256, i16 65535
280 %t3 = icmp ult i32 %t2, 144
281 %t4 = trunc i32 %x to i16
282 %r = select i1 %t3, i16 %t4, i16 %t1
286 define i8 @badimm1(i16 %add) {
287 ; CHECK-LABEL: @badimm1(
288 ; CHECK-NEXT: [[SH:%.*]] = lshr i16 [[ADD:%.*]], 9
289 ; CHECK-NEXT: [[CONV_I:%.*]] = trunc i16 [[SH]] to i8
290 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i16 [[ADD]] to i8
291 ; CHECK-NEXT: [[SHR2_I:%.*]] = ashr i8 [[CONV1_I]], 7
292 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp eq i8 [[SHR2_I]], [[CONV_I]]
293 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[ADD]], -1
294 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP1]], i8 127, i8 -128
295 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
296 ; CHECK-NEXT: ret i8 [[COND_I]]
298 %sh = lshr i16 %add, 9
299 %conv.i = trunc i16 %sh to i8
300 %conv1.i = trunc i16 %add to i8
301 %shr2.i = ashr i8 %conv1.i, 7
302 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
303 %shr4.i = ashr i16 %add, 15
304 %conv5.i = trunc i16 %shr4.i to i8
305 %xor.i = xor i8 %conv5.i, 127
306 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
310 define i8 @badimm2(i16 %add) {
311 ; CHECK-LABEL: @badimm2(
312 ; CHECK-NEXT: [[SH:%.*]] = lshr i16 [[ADD:%.*]], 8
313 ; CHECK-NEXT: [[CONV_I:%.*]] = trunc i16 [[SH]] to i8
314 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i16 [[ADD]] to i8
315 ; CHECK-NEXT: [[SHR2_I:%.*]] = ashr i8 [[CONV1_I]], 6
316 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp eq i8 [[SHR2_I]], [[CONV_I]]
317 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 [[ADD]], -1
318 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP1]], i8 127, i8 -128
319 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
320 ; CHECK-NEXT: ret i8 [[COND_I]]
322 %sh = lshr i16 %add, 8
323 %conv.i = trunc i16 %sh to i8
324 %conv1.i = trunc i16 %add to i8
325 %shr2.i = ashr i8 %conv1.i, 6
326 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
327 %shr4.i = ashr i16 %add, 15
328 %conv5.i = trunc i16 %shr4.i to i8
329 %xor.i = xor i8 %conv5.i, 127
330 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
334 define i8 @badimm3(i16 %add) {
335 ; CHECK-LABEL: @badimm3(
336 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i16 [[ADD:%.*]] to i8
337 ; CHECK-NEXT: [[TMP1:%.*]] = add i16 [[ADD]], 128
338 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i16 [[TMP1]], 256
339 ; CHECK-NEXT: [[SHR4_I:%.*]] = ashr i16 [[ADD]], 14
340 ; CHECK-NEXT: [[CONV5_I:%.*]] = trunc i16 [[SHR4_I]] to i8
341 ; CHECK-NEXT: [[XOR_I:%.*]] = xor i8 [[CONV5_I]], 127
342 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i8 [[CONV1_I]], i8 [[XOR_I]]
343 ; CHECK-NEXT: ret i8 [[COND_I]]
345 %sh = lshr i16 %add, 8
346 %conv.i = trunc i16 %sh to i8
347 %conv1.i = trunc i16 %add to i8
348 %shr2.i = ashr i8 %conv1.i, 7
349 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
350 %shr4.i = ashr i16 %add, 14
351 %conv5.i = trunc i16 %shr4.i to i8
352 %xor.i = xor i8 %conv5.i, 127
353 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
357 define i8 @badimm4(i16 %add) {
358 ; CHECK-LABEL: @badimm4(
359 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i16 [[ADD:%.*]], -128
360 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i16 [[ADD]], 127
361 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i16 [[ADD]] to i8
362 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], i8 -127, i8 [[TMP3]]
363 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], i8 126, i8 [[TMP4]]
364 ; CHECK-NEXT: ret i8 [[TMP5]]
366 %sh = lshr i16 %add, 8
367 %conv.i = trunc i16 %sh to i8
368 %conv1.i = trunc i16 %add to i8
369 %shr2.i = ashr i8 %conv1.i, 7
370 %cmp.not.i = icmp eq i8 %shr2.i, %conv.i
371 %shr4.i = ashr i16 %add, 15
372 %conv5.i = trunc i16 %shr4.i to i8
373 %xor.i = xor i8 %conv5.i, 126
374 %cond.i = select i1 %cmp.not.i, i8 %conv1.i, i8 %xor.i
380 define i32 @oneusexor(i64 %add) {
381 ; CHECK-LABEL: @oneusexor(
382 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
383 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
384 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
385 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
386 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
387 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
388 ; CHECK-NEXT: call void @use(i32 [[XOR_I]])
389 ; CHECK-NEXT: ret i32 [[COND_I]]
391 %sh = lshr i64 %add, 32
392 %conv.i = trunc i64 %sh to i32
393 %conv1.i = trunc i64 %add to i32
394 %shr2.i = ashr i32 %conv1.i, 31
395 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
396 %shr4.i = ashr i64 %add, 63
397 %conv5.i = trunc i64 %shr4.i to i32
398 %xor.i = xor i32 %conv5.i, 2147483647
399 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
400 call void @use(i32 %xor.i)
404 define i32 @oneuseconv(i64 %add) {
405 ; CHECK-LABEL: @oneuseconv(
406 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
407 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
408 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
409 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
410 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
411 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
412 ; CHECK-NEXT: call void @use(i32 [[CONV1_I]])
413 ; CHECK-NEXT: ret i32 [[COND_I]]
415 %sh = lshr i64 %add, 32
416 %conv.i = trunc i64 %sh to i32
417 %conv1.i = trunc i64 %add to i32
418 %shr2.i = ashr i32 %conv1.i, 31
419 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
420 %shr4.i = ashr i64 %add, 63
421 %conv5.i = trunc i64 %shr4.i to i32
422 %xor.i = xor i32 %conv5.i, 2147483647
423 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
424 call void @use(i32 %conv1.i)
428 define i32 @oneusecmp(i64 %add) {
429 ; CHECK-LABEL: @oneusecmp(
430 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
431 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
432 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
433 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
434 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
435 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
436 ; CHECK-NEXT: call void @use1(i1 [[CMP_NOT_I]])
437 ; CHECK-NEXT: ret i32 [[COND_I]]
439 %sh = lshr i64 %add, 32
440 %conv.i = trunc i64 %sh to i32
441 %conv1.i = trunc i64 %add to i32
442 %shr2.i = ashr i32 %conv1.i, 31
443 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
444 %shr4.i = ashr i64 %add, 63
445 %conv5.i = trunc i64 %shr4.i to i32
446 %xor.i = xor i32 %conv5.i, 2147483647
447 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
448 call void @use1(i1 %cmp.not.i)
452 define i32 @oneuseboth(i64 %add) {
453 ; CHECK-LABEL: @oneuseboth(
454 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
455 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
456 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
457 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
458 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
459 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
460 ; CHECK-NEXT: call void @use(i32 [[XOR_I]])
461 ; CHECK-NEXT: call void @use(i32 [[CONV1_I]])
462 ; CHECK-NEXT: ret i32 [[COND_I]]
464 %sh = lshr i64 %add, 32
465 %conv.i = trunc i64 %sh to i32
466 %conv1.i = trunc i64 %add to i32
467 %shr2.i = ashr i32 %conv1.i, 31
468 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
469 %shr4.i = ashr i64 %add, 63
470 %conv5.i = trunc i64 %shr4.i to i32
471 %xor.i = xor i32 %conv5.i, 2147483647
472 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
473 call void @use(i32 %xor.i)
474 call void @use(i32 %conv1.i)
478 define i32 @oneusethree(i64 %add) {
479 ; CHECK-LABEL: @oneusethree(
480 ; CHECK-NEXT: [[CONV1_I:%.*]] = trunc i64 [[ADD:%.*]] to i32
481 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[ADD]], 2147483648
482 ; CHECK-NEXT: [[CMP_NOT_I:%.*]] = icmp ult i64 [[TMP1]], 4294967296
483 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[ADD]], -1
484 ; CHECK-NEXT: [[XOR_I:%.*]] = select i1 [[TMP2]], i32 2147483647, i32 -2147483648
485 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_NOT_I]], i32 [[CONV1_I]], i32 [[XOR_I]]
486 ; CHECK-NEXT: call void @use(i32 [[XOR_I]])
487 ; CHECK-NEXT: call void @use(i32 [[CONV1_I]])
488 ; CHECK-NEXT: call void @use1(i1 [[CMP_NOT_I]])
489 ; CHECK-NEXT: ret i32 [[COND_I]]
491 %sh = lshr i64 %add, 32
492 %conv.i = trunc i64 %sh to i32
493 %conv1.i = trunc i64 %add to i32
494 %shr2.i = ashr i32 %conv1.i, 31
495 %cmp.not.i = icmp eq i32 %shr2.i, %conv.i
496 %shr4.i = ashr i64 %add, 63
497 %conv5.i = trunc i64 %shr4.i to i32
498 %xor.i = xor i32 %conv5.i, 2147483647
499 %cond.i = select i1 %cmp.not.i, i32 %conv1.i, i32 %xor.i
500 call void @use(i32 %xor.i)
501 call void @use(i32 %conv1.i)
502 call void @use1(i1 %cmp.not.i)
506 define i16 @differentconsts_usetrunc(i32 %x, i16 %replacement_low, i16 %replacement_high) {
507 ; CHECK-LABEL: @differentconsts_usetrunc(
508 ; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[X:%.*]], 128
509 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i16 256, i16 -1
510 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[X]], 16
511 ; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 144
512 ; CHECK-NEXT: [[T4:%.*]] = trunc i32 [[X]] to i16
513 ; CHECK-NEXT: [[R:%.*]] = select i1 [[T3]], i16 [[T4]], i16 [[T1]]
514 ; CHECK-NEXT: call void @use16(i16 [[T4]])
515 ; CHECK-NEXT: ret i16 [[R]]
517 %t0 = icmp slt i32 %x, 128
518 %t1 = select i1 %t0, i16 256, i16 65535
520 %t3 = icmp ult i32 %t2, 144
521 %t4 = trunc i32 %x to i16
522 %r = select i1 %t3, i16 %t4, i16 %t1
523 call void @use16(i16 %t4)
527 define i16 @differentconsts_useadd(i32 %x, i16 %replacement_low, i16 %replacement_high) {
528 ; CHECK-LABEL: @differentconsts_useadd(
529 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[X:%.*]], 16
530 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X]], -16
531 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[X]], 127
532 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[X]] to i16
533 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], i16 256, i16 [[TMP3]]
534 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], i16 -1, i16 [[TMP4]]
535 ; CHECK-NEXT: call void @use(i32 [[T2]])
536 ; CHECK-NEXT: ret i16 [[TMP5]]
538 %t0 = icmp slt i32 %x, 128
539 %t1 = select i1 %t0, i16 256, i16 65535
541 %t3 = icmp ult i32 %t2, 144
542 %t4 = trunc i32 %x to i16
543 %r = select i1 %t3, i16 %t4, i16 %t1
544 call void @use(i32 %t2)
548 define i16 @differentconsts_useaddtrunc(i32 %x, i16 %replacement_low, i16 %replacement_high) {
549 ; CHECK-LABEL: @differentconsts_useaddtrunc(
550 ; CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[X:%.*]], 128
551 ; CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i16 256, i16 -1
552 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[X]], 16
553 ; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 144
554 ; CHECK-NEXT: [[T4:%.*]] = trunc i32 [[X]] to i16
555 ; CHECK-NEXT: [[R:%.*]] = select i1 [[T3]], i16 [[T4]], i16 [[T1]]
556 ; CHECK-NEXT: call void @use16(i16 [[T4]])
557 ; CHECK-NEXT: call void @use(i32 [[T2]])
558 ; CHECK-NEXT: ret i16 [[R]]
560 %t0 = icmp slt i32 %x, 128
561 %t1 = select i1 %t0, i16 256, i16 65535
563 %t3 = icmp ult i32 %t2, 144
564 %t4 = trunc i32 %x to i16
565 %r = select i1 %t3, i16 %t4, i16 %t1
566 call void @use16(i16 %t4)
567 call void @use(i32 %t2)
572 define i8 @C0zero(i8 %X, i8 %y, i8 %z) {
573 ; CHECK-LABEL: @C0zero(
574 ; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], -10
575 ; CHECK-NEXT: [[F:%.*]] = select i1 [[C]], i8 [[Y:%.*]], i8 [[Z:%.*]]
576 ; CHECK-NEXT: ret i8 [[F]]
579 %cmp = icmp ult i8 %a, 0
580 %c = icmp slt i8 %X, -10
581 %f = select i1 %c, i8 %y, i8 %z
582 %r = select i1 %cmp, i8 %X, i8 %f
586 define <2 x i8> @C0zeroV(<2 x i8> %X, <2 x i8> %y, <2 x i8> %z) {
587 ; CHECK-LABEL: @C0zeroV(
588 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 -10, i8 -10>
589 ; CHECK-NEXT: [[F:%.*]] = select <2 x i1> [[C]], <2 x i8> [[Y:%.*]], <2 x i8> [[Z:%.*]]
590 ; CHECK-NEXT: ret <2 x i8> [[F]]
592 %a = add <2 x i8> %X, <i8 10, i8 10>
593 %cmp = icmp ult <2 x i8> %a, zeroinitializer
594 %c = icmp slt <2 x i8> %X, <i8 -10, i8 -10>
595 %f = select <2 x i1> %c, <2 x i8> %y, <2 x i8> %z
596 %r = select <2 x i1> %cmp, <2 x i8> %X, <2 x i8> %f
600 define <2 x i8> @C0zeroVu(<2 x i8> %X, <2 x i8> %y, <2 x i8> %z) {
601 ; CHECK-LABEL: @C0zeroVu(
602 ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 10, i8 10>
603 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[A]], <i8 0, i8 10>
604 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i8> [[X]], <i8 -10, i8 -10>
605 ; CHECK-NEXT: [[F:%.*]] = select <2 x i1> [[C]], <2 x i8> [[Y:%.*]], <2 x i8> [[Z:%.*]]
606 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[F]]
607 ; CHECK-NEXT: ret <2 x i8> [[R]]
609 %a = add <2 x i8> %X, <i8 10, i8 10>
610 %cmp = icmp ult <2 x i8> %a, <i8 0, i8 10>
611 %c = icmp slt <2 x i8> %X, <i8 -10, i8 -10>
612 %f = select <2 x i1> %c, <2 x i8> %y, <2 x i8> %z
613 %r = select <2 x i1> %cmp, <2 x i8> %X, <2 x i8> %f
617 define i8 @f(i32 %value, i8 %call.i) {
620 ; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[VALUE:%.*]], 0
621 ; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], i8 [[CALL_I:%.*]], i8 0
622 ; CHECK-NEXT: [[CMP_I_I:%.*]] = icmp ult i32 [[VALUE]], 256
623 ; CHECK-NEXT: [[CONV4:%.*]] = trunc i32 [[VALUE]] to i8
624 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP_I_I]], i8 [[CONV4]], i8 [[COND_I]]
625 ; CHECK-NEXT: ret i8 [[COND]]
628 %cmp.i = icmp slt i32 %value, 0
629 %cond.i = select i1 %cmp.i, i8 %call.i, i8 0
630 %cmp.i.i = icmp ult i32 %value, 256
631 %conv4 = trunc i32 %value to i8
632 %cond = select i1 %cmp.i.i, i8 %conv4, i8 %cond.i