1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i32 @abs_abs_x01(i32 %x) {
5 ; CHECK-LABEL: @abs_abs_x01(
6 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
7 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
8 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
9 ; CHECK-NEXT: ret i32 [[COND]]
11 %cmp = icmp sgt i32 %x, -1
12 %sub = sub nsw i32 0, %x
13 %cond = select i1 %cmp, i32 %x, i32 %sub
14 %cmp1 = icmp sgt i32 %cond, -1
15 %sub16 = sub nsw i32 0, %cond
16 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
20 define <2 x i32> @abs_abs_x01_vec(<2 x i32> %x) {
21 ; CHECK-LABEL: @abs_abs_x01_vec(
22 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
23 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X]]
24 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]]
25 ; CHECK-NEXT: ret <2 x i32> [[COND]]
27 %cmp = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
28 %sub = sub nsw <2 x i32> zeroinitializer, %x
29 %cond = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %sub
30 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
31 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
32 %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
36 define i32 @abs_abs_x02(i32 %x) {
37 ; CHECK-LABEL: @abs_abs_x02(
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
39 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
40 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
41 ; CHECK-NEXT: ret i32 [[COND]]
43 %cmp = icmp sgt i32 %x, 0
44 %sub = sub nsw i32 0, %x
45 %cond = select i1 %cmp, i32 %x, i32 %sub
46 %cmp1 = icmp sgt i32 %cond, -1
47 %sub16 = sub nsw i32 0, %cond
48 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
52 define i32 @abs_abs_x03(i32 %x) {
53 ; CHECK-LABEL: @abs_abs_x03(
54 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
55 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
56 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
57 ; CHECK-NEXT: ret i32 [[COND]]
59 %cmp = icmp slt i32 %x, 0
60 %sub = sub nsw i32 0, %x
61 %cond = select i1 %cmp, i32 %sub, i32 %x
62 %cmp1 = icmp sgt i32 %cond, -1
63 %sub16 = sub nsw i32 0, %cond
64 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
68 define i32 @abs_abs_x04(i32 %x) {
69 ; CHECK-LABEL: @abs_abs_x04(
70 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
71 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
72 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
73 ; CHECK-NEXT: ret i32 [[COND]]
75 %cmp = icmp slt i32 %x, 1
76 %sub = sub nsw i32 0, %x
77 %cond = select i1 %cmp, i32 %sub, i32 %x
78 %cmp1 = icmp sgt i32 %cond, -1
79 %sub16 = sub nsw i32 0, %cond
80 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
84 define <2 x i32> @abs_abs_x04_vec(<2 x i32> %x) {
85 ; CHECK-LABEL: @abs_abs_x04_vec(
86 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
87 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X]]
88 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]]
89 ; CHECK-NEXT: ret <2 x i32> [[COND]]
91 %cmp = icmp slt <2 x i32> %x, <i32 1, i32 1>
92 %sub = sub nsw <2 x i32> zeroinitializer, %x
93 %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x
94 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
95 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
96 %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
100 define i32 @abs_abs_x05(i32 %x) {
101 ; CHECK-LABEL: @abs_abs_x05(
102 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
103 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
104 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
105 ; CHECK-NEXT: ret i32 [[COND]]
107 %cmp = icmp sgt i32 %x, -1
108 %sub = sub nsw i32 0, %x
109 %cond = select i1 %cmp, i32 %x, i32 %sub
110 %cmp1 = icmp sgt i32 %cond, 0
111 %sub16 = sub nsw i32 0, %cond
112 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
116 define i32 @abs_abs_x06(i32 %x) {
117 ; CHECK-LABEL: @abs_abs_x06(
118 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
119 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
120 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
121 ; CHECK-NEXT: ret i32 [[COND]]
123 %cmp = icmp sgt i32 %x, 0
124 %sub = sub nsw i32 0, %x
125 %cond = select i1 %cmp, i32 %x, i32 %sub
126 %cmp1 = icmp sgt i32 %cond, 0
127 %sub16 = sub nsw i32 0, %cond
128 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
132 define i32 @abs_abs_x07(i32 %x) {
133 ; CHECK-LABEL: @abs_abs_x07(
134 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
135 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
136 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
137 ; CHECK-NEXT: ret i32 [[COND]]
139 %cmp = icmp slt i32 %x, 0
140 %sub = sub nsw i32 0, %x
141 %cond = select i1 %cmp, i32 %sub, i32 %x
142 %cmp1 = icmp sgt i32 %cond, 0
143 %sub16 = sub nsw i32 0, %cond
144 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
148 define i32 @abs_abs_x08(i32 %x) {
149 ; CHECK-LABEL: @abs_abs_x08(
150 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
151 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
152 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
153 ; CHECK-NEXT: ret i32 [[COND]]
155 %cmp = icmp slt i32 %x, 1
156 %sub = sub nsw i32 0, %x
157 %cond = select i1 %cmp, i32 %sub, i32 %x
158 %cmp1 = icmp sgt i32 %cond, 0
159 %sub16 = sub nsw i32 0, %cond
160 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
164 define i32 @abs_abs_x09(i32 %x) {
165 ; CHECK-LABEL: @abs_abs_x09(
166 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
167 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
168 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
169 ; CHECK-NEXT: ret i32 [[COND]]
171 %cmp = icmp sgt i32 %x, -1
172 %sub = sub nsw i32 0, %x
173 %cond = select i1 %cmp, i32 %x, i32 %sub
174 %cmp1 = icmp slt i32 %cond, 0
175 %sub9 = sub nsw i32 0, %cond
176 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
180 define i32 @abs_abs_x10(i32 %x) {
181 ; CHECK-LABEL: @abs_abs_x10(
182 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
183 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
184 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
185 ; CHECK-NEXT: ret i32 [[COND]]
187 %cmp = icmp sgt i32 %x, 0
188 %sub = sub nsw i32 0, %x
189 %cond = select i1 %cmp, i32 %x, i32 %sub
190 %cmp1 = icmp slt i32 %cond, 0
191 %sub9 = sub nsw i32 0, %cond
192 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
196 define i32 @abs_abs_x11(i32 %x) {
197 ; CHECK-LABEL: @abs_abs_x11(
198 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
199 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
200 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
201 ; CHECK-NEXT: ret i32 [[COND]]
203 %cmp = icmp slt i32 %x, 0
204 %sub = sub nsw i32 0, %x
205 %cond = select i1 %cmp, i32 %sub, i32 %x
206 %cmp1 = icmp slt i32 %cond, 0
207 %sub9 = sub nsw i32 0, %cond
208 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
212 define i32 @abs_abs_x12(i32 %x) {
213 ; CHECK-LABEL: @abs_abs_x12(
214 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
215 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
216 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
217 ; CHECK-NEXT: ret i32 [[COND]]
219 %cmp = icmp slt i32 %x, 1
220 %sub = sub nsw i32 0, %x
221 %cond = select i1 %cmp, i32 %sub, i32 %x
222 %cmp1 = icmp slt i32 %cond, 0
223 %sub9 = sub nsw i32 0, %cond
224 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
228 define i32 @abs_abs_x13(i32 %x) {
229 ; CHECK-LABEL: @abs_abs_x13(
230 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
231 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
232 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
233 ; CHECK-NEXT: ret i32 [[COND]]
235 %cmp = icmp sgt i32 %x, -1
236 %sub = sub nsw i32 0, %x
237 %cond = select i1 %cmp, i32 %x, i32 %sub
238 %cmp1 = icmp slt i32 %cond, 1
239 %sub9 = sub nsw i32 0, %cond
240 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
244 define i32 @abs_abs_x14(i32 %x) {
245 ; CHECK-LABEL: @abs_abs_x14(
246 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
247 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
248 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
249 ; CHECK-NEXT: ret i32 [[COND]]
251 %cmp = icmp sgt i32 %x, 0
252 %sub = sub nsw i32 0, %x
253 %cond = select i1 %cmp, i32 %x, i32 %sub
254 %cmp1 = icmp slt i32 %cond, 1
255 %sub9 = sub nsw i32 0, %cond
256 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
260 define i32 @abs_abs_x15(i32 %x) {
261 ; CHECK-LABEL: @abs_abs_x15(
262 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
263 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
264 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
265 ; CHECK-NEXT: ret i32 [[COND]]
267 %cmp = icmp slt i32 %x, 0
268 %sub = sub nsw i32 0, %x
269 %cond = select i1 %cmp, i32 %sub, i32 %x
270 %cmp1 = icmp slt i32 %cond, 1
271 %sub9 = sub nsw i32 0, %cond
272 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
276 define i32 @abs_abs_x16(i32 %x) {
277 ; CHECK-LABEL: @abs_abs_x16(
278 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
279 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
280 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
281 ; CHECK-NEXT: ret i32 [[COND]]
283 %cmp = icmp slt i32 %x, 1
284 %sub = sub nsw i32 0, %x
285 %cond = select i1 %cmp, i32 %sub, i32 %x
286 %cmp1 = icmp slt i32 %cond, 1
287 %sub9 = sub nsw i32 0, %cond
288 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
292 ; abs(abs(-x)) -> abs(-x) -> abs(x)
293 define i32 @abs_abs_x17(i32 %x) {
294 ; CHECK-LABEL: @abs_abs_x17(
295 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]]
296 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0
297 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
298 ; CHECK-NEXT: ret i32 [[COND]]
300 %sub = sub nsw i32 0, %x
301 %cmp = icmp sgt i32 %sub, -1
302 %cond = select i1 %cmp, i32 %sub, i32 %x
303 %cmp1 = icmp sgt i32 %cond, -1
304 %sub16 = sub nsw i32 0, %cond
305 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
309 ; abs(abs(x - y)) -> abs(x - y)
310 define i32 @abs_abs_x18(i32 %x, i32 %y) {
311 ; CHECK-LABEL: @abs_abs_x18(
312 ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
313 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0
314 ; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]]
315 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[NEGA]], i32 [[A]]
316 ; CHECK-NEXT: ret i32 [[COND]]
318 %a = sub nsw i32 %x, %y
319 %b = sub nsw i32 %y, %x
320 %cmp = icmp sgt i32 %a, -1
321 %cond = select i1 %cmp, i32 %a, i32 %b
322 %cmp1 = icmp sgt i32 %cond, -1
323 %sub16 = sub nsw i32 0, %cond
324 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
328 ; abs(abs(-x)) -> abs(-x) -> abs(x)
329 define <2 x i32> @abs_abs_x02_vec(<2 x i32> %x) {
330 ; CHECK-LABEL: @abs_abs_x02_vec(
331 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
332 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer
333 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]]
334 ; CHECK-NEXT: ret <2 x i32> [[COND]]
336 %sub = sub nsw <2 x i32> zeroinitializer, %x
337 %cmp = icmp sgt <2 x i32> %sub, <i32 -1, i32 -1>
338 %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x
339 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
340 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
341 %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
342 ret <2 x i32> %cond18
345 ; abs(abs(x - y)) -> abs(x - y)
346 define <2 x i32> @abs_abs_x03_vec(<2 x i32> %x, <2 x i32> %y) {
347 ; CHECK-LABEL: @abs_abs_x03_vec(
348 ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
349 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer
350 ; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]]
351 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NEGA]], <2 x i32> [[A]]
352 ; CHECK-NEXT: ret <2 x i32> [[COND]]
354 %a = sub nsw <2 x i32> %x, %y
355 %b = sub nsw <2 x i32> %y, %x
356 %cmp = icmp sgt <2 x i32> %a, <i32 -1, i32 -1>
357 %cond = select <2 x i1> %cmp, <2 x i32> %a, <2 x i32> %b
358 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
359 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
360 %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
361 ret <2 x i32> %cond18
364 define i32 @nabs_nabs_x01(i32 %x) {
365 ; CHECK-LABEL: @nabs_nabs_x01(
366 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
367 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
368 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
369 ; CHECK-NEXT: ret i32 [[COND]]
371 %cmp = icmp sgt i32 %x, -1
372 %sub = sub nsw i32 0, %x
373 %cond = select i1 %cmp, i32 %sub, i32 %x
374 %cmp1 = icmp sgt i32 %cond, -1
375 %sub9 = sub nsw i32 0, %cond
376 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
380 define i32 @nabs_nabs_x02(i32 %x) {
381 ; CHECK-LABEL: @nabs_nabs_x02(
382 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
383 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
384 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
385 ; CHECK-NEXT: ret i32 [[COND]]
387 %cmp = icmp sgt i32 %x, 0
388 %sub = sub nsw i32 0, %x
389 %cond = select i1 %cmp, i32 %sub, i32 %x
390 %cmp1 = icmp sgt i32 %cond, -1
391 %sub9 = sub nsw i32 0, %cond
392 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
396 define i32 @nabs_nabs_x03(i32 %x) {
397 ; CHECK-LABEL: @nabs_nabs_x03(
398 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
399 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
400 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
401 ; CHECK-NEXT: ret i32 [[COND]]
403 %cmp = icmp slt i32 %x, 0
404 %sub = sub nsw i32 0, %x
405 %cond = select i1 %cmp, i32 %x, i32 %sub
406 %cmp1 = icmp sgt i32 %cond, -1
407 %sub9 = sub nsw i32 0, %cond
408 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
412 define i32 @nabs_nabs_x04(i32 %x) {
413 ; CHECK-LABEL: @nabs_nabs_x04(
414 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
415 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
416 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
417 ; CHECK-NEXT: ret i32 [[COND]]
419 %cmp = icmp slt i32 %x, 1
420 %sub = sub nsw i32 0, %x
421 %cond = select i1 %cmp, i32 %x, i32 %sub
422 %cmp1 = icmp sgt i32 %cond, -1
423 %sub9 = sub nsw i32 0, %cond
424 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
428 define i32 @nabs_nabs_x05(i32 %x) {
429 ; CHECK-LABEL: @nabs_nabs_x05(
430 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
431 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
432 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
433 ; CHECK-NEXT: ret i32 [[COND]]
435 %cmp = icmp sgt i32 %x, -1
436 %sub = sub nsw i32 0, %x
437 %cond = select i1 %cmp, i32 %sub, i32 %x
438 %cmp1 = icmp sgt i32 %cond, 0
439 %sub9 = sub nsw i32 0, %cond
440 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
444 define i32 @nabs_nabs_x06(i32 %x) {
445 ; CHECK-LABEL: @nabs_nabs_x06(
446 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
447 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
448 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
449 ; CHECK-NEXT: ret i32 [[COND]]
451 %cmp = icmp sgt i32 %x, 0
452 %sub = sub nsw i32 0, %x
453 %cond = select i1 %cmp, i32 %sub, i32 %x
454 %cmp1 = icmp sgt i32 %cond, 0
455 %sub9 = sub nsw i32 0, %cond
456 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
460 define i32 @nabs_nabs_x07(i32 %x) {
461 ; CHECK-LABEL: @nabs_nabs_x07(
462 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
463 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
464 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
465 ; CHECK-NEXT: ret i32 [[COND]]
467 %cmp = icmp slt i32 %x, 0
468 %sub = sub nsw i32 0, %x
469 %cond = select i1 %cmp, i32 %x, i32 %sub
470 %cmp1 = icmp sgt i32 %cond, 0
471 %sub9 = sub nsw i32 0, %cond
472 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
476 define i32 @nabs_nabs_x08(i32 %x) {
477 ; CHECK-LABEL: @nabs_nabs_x08(
478 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
479 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
480 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
481 ; CHECK-NEXT: ret i32 [[COND]]
483 %cmp = icmp slt i32 %x, 1
484 %sub = sub nsw i32 0, %x
485 %cond = select i1 %cmp, i32 %x, i32 %sub
486 %cmp1 = icmp sgt i32 %cond, 0
487 %sub9 = sub nsw i32 0, %cond
488 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
492 define i32 @nabs_nabs_x09(i32 %x) {
493 ; CHECK-LABEL: @nabs_nabs_x09(
494 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
495 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
496 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
497 ; CHECK-NEXT: ret i32 [[COND]]
499 %cmp = icmp sgt i32 %x, -1
500 %sub = sub nsw i32 0, %x
501 %cond = select i1 %cmp, i32 %sub, i32 %x
502 %cmp1 = icmp slt i32 %cond, 0
503 %sub16 = sub nsw i32 0, %cond
504 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
508 define i32 @nabs_nabs_x10(i32 %x) {
509 ; CHECK-LABEL: @nabs_nabs_x10(
510 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
511 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
512 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
513 ; CHECK-NEXT: ret i32 [[COND]]
515 %cmp = icmp sgt i32 %x, 0
516 %sub = sub nsw i32 0, %x
517 %cond = select i1 %cmp, i32 %sub, i32 %x
518 %cmp1 = icmp slt i32 %cond, 0
519 %sub16 = sub nsw i32 0, %cond
520 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
524 define i32 @nabs_nabs_x11(i32 %x) {
525 ; CHECK-LABEL: @nabs_nabs_x11(
526 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
527 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
528 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
529 ; CHECK-NEXT: ret i32 [[COND]]
531 %cmp = icmp slt i32 %x, 0
532 %sub = sub nsw i32 0, %x
533 %cond = select i1 %cmp, i32 %x, i32 %sub
534 %cmp1 = icmp slt i32 %cond, 0
535 %sub16 = sub nsw i32 0, %cond
536 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
540 define i32 @nabs_nabs_x12(i32 %x) {
541 ; CHECK-LABEL: @nabs_nabs_x12(
542 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
543 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
544 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
545 ; CHECK-NEXT: ret i32 [[COND]]
547 %cmp = icmp slt i32 %x, 1
548 %sub = sub nsw i32 0, %x
549 %cond = select i1 %cmp, i32 %x, i32 %sub
550 %cmp1 = icmp slt i32 %cond, 0
551 %sub16 = sub nsw i32 0, %cond
552 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
556 define i32 @nabs_nabs_x13(i32 %x) {
557 ; CHECK-LABEL: @nabs_nabs_x13(
558 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
559 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
560 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
561 ; CHECK-NEXT: ret i32 [[COND]]
563 %cmp = icmp sgt i32 %x, -1
564 %sub = sub nsw i32 0, %x
565 %cond = select i1 %cmp, i32 %sub, i32 %x
566 %cmp1 = icmp slt i32 %cond, 1
567 %sub16 = sub nsw i32 0, %cond
568 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
572 define i32 @nabs_nabs_x14(i32 %x) {
573 ; CHECK-LABEL: @nabs_nabs_x14(
574 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
575 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
576 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
577 ; CHECK-NEXT: ret i32 [[COND]]
579 %cmp = icmp sgt i32 %x, 0
580 %sub = sub nsw i32 0, %x
581 %cond = select i1 %cmp, i32 %sub, i32 %x
582 %cmp1 = icmp slt i32 %cond, 1
583 %sub16 = sub nsw i32 0, %cond
584 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
588 define i32 @nabs_nabs_x15(i32 %x) {
589 ; CHECK-LABEL: @nabs_nabs_x15(
590 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
591 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
592 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
593 ; CHECK-NEXT: ret i32 [[COND]]
595 %cmp = icmp slt i32 %x, 0
596 %sub = sub nsw i32 0, %x
597 %cond = select i1 %cmp, i32 %x, i32 %sub
598 %cmp1 = icmp slt i32 %cond, 1
599 %sub16 = sub nsw i32 0, %cond
600 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
604 define i32 @nabs_nabs_x16(i32 %x) {
605 ; CHECK-LABEL: @nabs_nabs_x16(
606 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
607 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
608 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
609 ; CHECK-NEXT: ret i32 [[COND]]
611 %cmp = icmp slt i32 %x, 1
612 %sub = sub nsw i32 0, %x
613 %cond = select i1 %cmp, i32 %x, i32 %sub
614 %cmp1 = icmp slt i32 %cond, 1
615 %sub16 = sub nsw i32 0, %cond
616 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
620 ; nabs(nabs(-x)) -> nabs(-x) -> nabs(x)
621 define i32 @nabs_nabs_x17(i32 %x) {
622 ; CHECK-LABEL: @nabs_nabs_x17(
623 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]]
624 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0
625 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
626 ; CHECK-NEXT: ret i32 [[COND]]
628 %sub = sub nsw i32 0, %x
629 %cmp = icmp sgt i32 %sub, -1
630 %cond = select i1 %cmp, i32 %x, i32 %sub
631 %cmp1 = icmp sgt i32 %cond, -1
632 %sub16 = sub nsw i32 0, %cond
633 %cond18 = select i1 %cmp1, i32 %sub16, i32 %cond
637 ; nabs(nabs(x - y)) -> nabs(x - y)
638 define i32 @nabs_nabs_x18(i32 %x, i32 %y) {
639 ; CHECK-LABEL: @nabs_nabs_x18(
640 ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
641 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0
642 ; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]]
643 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[NEGA]]
644 ; CHECK-NEXT: ret i32 [[COND]]
646 %a = sub nsw i32 %x, %y
647 %b = sub nsw i32 %y, %x
648 %cmp = icmp sgt i32 %a, -1
649 %cond = select i1 %cmp, i32 %b, i32 %a
650 %cmp1 = icmp sgt i32 %cond, -1
651 %sub16 = sub nsw i32 0, %cond
652 %cond18 = select i1 %cmp1, i32 %sub16, i32 %cond
656 ; nabs(nabs(-x)) -> nabs(-x) -> nabs(x)
657 define <2 x i32> @nabs_nabs_x01_vec(<2 x i32> %x) {
658 ; CHECK-LABEL: @nabs_nabs_x01_vec(
659 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
660 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer
661 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]]
662 ; CHECK-NEXT: ret <2 x i32> [[COND]]
664 %sub = sub nsw <2 x i32> zeroinitializer, %x
665 %cmp = icmp sgt <2 x i32> %sub, <i32 -1, i32 -1>
666 %cond = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %sub
667 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
668 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
669 %cond18 = select <2 x i1> %cmp1, <2 x i32> %sub16, <2 x i32> %cond
670 ret <2 x i32> %cond18
673 ; nabs(nabs(x - y)) -> nabs(x - y)
674 define <2 x i32> @nabs_nabs_x02_vec(<2 x i32> %x, <2 x i32> %y) {
675 ; CHECK-LABEL: @nabs_nabs_x02_vec(
676 ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
677 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer
678 ; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]]
679 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[A]], <2 x i32> [[NEGA]]
680 ; CHECK-NEXT: ret <2 x i32> [[COND]]
682 %a = sub nsw <2 x i32> %x, %y
683 %b = sub nsw <2 x i32> %y, %x
684 %cmp = icmp sgt <2 x i32> %a, <i32 -1, i32 -1>
685 %cond = select <2 x i1> %cmp, <2 x i32> %b, <2 x i32> %a
686 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
687 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
688 %cond18 = select <2 x i1> %cmp1, <2 x i32> %sub16, <2 x i32> %cond
689 ret <2 x i32> %cond18
692 define i32 @abs_nabs_x01(i32 %x) {
693 ; CHECK-LABEL: @abs_nabs_x01(
694 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
695 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
696 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
697 ; CHECK-NEXT: ret i32 [[COND1]]
699 %cmp = icmp sgt i32 %x, -1
700 %sub = sub nsw i32 0, %x
701 %cond = select i1 %cmp, i32 %sub, i32 %x
702 %cmp1 = icmp sgt i32 %cond, -1
703 %sub16 = sub nsw i32 0, %cond
704 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
708 define i32 @abs_nabs_x02(i32 %x) {
709 ; CHECK-LABEL: @abs_nabs_x02(
710 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
711 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
712 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
713 ; CHECK-NEXT: ret i32 [[COND1]]
715 %cmp = icmp sgt i32 %x, 0
716 %sub = sub nsw i32 0, %x
717 %cond = select i1 %cmp, i32 %sub, i32 %x
718 %cmp1 = icmp sgt i32 %cond, -1
719 %sub16 = sub nsw i32 0, %cond
720 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
724 define i32 @abs_nabs_x03(i32 %x) {
725 ; CHECK-LABEL: @abs_nabs_x03(
726 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
727 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
728 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
729 ; CHECK-NEXT: ret i32 [[COND1]]
731 %cmp = icmp slt i32 %x, 0
732 %sub = sub nsw i32 0, %x
733 %cond = select i1 %cmp, i32 %x, i32 %sub
734 %cmp1 = icmp sgt i32 %cond, -1
735 %sub16 = sub nsw i32 0, %cond
736 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
740 define i32 @abs_nabs_x04(i32 %x) {
741 ; CHECK-LABEL: @abs_nabs_x04(
742 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
743 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
744 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
745 ; CHECK-NEXT: ret i32 [[COND1]]
747 %cmp = icmp slt i32 %x, 1
748 %sub = sub nsw i32 0, %x
749 %cond = select i1 %cmp, i32 %x, i32 %sub
750 %cmp1 = icmp sgt i32 %cond, -1
751 %sub16 = sub nsw i32 0, %cond
752 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
756 define i32 @abs_nabs_x05(i32 %x) {
757 ; CHECK-LABEL: @abs_nabs_x05(
758 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
759 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
760 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
761 ; CHECK-NEXT: ret i32 [[COND1]]
763 %cmp = icmp sgt i32 %x, -1
764 %sub = sub nsw i32 0, %x
765 %cond = select i1 %cmp, i32 %sub, i32 %x
766 %cmp1 = icmp sgt i32 %cond, 0
767 %sub16 = sub nsw i32 0, %cond
768 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
772 define i32 @abs_nabs_x06(i32 %x) {
773 ; CHECK-LABEL: @abs_nabs_x06(
774 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
775 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
776 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
777 ; CHECK-NEXT: ret i32 [[COND1]]
779 %cmp = icmp sgt i32 %x, 0
780 %sub = sub nsw i32 0, %x
781 %cond = select i1 %cmp, i32 %sub, i32 %x
782 %cmp1 = icmp sgt i32 %cond, 0
783 %sub16 = sub nsw i32 0, %cond
784 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
788 define i32 @abs_nabs_x07(i32 %x) {
789 ; CHECK-LABEL: @abs_nabs_x07(
790 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
791 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
792 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
793 ; CHECK-NEXT: ret i32 [[COND1]]
795 %cmp = icmp slt i32 %x, 0
796 %sub = sub nsw i32 0, %x
797 %cond = select i1 %cmp, i32 %x, i32 %sub
798 %cmp1 = icmp sgt i32 %cond, 0
799 %sub16 = sub nsw i32 0, %cond
800 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
804 define i32 @abs_nabs_x08(i32 %x) {
805 ; CHECK-LABEL: @abs_nabs_x08(
806 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
807 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
808 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
809 ; CHECK-NEXT: ret i32 [[COND1]]
811 %cmp = icmp slt i32 %x, 1
812 %sub = sub nsw i32 0, %x
813 %cond = select i1 %cmp, i32 %x, i32 %sub
814 %cmp1 = icmp sgt i32 %cond, 0
815 %sub16 = sub nsw i32 0, %cond
816 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
820 define i32 @abs_nabs_x09(i32 %x) {
821 ; CHECK-LABEL: @abs_nabs_x09(
822 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
823 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
824 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
825 ; CHECK-NEXT: ret i32 [[COND1]]
827 %cmp = icmp sgt i32 %x, -1
828 %sub = sub nsw i32 0, %x
829 %cond = select i1 %cmp, i32 %sub, i32 %x
830 %cmp1 = icmp slt i32 %cond, 0
831 %sub9 = sub nsw i32 0, %cond
832 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
836 define i32 @abs_nabs_x10(i32 %x) {
837 ; CHECK-LABEL: @abs_nabs_x10(
838 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
839 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
840 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
841 ; CHECK-NEXT: ret i32 [[COND1]]
843 %cmp = icmp sgt i32 %x, 0
844 %sub = sub nsw i32 0, %x
845 %cond = select i1 %cmp, i32 %sub, i32 %x
846 %cmp1 = icmp slt i32 %cond, 0
847 %sub9 = sub nsw i32 0, %cond
848 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
852 define i32 @abs_nabs_x11(i32 %x) {
853 ; CHECK-LABEL: @abs_nabs_x11(
854 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
855 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
856 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
857 ; CHECK-NEXT: ret i32 [[COND1]]
859 %cmp = icmp slt i32 %x, 0
860 %sub = sub nsw i32 0, %x
861 %cond = select i1 %cmp, i32 %x, i32 %sub
862 %cmp1 = icmp slt i32 %cond, 0
863 %sub9 = sub nsw i32 0, %cond
864 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
868 define i32 @abs_nabs_x12(i32 %x) {
869 ; CHECK-LABEL: @abs_nabs_x12(
870 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
871 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
872 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
873 ; CHECK-NEXT: ret i32 [[COND1]]
875 %cmp = icmp slt i32 %x, 1
876 %sub = sub nsw i32 0, %x
877 %cond = select i1 %cmp, i32 %x, i32 %sub
878 %cmp1 = icmp slt i32 %cond, 0
879 %sub9 = sub nsw i32 0, %cond
880 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
884 define i32 @abs_nabs_x13(i32 %x) {
885 ; CHECK-LABEL: @abs_nabs_x13(
886 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
887 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
888 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
889 ; CHECK-NEXT: ret i32 [[COND1]]
891 %cmp = icmp sgt i32 %x, -1
892 %sub = sub nsw i32 0, %x
893 %cond = select i1 %cmp, i32 %sub, i32 %x
894 %cmp1 = icmp slt i32 %cond, 1
895 %sub9 = sub nsw i32 0, %cond
896 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
900 define i32 @abs_nabs_x14(i32 %x) {
901 ; CHECK-LABEL: @abs_nabs_x14(
902 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
903 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
904 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
905 ; CHECK-NEXT: ret i32 [[COND1]]
907 %cmp = icmp sgt i32 %x, 0
908 %sub = sub nsw i32 0, %x
909 %cond = select i1 %cmp, i32 %sub, i32 %x
910 %cmp1 = icmp slt i32 %cond, 1
911 %sub9 = sub nsw i32 0, %cond
912 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
916 define i32 @abs_nabs_x15(i32 %x) {
917 ; CHECK-LABEL: @abs_nabs_x15(
918 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
919 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
920 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
921 ; CHECK-NEXT: ret i32 [[COND1]]
923 %cmp = icmp slt i32 %x, 0
924 %sub = sub nsw i32 0, %x
925 %cond = select i1 %cmp, i32 %x, i32 %sub
926 %cmp1 = icmp slt i32 %cond, 1
927 %sub9 = sub nsw i32 0, %cond
928 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
932 define i32 @abs_nabs_x16(i32 %x) {
933 ; CHECK-LABEL: @abs_nabs_x16(
934 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
935 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
936 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
937 ; CHECK-NEXT: ret i32 [[COND1]]
939 %cmp = icmp slt i32 %x, 1
940 %sub = sub nsw i32 0, %x
941 %cond = select i1 %cmp, i32 %x, i32 %sub
942 %cmp1 = icmp slt i32 %cond, 1
943 %sub9 = sub nsw i32 0, %cond
944 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
948 ; abs(nabs(-x)) -> abs(-x) -> abs(x)
949 define i32 @abs_nabs_x17(i32 %x) {
950 ; CHECK-LABEL: @abs_nabs_x17(
951 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]]
952 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0
953 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]]
954 ; CHECK-NEXT: ret i32 [[COND]]
956 %sub = sub nsw i32 0, %x
957 %cmp = icmp sgt i32 %sub, -1
958 %cond = select i1 %cmp, i32 %x, i32 %sub
959 %cmp1 = icmp sgt i32 %cond, -1
960 %sub16 = sub nsw i32 0, %cond
961 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
965 ; abs(nabs(x - y)) -> abs(x - y)
966 define i32 @abs_nabs_x18(i32 %x, i32 %y) {
967 ; CHECK-LABEL: @abs_nabs_x18(
968 ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
969 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0
970 ; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]]
971 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[NEGA]], i32 [[A]]
972 ; CHECK-NEXT: ret i32 [[COND]]
974 %a = sub nsw i32 %x, %y
975 %b = sub nsw i32 %y, %x
976 %cmp = icmp sgt i32 %a, -1
977 %cond = select i1 %cmp, i32 %b, i32 %a
978 %cmp1 = icmp sgt i32 %cond, -1
979 %sub16 = sub nsw i32 0, %cond
980 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
984 ; abs(nabs(-x)) -> abs(-x) -> abs(x)
985 define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) {
986 ; CHECK-LABEL: @abs_nabs_x01_vec(
987 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
988 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer
989 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]]
990 ; CHECK-NEXT: ret <2 x i32> [[COND]]
992 %sub = sub nsw <2 x i32> zeroinitializer, %x
993 %cmp = icmp sgt <2 x i32> %sub, <i32 -1, i32 -1>
994 %cond = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %sub
995 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
996 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
997 %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
998 ret <2 x i32> %cond18
1001 ; abs(nabs(x - y)) -> abs(x - y)
1002 define <2 x i32> @abs_nabs_x02_vec(<2 x i32> %x, <2 x i32> %y) {
1003 ; CHECK-LABEL: @abs_nabs_x02_vec(
1004 ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
1005 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer
1006 ; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]]
1007 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NEGA]], <2 x i32> [[A]]
1008 ; CHECK-NEXT: ret <2 x i32> [[COND]]
1010 %a = sub nsw <2 x i32> %x, %y
1011 %b = sub nsw <2 x i32> %y, %x
1012 %cmp = icmp sgt <2 x i32> %a, <i32 -1, i32 -1>
1013 %cond = select <2 x i1> %cmp, <2 x i32> %b, <2 x i32> %a
1014 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
1015 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
1016 %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16
1017 ret <2 x i32> %cond18
1020 define i32 @nabs_abs_x01(i32 %x) {
1021 ; CHECK-LABEL: @nabs_abs_x01(
1022 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1023 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1024 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1025 ; CHECK-NEXT: ret i32 [[COND1]]
1027 %cmp = icmp sgt i32 %x, -1
1028 %sub = sub nsw i32 0, %x
1029 %cond = select i1 %cmp, i32 %x, i32 %sub
1030 %cmp1 = icmp sgt i32 %cond, -1
1031 %sub9 = sub nsw i32 0, %cond
1032 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1036 define i32 @nabs_abs_x02(i32 %x) {
1037 ; CHECK-LABEL: @nabs_abs_x02(
1038 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1039 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1040 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1041 ; CHECK-NEXT: ret i32 [[COND1]]
1043 %cmp = icmp sgt i32 %x, 0
1044 %sub = sub nsw i32 0, %x
1045 %cond = select i1 %cmp, i32 %x, i32 %sub
1046 %cmp1 = icmp sgt i32 %cond, -1
1047 %sub9 = sub nsw i32 0, %cond
1048 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1052 define i32 @nabs_abs_x03(i32 %x) {
1053 ; CHECK-LABEL: @nabs_abs_x03(
1054 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1055 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1056 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1057 ; CHECK-NEXT: ret i32 [[COND1]]
1059 %cmp = icmp slt i32 %x, 0
1060 %sub = sub nsw i32 0, %x
1061 %cond = select i1 %cmp, i32 %sub, i32 %x
1062 %cmp1 = icmp sgt i32 %cond, -1
1063 %sub9 = sub nsw i32 0, %cond
1064 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1068 define i32 @nabs_abs_x04(i32 %x) {
1069 ; CHECK-LABEL: @nabs_abs_x04(
1070 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1071 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1072 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1073 ; CHECK-NEXT: ret i32 [[COND1]]
1075 %cmp = icmp slt i32 %x, 1
1076 %sub = sub nsw i32 0, %x
1077 %cond = select i1 %cmp, i32 %sub, i32 %x
1078 %cmp1 = icmp sgt i32 %cond, -1
1079 %sub9 = sub nsw i32 0, %cond
1080 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1084 define i32 @nabs_abs_x05(i32 %x) {
1085 ; CHECK-LABEL: @nabs_abs_x05(
1086 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1087 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1088 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1089 ; CHECK-NEXT: ret i32 [[COND1]]
1091 %cmp = icmp sgt i32 %x, -1
1092 %sub = sub nsw i32 0, %x
1093 %cond = select i1 %cmp, i32 %x, i32 %sub
1094 %cmp1 = icmp sgt i32 %cond, 0
1095 %sub9 = sub nsw i32 0, %cond
1096 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1100 define i32 @nabs_abs_x06(i32 %x) {
1101 ; CHECK-LABEL: @nabs_abs_x06(
1102 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1103 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1104 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1105 ; CHECK-NEXT: ret i32 [[COND1]]
1107 %cmp = icmp sgt i32 %x, 0
1108 %sub = sub nsw i32 0, %x
1109 %cond = select i1 %cmp, i32 %x, i32 %sub
1110 %cmp1 = icmp sgt i32 %cond, 0
1111 %sub9 = sub nsw i32 0, %cond
1112 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1116 define i32 @nabs_abs_x07(i32 %x) {
1117 ; CHECK-LABEL: @nabs_abs_x07(
1118 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1119 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1120 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1121 ; CHECK-NEXT: ret i32 [[COND1]]
1123 %cmp = icmp slt i32 %x, 0
1124 %sub = sub nsw i32 0, %x
1125 %cond = select i1 %cmp, i32 %sub, i32 %x
1126 %cmp1 = icmp sgt i32 %cond, 0
1127 %sub9 = sub nsw i32 0, %cond
1128 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1132 define i32 @nabs_abs_x08(i32 %x) {
1133 ; CHECK-LABEL: @nabs_abs_x08(
1134 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1135 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1136 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1137 ; CHECK-NEXT: ret i32 [[COND1]]
1139 %cmp = icmp slt i32 %x, 1
1140 %sub = sub nsw i32 0, %x
1141 %cond = select i1 %cmp, i32 %sub, i32 %x
1142 %cmp1 = icmp sgt i32 %cond, 0
1143 %sub9 = sub nsw i32 0, %cond
1144 %cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
1148 define i32 @nabs_abs_x09(i32 %x) {
1149 ; CHECK-LABEL: @nabs_abs_x09(
1150 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1151 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1152 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1153 ; CHECK-NEXT: ret i32 [[COND]]
1155 %cmp = icmp sgt i32 %x, -1
1156 %sub = sub nsw i32 0, %x
1157 %cond = select i1 %cmp, i32 %x, i32 %sub
1158 %cmp1 = icmp slt i32 %cond, 0
1159 %sub16 = sub nsw i32 0, %cond
1160 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1164 define i32 @nabs_abs_x10(i32 %x) {
1165 ; CHECK-LABEL: @nabs_abs_x10(
1166 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1167 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1168 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1169 ; CHECK-NEXT: ret i32 [[COND]]
1171 %cmp = icmp sgt i32 %x, 0
1172 %sub = sub nsw i32 0, %x
1173 %cond = select i1 %cmp, i32 %x, i32 %sub
1174 %cmp1 = icmp slt i32 %cond, 0
1175 %sub16 = sub nsw i32 0, %cond
1176 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1180 define i32 @nabs_abs_x11(i32 %x) {
1181 ; CHECK-LABEL: @nabs_abs_x11(
1182 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1183 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1184 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1185 ; CHECK-NEXT: ret i32 [[COND]]
1187 %cmp = icmp slt i32 %x, 0
1188 %sub = sub nsw i32 0, %x
1189 %cond = select i1 %cmp, i32 %sub, i32 %x
1190 %cmp1 = icmp slt i32 %cond, 0
1191 %sub16 = sub nsw i32 0, %cond
1192 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1196 define i32 @nabs_abs_x12(i32 %x) {
1197 ; CHECK-LABEL: @nabs_abs_x12(
1198 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1199 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1200 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1201 ; CHECK-NEXT: ret i32 [[COND]]
1203 %cmp = icmp slt i32 %x, 1
1204 %sub = sub nsw i32 0, %x
1205 %cond = select i1 %cmp, i32 %sub, i32 %x
1206 %cmp1 = icmp slt i32 %cond, 0
1207 %sub16 = sub nsw i32 0, %cond
1208 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1212 define i32 @nabs_abs_x13(i32 %x) {
1213 ; CHECK-LABEL: @nabs_abs_x13(
1214 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1215 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1216 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1217 ; CHECK-NEXT: ret i32 [[COND1]]
1219 %cmp = icmp sgt i32 %x, -1
1220 %sub = sub nsw i32 0, %x
1221 %cond = select i1 %cmp, i32 %x, i32 %sub
1222 %cmp1 = icmp slt i32 %cond, 1
1223 %sub16 = sub nsw i32 0, %cond
1224 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1228 define i32 @nabs_abs_x14(i32 %x) {
1229 ; CHECK-LABEL: @nabs_abs_x14(
1230 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1231 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1232 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1233 ; CHECK-NEXT: ret i32 [[COND1]]
1235 %cmp = icmp sgt i32 %x, 0
1236 %sub = sub nsw i32 0, %x
1237 %cond = select i1 %cmp, i32 %x, i32 %sub
1238 %cmp1 = icmp slt i32 %cond, 1
1239 %sub16 = sub nsw i32 0, %cond
1240 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1244 define i32 @nabs_abs_x15(i32 %x) {
1245 ; CHECK-LABEL: @nabs_abs_x15(
1246 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1247 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1248 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1249 ; CHECK-NEXT: ret i32 [[COND1]]
1251 %cmp = icmp slt i32 %x, 0
1252 %sub = sub nsw i32 0, %x
1253 %cond = select i1 %cmp, i32 %sub, i32 %x
1254 %cmp1 = icmp slt i32 %cond, 1
1255 %sub16 = sub nsw i32 0, %cond
1256 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1260 define i32 @nabs_abs_x16(i32 %x) {
1261 ; CHECK-LABEL: @nabs_abs_x16(
1262 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1263 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]]
1264 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1265 ; CHECK-NEXT: ret i32 [[COND1]]
1267 %cmp = icmp slt i32 %x, 1
1268 %sub = sub nsw i32 0, %x
1269 %cond = select i1 %cmp, i32 %sub, i32 %x
1270 %cmp1 = icmp slt i32 %cond, 1
1271 %sub16 = sub nsw i32 0, %cond
1272 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
1276 ; nabs(abs(-x)) -> nabs(-x) -> nabs(x)
1277 define i32 @nabs_abs_x17(i32 %x) {
1278 ; CHECK-LABEL: @nabs_abs_x17(
1279 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]]
1280 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0
1281 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]]
1282 ; CHECK-NEXT: ret i32 [[COND]]
1284 %sub = sub nsw i32 0, %x
1285 %cmp = icmp sgt i32 %sub, -1
1286 %cond = select i1 %cmp, i32 %sub, i32 %x
1287 %cmp1 = icmp sgt i32 %cond, -1
1288 %sub16 = sub nsw i32 0, %cond
1289 %cond18 = select i1 %cmp1, i32 %sub16, i32 %cond
1293 ; nabs(abs(x - y)) -> nabs(x - y)
1294 define i32 @nabs_abs_x18(i32 %x, i32 %y) {
1295 ; CHECK-LABEL: @nabs_abs_x18(
1296 ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
1297 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0
1298 ; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]]
1299 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[NEGA]]
1300 ; CHECK-NEXT: ret i32 [[COND]]
1302 %a = sub nsw i32 %x, %y
1303 %b = sub nsw i32 %y, %x
1304 %cmp = icmp sgt i32 %a, -1
1305 %cond = select i1 %cmp, i32 %a, i32 %b
1306 %cmp1 = icmp sgt i32 %cond, -1
1307 %sub16 = sub nsw i32 0, %cond
1308 %cond18 = select i1 %cmp1, i32 %sub16, i32 %cond
1312 ; nabs(abs(-x)) -> nabs(-x) -> nabs(x)
1313 define <2 x i32> @nabs_abs_x01_vec(<2 x i32> %x) {
1314 ; CHECK-LABEL: @nabs_abs_x01_vec(
1315 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
1316 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer
1317 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]]
1318 ; CHECK-NEXT: ret <2 x i32> [[COND]]
1320 %sub = sub nsw <2 x i32> zeroinitializer, %x
1321 %cmp = icmp sgt <2 x i32> %sub, <i32 -1, i32 -1>
1322 %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x
1323 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
1324 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
1325 %cond18 = select <2 x i1> %cmp1, <2 x i32> %sub16, <2 x i32> %cond
1326 ret <2 x i32> %cond18
1329 ; nabs(abs(x - y)) -> nabs(x - y)
1330 define <2 x i32> @nabs_abs_x02_vec(<2 x i32> %x, <2 x i32> %y) {
1331 ; CHECK-LABEL: @nabs_abs_x02_vec(
1332 ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
1333 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer
1334 ; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]]
1335 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[A]], <2 x i32> [[NEGA]]
1336 ; CHECK-NEXT: ret <2 x i32> [[COND]]
1338 %a = sub nsw <2 x i32> %x, %y
1339 %b = sub nsw <2 x i32> %y, %x
1340 %cmp = icmp sgt <2 x i32> %a, <i32 -1, i32 -1>
1341 %cond = select <2 x i1> %cmp, <2 x i32> %a, <2 x i32> %b
1342 %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
1343 %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
1344 %cond18 = select <2 x i1> %cmp1, <2 x i32> %sub16, <2 x i32> %cond
1345 ret <2 x i32> %cond18