1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-p1:16:16:16-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"
6 define i32 @sub_constant(i32 %x) {
7 ; CHECK-LABEL: @sub_constant(
8 ; CHECK-NEXT: [[R:%.*]] = add i32 [[X:%.*]], -42
9 ; CHECK-NEXT: ret i32 [[R]]
17 define i32 @sub_constant_expression(i32 %x) {
18 ; CHECK-LABEL: @sub_constant_expression(
19 ; CHECK-NEXT: [[R:%.*]] = sub i32 [[X:%.*]], ptrtoint (i32* @g to i32)
20 ; CHECK-NEXT: ret i32 [[R]]
22 %r = sub i32 %x, ptrtoint (i32* @g to i32)
26 define <2 x i32> @sub_constant_vec(<2 x i32> %x) {
27 ; CHECK-LABEL: @sub_constant_vec(
28 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[X:%.*]], <i32 -42, i32 12>
29 ; CHECK-NEXT: ret <2 x i32> [[R]]
31 %r = sub <2 x i32> %x, <i32 42, i32 -12>
35 define <3 x i33> @sub_constant_vec_weird_type(<3 x i33> %x) {
36 ; CHECK-LABEL: @sub_constant_vec_weird_type(
37 ; CHECK-NEXT: [[R:%.*]] = add <3 x i33> [[X:%.*]], <i33 42, i33 -42, i33 12>
38 ; CHECK-NEXT: ret <3 x i33> [[R]]
40 %r = sub <3 x i33> %x, <i33 -42, i33 42, i33 -12>
44 define <4 x i32> @sub_constant_expression_vec(<4 x i32> %x) {
45 ; CHECK-LABEL: @sub_constant_expression_vec(
46 ; CHECK-NEXT: [[R:%.*]] = sub <4 x i32> [[X:%.*]], bitcast (i128 ptrtoint (i32* @g to i128) to <4 x i32>)
47 ; CHECK-NEXT: ret <4 x i32> [[R]]
49 %r = sub <4 x i32> %x, bitcast (i128 ptrtoint (i32* @g to i128) to <4 x i32>)
53 define i32 @neg_sub(i32 %x, i32 %y) {
54 ; CHECK-LABEL: @neg_sub(
55 ; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
56 ; CHECK-NEXT: ret i32 [[R]]
63 define i32 @neg_nsw_sub(i32 %x, i32 %y) {
64 ; CHECK-LABEL: @neg_nsw_sub(
65 ; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
66 ; CHECK-NEXT: ret i32 [[R]]
68 %neg = sub nsw i32 0, %x
73 define i32 @neg_sub_nsw(i32 %x, i32 %y) {
74 ; CHECK-LABEL: @neg_sub_nsw(
75 ; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
76 ; CHECK-NEXT: ret i32 [[R]]
79 %r = sub nsw i32 %y, %neg
83 define i32 @neg_nsw_sub_nsw(i32 %x, i32 %y) {
84 ; CHECK-LABEL: @neg_nsw_sub_nsw(
85 ; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[Y:%.*]], [[X:%.*]]
86 ; CHECK-NEXT: ret i32 [[R]]
88 %neg = sub nsw i32 0, %x
89 %r = sub nsw i32 %y, %neg
93 define <2 x i32> @neg_sub_vec(<2 x i32> %x, <2 x i32> %y) {
94 ; CHECK-LABEL: @neg_sub_vec(
95 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
96 ; CHECK-NEXT: ret <2 x i32> [[R]]
98 %neg = sub <2 x i32> zeroinitializer, %x
99 %r = sub <2 x i32> %y, %neg
103 define <2 x i32> @neg_nsw_sub_vec(<2 x i32> %x, <2 x i32> %y) {
104 ; CHECK-LABEL: @neg_nsw_sub_vec(
105 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
106 ; CHECK-NEXT: ret <2 x i32> [[R]]
108 %neg = sub nsw <2 x i32> zeroinitializer, %x
109 %r = sub <2 x i32> %y, %neg
113 define <2 x i32> @neg_sub_nsw_vec(<2 x i32> %x, <2 x i32> %y) {
114 ; CHECK-LABEL: @neg_sub_nsw_vec(
115 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
116 ; CHECK-NEXT: ret <2 x i32> [[R]]
118 %neg = sub <2 x i32> zeroinitializer, %x
119 %r = sub nsw <2 x i32> %y, %neg
123 define <2 x i32> @neg_nsw_sub_nsw_vec(<2 x i32> %x, <2 x i32> %y) {
124 ; CHECK-LABEL: @neg_nsw_sub_nsw_vec(
125 ; CHECK-NEXT: [[R:%.*]] = add nsw <2 x i32> [[Y:%.*]], [[X:%.*]]
126 ; CHECK-NEXT: ret <2 x i32> [[R]]
128 %neg = sub nsw <2 x i32> zeroinitializer, %x
129 %r = sub nsw <2 x i32> %y, %neg
133 define <2 x i32> @neg_sub_vec_undef(<2 x i32> %x, <2 x i32> %y) {
134 ; CHECK-LABEL: @neg_sub_vec_undef(
135 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
136 ; CHECK-NEXT: ret <2 x i32> [[R]]
138 %neg = sub <2 x i32> <i32 0, i32 undef>, %x
139 %r = sub <2 x i32> %y, %neg
143 define <2 x i32> @neg_nsw_sub_vec_undef(<2 x i32> %x, <2 x i32> %y) {
144 ; CHECK-LABEL: @neg_nsw_sub_vec_undef(
145 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
146 ; CHECK-NEXT: ret <2 x i32> [[R]]
148 %neg = sub nsw <2 x i32> <i32 undef, i32 0>, %x
149 %r = sub <2 x i32> %y, %neg
153 define <2 x i32> @neg_sub_nsw_vec_undef(<2 x i32> %x, <2 x i32> %y) {
154 ; CHECK-LABEL: @neg_sub_nsw_vec_undef(
155 ; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
156 ; CHECK-NEXT: ret <2 x i32> [[R]]
158 %neg = sub <2 x i32> <i32 undef, i32 0>, %x
159 %r = sub nsw <2 x i32> %y, %neg
163 ; This should not drop 'nsw'.
165 define <2 x i32> @neg_nsw_sub_nsw_vec_undef(<2 x i32> %x, <2 x i32> %y) {
166 ; CHECK-LABEL: @neg_nsw_sub_nsw_vec_undef(
167 ; CHECK-NEXT: [[R:%.*]] = add nsw <2 x i32> [[Y:%.*]], [[X:%.*]]
168 ; CHECK-NEXT: ret <2 x i32> [[R]]
170 %neg = sub nsw <2 x i32> <i32 0, i32 undef>, %x
171 %r = sub nsw <2 x i32> %y, %neg
175 ; (~X) - (~Y) --> Y - X
176 ; Also, show that we can handle extra uses and vectors.
178 declare void @use8(i8)
180 define i8 @notnotsub(i8 %x, i8 %y) {
181 ; CHECK-LABEL: @notnotsub(
182 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
183 ; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
184 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[Y]], [[X]]
185 ; CHECK-NEXT: call void @use8(i8 [[NX]])
186 ; CHECK-NEXT: call void @use8(i8 [[NY]])
187 ; CHECK-NEXT: ret i8 [[SUB]]
191 %sub = sub i8 %nx, %ny
192 call void @use8(i8 %nx)
193 call void @use8(i8 %ny)
197 define <2 x i8> @notnotsub_vec(<2 x i8> %x, <2 x i8> %y) {
198 ; CHECK-LABEL: @notnotsub_vec(
199 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[Y:%.*]], [[X:%.*]]
200 ; CHECK-NEXT: ret <2 x i8> [[SUB]]
202 %nx = xor <2 x i8> %x, <i8 -1, i8 -1>
203 %ny = xor <2 x i8> %y, <i8 -1, i8 -1>
204 %sub = sub <2 x i8> %nx, %ny
208 define <2 x i8> @notnotsub_vec_undef_elts(<2 x i8> %x, <2 x i8> %y) {
209 ; CHECK-LABEL: @notnotsub_vec_undef_elts(
210 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[Y:%.*]], [[X:%.*]]
211 ; CHECK-NEXT: ret <2 x i8> [[SUB]]
213 %nx = xor <2 x i8> %x, <i8 undef, i8 -1>
214 %ny = xor <2 x i8> %y, <i8 -1, i8 undef>
215 %sub = sub <2 x i8> %nx, %ny
219 define i32 @test5(i32 %A, i32 %B, i32 %C) {
220 ; CHECK-LABEL: @test5(
221 ; CHECK-NEXT: [[D_NEG:%.*]] = sub i32 [[C:%.*]], [[B:%.*]]
222 ; CHECK-NEXT: [[E:%.*]] = add i32 [[D_NEG]], [[A:%.*]]
223 ; CHECK-NEXT: ret i32 [[E]]
230 define i32 @test6(i32 %A, i32 %B) {
231 ; CHECK-LABEL: @test6(
232 ; CHECK-NEXT: [[B_NOT:%.*]] = xor i32 [[B:%.*]], -1
233 ; CHECK-NEXT: [[D:%.*]] = and i32 [[B_NOT]], [[A:%.*]]
234 ; CHECK-NEXT: ret i32 [[D]]
241 define i32 @test6commuted(i32 %A, i32 %B) {
242 ; CHECK-LABEL: @test6commuted(
243 ; CHECK-NEXT: [[B_NOT:%.*]] = xor i32 [[B:%.*]], -1
244 ; CHECK-NEXT: [[D:%.*]] = and i32 [[B_NOT]], [[A:%.*]]
245 ; CHECK-NEXT: ret i32 [[D]]
252 define i32 @test7(i32 %A) {
253 ; CHECK-LABEL: @test7(
254 ; CHECK-NEXT: [[B:%.*]] = xor i32 [[A:%.*]], -1
255 ; CHECK-NEXT: ret i32 [[B]]
261 define i32 @test8(i32 %A) {
262 ; CHECK-LABEL: @test8(
263 ; CHECK-NEXT: [[C:%.*]] = shl i32 [[A:%.*]], 3
264 ; CHECK-NEXT: ret i32 [[C]]
271 define i32 @test9(i32 %A) {
272 ; CHECK-LABEL: @test9(
273 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], -2
274 ; CHECK-NEXT: ret i32 [[C]]
281 define i1 @test11(i8 %A, i8 %B) {
282 ; CHECK-LABEL: @test11(
283 ; CHECK-NEXT: [[D:%.*]] = icmp ne i8 [[A:%.*]], [[B:%.*]]
284 ; CHECK-NEXT: ret i1 [[D]]
287 %D = icmp ne i8 %C, 0
291 define <2 x i1> @test11vec(<2 x i8> %A, <2 x i8> %B) {
292 ; CHECK-LABEL: @test11vec(
293 ; CHECK-NEXT: [[D:%.*]] = icmp ne <2 x i8> [[A:%.*]], [[B:%.*]]
294 ; CHECK-NEXT: ret <2 x i1> [[D]]
296 %C = sub <2 x i8> %A, %B
297 %D = icmp ne <2 x i8> %C, zeroinitializer
301 define i32 @test12(i32 %A) {
302 ; CHECK-LABEL: @test12(
303 ; CHECK-NEXT: [[B_NEG:%.*]] = lshr i32 [[A:%.*]], 31
304 ; CHECK-NEXT: ret i32 [[B_NEG]]
311 define i32 @test13(i32 %A) {
312 ; CHECK-LABEL: @test13(
313 ; CHECK-NEXT: [[B_NEG:%.*]] = ashr i32 [[A:%.*]], 31
314 ; CHECK-NEXT: ret i32 [[B_NEG]]
321 define <2 x i32> @test12vec(<2 x i32> %A) {
322 ; CHECK-LABEL: @test12vec(
323 ; CHECK-NEXT: [[B_NEG:%.*]] = lshr <2 x i32> [[A:%.*]], <i32 31, i32 31>
324 ; CHECK-NEXT: ret <2 x i32> [[B_NEG]]
326 %B = ashr <2 x i32> %A, <i32 31, i32 31>
327 %C = sub <2 x i32> zeroinitializer, %B
331 define <2 x i32> @test13vec(<2 x i32> %A) {
332 ; CHECK-LABEL: @test13vec(
333 ; CHECK-NEXT: [[B_NEG:%.*]] = ashr <2 x i32> [[A:%.*]], <i32 31, i32 31>
334 ; CHECK-NEXT: ret <2 x i32> [[B_NEG]]
336 %B = lshr <2 x i32> %A, <i32 31, i32 31>
337 %C = sub <2 x i32> zeroinitializer, %B
341 define i32 @test15(i32 %A, i32 %B) {
342 ; CHECK-LABEL: @test15(
343 ; CHECK-NEXT: [[C:%.*]] = sub i32 0, [[A:%.*]]
344 ; CHECK-NEXT: [[D:%.*]] = srem i32 [[B:%.*]], [[C]]
345 ; CHECK-NEXT: ret i32 [[D]]
352 define i32 @test16(i32 %A) {
353 ; CHECK-LABEL: @test16(
354 ; CHECK-NEXT: [[X_NEG:%.*]] = sdiv i32 [[A:%.*]], -1123
355 ; CHECK-NEXT: ret i32 [[X_NEG]]
357 %X = sdiv i32 %A, 1123
362 ; Can't fold subtract here because negation it might oveflow.
364 define i32 @test17(i32 %A) {
365 ; CHECK-LABEL: @test17(
366 ; CHECK-NEXT: [[B:%.*]] = sub i32 0, [[A:%.*]]
367 ; CHECK-NEXT: [[C:%.*]] = sdiv i32 [[B]], 1234
368 ; CHECK-NEXT: ret i32 [[C]]
371 %C = sdiv i32 %B, 1234
375 define i64 @test18(i64 %Y) {
376 ; CHECK-LABEL: @test18(
377 ; CHECK-NEXT: ret i64 0
380 %i.12 = shl i64 %Y, 2
381 %i.8 = sub i64 %i.4, %i.12
385 define i1 @test20(i32 %g, i32 %h) {
386 ; CHECK-LABEL: @test20(
387 ; CHECK-NEXT: [[I_4:%.*]] = icmp ne i32 [[H:%.*]], 0
388 ; CHECK-NEXT: ret i1 [[I_4]]
390 %i.2 = sub i32 %g, %h
391 %i.4 = icmp ne i32 %i.2, %g
395 define i1 @test21(i32 %g, i32 %h) {
396 ; CHECK-LABEL: @test21(
397 ; CHECK-NEXT: [[I_4:%.*]] = icmp ne i32 [[H:%.*]], 0
398 ; CHECK-NEXT: ret i1 [[I_4]]
400 %i.2 = sub i32 %g, %h
401 %i.4 = icmp ne i32 %i.2, %g
406 define zeroext i1 @test22(i32 %a, i32 %b) nounwind {
407 ; CHECK-LABEL: @test22(
408 ; CHECK-NEXT: [[I5:%.*]] = icmp eq i32 [[B:%.*]], [[A:%.*]]
409 ; CHECK-NEXT: ret i1 [[I5]]
413 %i5 = icmp eq i32 %i2, %i4
417 define i32 @test26(i32 %x) {
418 ; CHECK-LABEL: @test26(
419 ; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i32 -3, [[X:%.*]]
420 ; CHECK-NEXT: ret i32 [[SHL_NEG]]
423 %neg = sub i32 0, %shl
427 define i64 @test_neg_shl_sub(i64 %a, i64 %b) {
428 ; CHECK-LABEL: @test_neg_shl_sub(
429 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i64 [[B:%.*]], [[A:%.*]]
430 ; CHECK-NEXT: [[MUL_NEG:%.*]] = shl i64 [[SUB_NEG]], 2
431 ; CHECK-NEXT: ret i64 [[MUL_NEG]]
433 %sub = sub i64 %a, %b
434 %mul = shl i64 %sub, 2
435 %neg = sub i64 0, %mul
439 define i64 @test_neg_shl_sub_extra_use1(i64 %a, i64 %b, i64* %p) {
440 ; CHECK-LABEL: @test_neg_shl_sub_extra_use1(
441 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[A:%.*]], [[B:%.*]]
442 ; CHECK-NEXT: store i64 [[SUB]], i64* [[P:%.*]], align 8
443 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul i64 [[SUB]], -4
444 ; CHECK-NEXT: ret i64 [[MUL_NEG]]
446 %sub = sub i64 %a, %b
447 store i64 %sub, i64* %p
448 %mul = shl i64 %sub, 2
449 %neg = sub i64 0, %mul
453 define i64 @test_neg_shl_sub_extra_use2(i64 %a, i64 %b, i64* %p) {
454 ; CHECK-LABEL: @test_neg_shl_sub_extra_use2(
455 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[A:%.*]], [[B:%.*]]
456 ; CHECK-NEXT: [[MUL:%.*]] = shl i64 [[SUB]], 2
457 ; CHECK-NEXT: store i64 [[MUL]], i64* [[P:%.*]], align 8
458 ; CHECK-NEXT: [[NEG:%.*]] = sub i64 0, [[MUL]]
459 ; CHECK-NEXT: ret i64 [[NEG]]
461 %sub = sub i64 %a, %b
462 %mul = shl i64 %sub, 2
463 store i64 %mul, i64* %p
464 %neg = sub i64 0, %mul
468 define i64 @test_neg_shl_div(i64 %a) {
469 ; CHECK-LABEL: @test_neg_shl_div(
470 ; CHECK-NEXT: [[DIV_NEG:%.*]] = sdiv i64 [[A:%.*]], -3
471 ; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i64 [[DIV_NEG]], 2
472 ; CHECK-NEXT: ret i64 [[SHL_NEG]]
474 %div = sdiv i64 %a, 3
475 %shl = shl i64 %div, 2
476 %neg = sub i64 0, %shl
480 define i64 @test_neg_shl_zext_i1(i1 %a, i64 %b) {
481 ; CHECK-LABEL: @test_neg_shl_zext_i1(
482 ; CHECK-NEXT: [[EXT_NEG:%.*]] = sext i1 [[A:%.*]] to i64
483 ; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i64 [[EXT_NEG]], [[B:%.*]]
484 ; CHECK-NEXT: ret i64 [[SHL_NEG]]
486 %ext = zext i1 %a to i64
487 %shl = shl i64 %ext, %b
488 %neg = sub i64 0, %shl
492 define i64 @test_neg_shl_sext_i1(i1 %a, i64 %b) {
493 ; CHECK-LABEL: @test_neg_shl_sext_i1(
494 ; CHECK-NEXT: [[EXT_NEG:%.*]] = zext i1 [[A:%.*]] to i64
495 ; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i64 [[EXT_NEG]], [[B:%.*]]
496 ; CHECK-NEXT: ret i64 [[SHL_NEG]]
498 %ext = sext i1 %a to i64
499 %shl = shl i64 %ext, %b
500 %neg = sub i64 0, %shl
504 define i64 @test_neg_zext_i1_extra_use(i1 %a, i64 %b, i64* %p) {
505 ; CHECK-LABEL: @test_neg_zext_i1_extra_use(
506 ; CHECK-NEXT: [[EXT_NEG:%.*]] = sext i1 [[A:%.*]] to i64
507 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[A]] to i64
508 ; CHECK-NEXT: store i64 [[EXT]], i64* [[P:%.*]], align 8
509 ; CHECK-NEXT: ret i64 [[EXT_NEG]]
511 %ext = zext i1 %a to i64
512 %neg = sub i64 0, %ext
513 store i64 %ext, i64* %p
517 define i64 @test_neg_sext_i1_extra_use(i1 %a, i64 %b, i64* %p) {
518 ; CHECK-LABEL: @test_neg_sext_i1_extra_use(
519 ; CHECK-NEXT: [[EXT_NEG:%.*]] = zext i1 [[A:%.*]] to i64
520 ; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[A]] to i64
521 ; CHECK-NEXT: store i64 [[EXT]], i64* [[P:%.*]], align 8
522 ; CHECK-NEXT: ret i64 [[EXT_NEG]]
524 %ext = sext i1 %a to i64
525 %neg = sub i64 0, %ext
526 store i64 %ext, i64* %p
530 define i32 @test_neg_trunc_shl_sub(i64 %a, i64 %b) {
531 ; CHECK-LABEL: @test_neg_trunc_shl_sub(
532 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i64 [[B:%.*]], [[A:%.*]]
533 ; CHECK-NEXT: [[SUB_TR_NEG:%.*]] = trunc i64 [[SUB_NEG]] to i32
534 ; CHECK-NEXT: [[TRUNC_NEG:%.*]] = shl i32 [[SUB_TR_NEG]], 2
535 ; CHECK-NEXT: ret i32 [[TRUNC_NEG]]
537 %sub = sub i64 %a, %b
538 %shl = shl i64 %sub, 2
539 %trunc = trunc i64 %shl to i32
540 %neg = sub i32 0, %trunc
544 define i32 @test_neg_trunc_shl_ashr(i64 %a, i64 %b) {
545 ; CHECK-LABEL: @test_neg_trunc_shl_ashr(
546 ; CHECK-NEXT: [[SHR_NEG:%.*]] = lshr i64 [[A:%.*]], 63
547 ; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i64 [[SHR_NEG]], [[B:%.*]]
548 ; CHECK-NEXT: [[TRUNC_NEG:%.*]] = trunc i64 [[SHL_NEG]] to i32
549 ; CHECK-NEXT: ret i32 [[TRUNC_NEG]]
551 %shr = ashr i64 %a, 63
552 %shl = shl i64 %shr, %b
553 %trunc = trunc i64 %shl to i32
554 %neg = sub i32 0, %trunc
558 define i32 @test_neg_trunc_shl_lshr(i64 %a, i64 %b) {
559 ; CHECK-LABEL: @test_neg_trunc_shl_lshr(
560 ; CHECK-NEXT: [[SHR_NEG:%.*]] = ashr i64 [[A:%.*]], 63
561 ; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i64 [[SHR_NEG]], [[B:%.*]]
562 ; CHECK-NEXT: [[TRUNC_NEG:%.*]] = trunc i64 [[SHL_NEG]] to i32
563 ; CHECK-NEXT: ret i32 [[TRUNC_NEG]]
565 %shr = lshr i64 %a, 63
566 %shl = shl i64 %shr, %b
567 %trunc = trunc i64 %shl to i32
568 %neg = sub i32 0, %trunc
572 define i64 @test_neg_mul_sub(i64 %a, i64 %b, i64 %c) {
573 ; CHECK-LABEL: @test_neg_mul_sub(
574 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i64 [[B:%.*]], [[A:%.*]]
575 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul i64 [[SUB_NEG]], [[C:%.*]]
576 ; CHECK-NEXT: ret i64 [[MUL_NEG]]
578 %sub = sub i64 %a, %b
579 %mul = mul i64 %sub, %c
580 %neg = sub i64 0, %mul
584 define i64 @test_neg_mul_sub_commuted(i64 %a, i64 %b, i64 %c) {
585 ; CHECK-LABEL: @test_neg_mul_sub_commuted(
586 ; CHECK-NEXT: [[COMPLEX:%.*]] = mul i64 [[C:%.*]], [[C]]
587 ; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i64 [[B:%.*]], [[A:%.*]]
588 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul i64 [[SUB_NEG]], [[COMPLEX]]
589 ; CHECK-NEXT: ret i64 [[MUL_NEG]]
591 %complex = mul i64 %c, %c
592 %sub = sub i64 %a, %b
593 %mul = mul i64 %complex, %sub
594 %neg = sub i64 0, %mul
598 define i32 @test27(i32 %x, i32 %y) {
599 ; CHECK-LABEL: @test27(
600 ; CHECK-NEXT: [[MUL_NEG:%.*]] = shl i32 [[Y:%.*]], 3
601 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[MUL_NEG]], [[X:%.*]]
602 ; CHECK-NEXT: ret i32 [[SUB]]
604 %mul = mul i32 %y, -8
605 %sub = sub i32 %x, %mul
609 define <2 x i32> @test27vec(<2 x i32> %x, <2 x i32> %y) {
610 ; CHECK-LABEL: @test27vec(
611 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul <2 x i32> [[Y:%.*]], <i32 8, i32 6>
612 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i32> [[MUL_NEG]], [[X:%.*]]
613 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
615 %mul = mul <2 x i32> %y, <i32 -8, i32 -6>
616 %sub = sub <2 x i32> %x, %mul
620 define <2 x i32> @test27vecsplat(<2 x i32> %x, <2 x i32> %y) {
621 ; CHECK-LABEL: @test27vecsplat(
622 ; CHECK-NEXT: [[MUL_NEG:%.*]] = shl <2 x i32> [[Y:%.*]], <i32 3, i32 3>
623 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i32> [[MUL_NEG]], [[X:%.*]]
624 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
626 %mul = mul <2 x i32> %y, <i32 -8, i32 -8>
627 %sub = sub <2 x i32> %x, %mul
631 define <2 x i32> @test27vecmixed(<2 x i32> %x, <2 x i32> %y) {
632 ; CHECK-LABEL: @test27vecmixed(
633 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul <2 x i32> [[Y:%.*]], <i32 8, i32 -8>
634 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i32> [[MUL_NEG]], [[X:%.*]]
635 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
637 %mul = mul <2 x i32> %y, <i32 -8, i32 8>
638 %sub = sub <2 x i32> %x, %mul
642 define i32 @test27commuted(i32 %x, i32 %y) {
643 ; CHECK-LABEL: @test27commuted(
644 ; CHECK-NEXT: [[MUL_NEG:%.*]] = shl i32 [[Y:%.*]], 3
645 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[MUL_NEG]], [[X:%.*]]
646 ; CHECK-NEXT: ret i32 [[SUB]]
648 %mul = mul i32 -8, %y
649 %sub = sub i32 %x, %mul
653 define <2 x i32> @test27commutedvec(<2 x i32> %x, <2 x i32> %y) {
654 ; CHECK-LABEL: @test27commutedvec(
655 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul <2 x i32> [[Y:%.*]], <i32 8, i32 6>
656 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i32> [[MUL_NEG]], [[X:%.*]]
657 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
659 %mul = mul <2 x i32> <i32 -8, i32 -6>, %y
660 %sub = sub <2 x i32> %x, %mul
664 define <2 x i32> @test27commutedvecsplat(<2 x i32> %x, <2 x i32> %y) {
665 ; CHECK-LABEL: @test27commutedvecsplat(
666 ; CHECK-NEXT: [[MUL_NEG:%.*]] = shl <2 x i32> [[Y:%.*]], <i32 3, i32 3>
667 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i32> [[MUL_NEG]], [[X:%.*]]
668 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
670 %mul = mul <2 x i32> <i32 -8, i32 -8>, %y
671 %sub = sub <2 x i32> %x, %mul
675 define <2 x i32> @test27commutedvecmixed(<2 x i32> %x, <2 x i32> %y) {
676 ; CHECK-LABEL: @test27commutedvecmixed(
677 ; CHECK-NEXT: [[MUL_NEG:%.*]] = mul <2 x i32> [[Y:%.*]], <i32 8, i32 -8>
678 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i32> [[MUL_NEG]], [[X:%.*]]
679 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
681 %mul = mul <2 x i32> <i32 -8, i32 8>, %y
682 %sub = sub <2 x i32> %x, %mul
686 define i32 @test28(i32 %x, i32 %y, i32 %z) {
687 ; CHECK-LABEL: @test28(
688 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[Z:%.*]], [[Y:%.*]]
689 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[TMP1]], [[X:%.*]]
690 ; CHECK-NEXT: ret i32 [[SUB]]
693 %mul = mul i32 %neg, %y
694 %sub = sub i32 %x, %mul
698 define i32 @test28commuted(i32 %x, i32 %y, i32 %z) {
699 ; CHECK-LABEL: @test28commuted(
700 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[Z:%.*]], [[Y:%.*]]
701 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[TMP1]], [[X:%.*]]
702 ; CHECK-NEXT: ret i32 [[SUB]]
705 %mul = mul i32 %y, %neg
706 %sub = sub i32 %x, %mul
710 define <2 x i64> @test31(<2 x i64> %A) {
711 ; CHECK-LABEL: @test31(
712 ; CHECK-NEXT: [[SUB:%.*]] = add <2 x i64> [[A:%.*]], <i64 3, i64 4>
713 ; CHECK-NEXT: ret <2 x i64> [[SUB]]
715 %xor = xor <2 x i64> %A, <i64 -1, i64 -1>
716 %sub = sub <2 x i64> <i64 2, i64 3>, %xor
720 define <2 x i64> @test32(<2 x i64> %A) {
721 ; CHECK-LABEL: @test32(
722 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i64> <i64 3, i64 4>, [[A:%.*]]
723 ; CHECK-NEXT: ret <2 x i64> [[SUB]]
725 %add = add <2 x i64> %A, <i64 -1, i64 -1>
726 %sub = sub <2 x i64> <i64 2, i64 3>, %add
730 define <2 x i64> @test35(<2 x i64> %A) {
731 ; CHECK-LABEL: @test35(
732 ; CHECK-NEXT: [[SUB:%.*]] = mul <2 x i64> [[A:%.*]], <i64 -2, i64 -3>
733 ; CHECK-NEXT: ret <2 x i64> [[SUB]]
735 %mul = mul <2 x i64> %A, <i64 3, i64 4>
736 %sub = sub <2 x i64> %A, %mul
740 define <2 x i64> @test36(<2 x i64> %A) {
741 ; CHECK-LABEL: @test36(
742 ; CHECK-NEXT: [[SUB:%.*]] = mul <2 x i64> [[A:%.*]], <i64 7, i64 15>
743 ; CHECK-NEXT: ret <2 x i64> [[SUB]]
745 %shl = shl <2 x i64> %A, <i64 3, i64 4>
746 %sub = sub <2 x i64> %shl, %A
750 define <2 x i32> @test37(<2 x i32> %A) {
751 ; CHECK-LABEL: @test37(
752 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i32> [[A:%.*]], <i32 -2147483648, i32 -2147483648>
753 ; CHECK-NEXT: [[DIV_NEG:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i32>
754 ; CHECK-NEXT: ret <2 x i32> [[DIV_NEG]]
756 %div = sdiv <2 x i32> %A, <i32 -2147483648, i32 -2147483648>
757 %sub = sub nsw <2 x i32> zeroinitializer, %div
761 define i32 @test38(i32 %A) {
762 ; CHECK-LABEL: @test38(
763 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[A:%.*]], -2147483648
764 ; CHECK-NEXT: [[DIV_NEG:%.*]] = sext i1 [[TMP1]] to i32
765 ; CHECK-NEXT: ret i32 [[DIV_NEG]]
767 %div = sdiv i32 %A, -2147483648
768 %sub = sub nsw i32 0, %div
772 define i16 @test40(i16 %a, i16 %b) {
773 ; CHECK-LABEL: @test40(
774 ; CHECK-NEXT: [[ASHR:%.*]] = ashr i16 [[A:%.*]], 1
775 ; CHECK-NEXT: [[ASHR1:%.*]] = ashr i16 [[B:%.*]], 1
776 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i16 [[ASHR]], [[ASHR1]]
777 ; CHECK-NEXT: ret i16 [[SUB]]
779 %ashr = ashr i16 %a, 1
780 %ashr1 = ashr i16 %b, 1
781 %sub = sub i16 %ashr, %ashr1
785 define i32 @test41(i16 %a, i16 %b) {
786 ; CHECK-LABEL: @test41(
787 ; CHECK-NEXT: [[CONV:%.*]] = sext i16 [[A:%.*]] to i32
788 ; CHECK-NEXT: [[CONV1:%.*]] = sext i16 [[B:%.*]] to i32
789 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[CONV]], [[CONV1]]
790 ; CHECK-NEXT: ret i32 [[SUB]]
792 %conv = sext i16 %a to i32
793 %conv1 = sext i16 %b to i32
794 %sub = sub i32 %conv, %conv1
798 define i4 @test42(i4 %x, i4 %y) {
799 ; CHECK-LABEL: @test42(
800 ; CHECK-NEXT: [[A:%.*]] = and i4 [[Y:%.*]], 7
801 ; CHECK-NEXT: [[B:%.*]] = and i4 [[X:%.*]], 7
802 ; CHECK-NEXT: [[C:%.*]] = sub nsw i4 [[A]], [[B]]
803 ; CHECK-NEXT: ret i4 [[C]]
811 define i4 @test43(i4 %x, i4 %y) {
812 ; CHECK-LABEL: @test43(
813 ; CHECK-NEXT: [[A:%.*]] = or i4 [[X:%.*]], -8
814 ; CHECK-NEXT: [[B:%.*]] = and i4 [[Y:%.*]], 7
815 ; CHECK-NEXT: [[C:%.*]] = sub nuw i4 [[A]], [[B]]
816 ; CHECK-NEXT: ret i4 [[C]]
824 define i32 @test44(i32 %x) {
825 ; CHECK-LABEL: @test44(
826 ; CHECK-NEXT: [[SUB:%.*]] = add nsw i32 [[X:%.*]], -32768
827 ; CHECK-NEXT: ret i32 [[SUB]]
829 %sub = sub nsw i32 %x, 32768
833 define <2 x i32> @test44vec(<2 x i32> %x) {
834 ; CHECK-LABEL: @test44vec(
835 ; CHECK-NEXT: [[SUB:%.*]] = add nsw <2 x i32> [[X:%.*]], <i32 -32768, i32 -32768>
836 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
838 %sub = sub nsw <2 x i32> %x, <i32 32768, i32 32768>
842 define <vscale x 2 x i32> @test44scalablevec(<vscale x 2 x i32> %x) {
843 ; CHECK-LABEL: @test44scalablevec(
844 ; CHECK-NEXT: [[SUB:%.*]] = add nsw <vscale x 2 x i32> [[X:%.*]], shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> poison, i32 -32768, i32 0), <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer)
845 ; CHECK-NEXT: ret <vscale x 2 x i32> [[SUB]]
847 %sub = sub nsw <vscale x 2 x i32> %x, shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> undef, i32 32768, i32 0), <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer)
848 ret <vscale x 2 x i32> %sub
851 define <2 x i16> @test44vecminval(<2 x i16> %x) {
852 ; CHECK-LABEL: @test44vecminval(
853 ; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i16> [[X:%.*]], <i16 -32768, i16 -32768>
854 ; CHECK-NEXT: ret <2 x i16> [[SUB]]
856 %sub = sub nsw <2 x i16> %x, <i16 -32768, i16 -32768>
860 ; FIXME: This isn't combined to xor as above because the pattern in visitSub
861 ; uses m_ImmConstant which matches Constant but (explicitly) not ConstantExpr.
862 define <vscale x 2 x i16> @test44scalablevecminval(<vscale x 2 x i16> %x) {
863 ; CHECK-LABEL: @test44scalablevecminval(
864 ; CHECK-NEXT: [[SUB:%.*]] = add <vscale x 2 x i16> [[X:%.*]], shufflevector (<vscale x 2 x i16> insertelement (<vscale x 2 x i16> poison, i16 -32768, i32 0), <vscale x 2 x i16> poison, <vscale x 2 x i32> zeroinitializer)
865 ; CHECK-NEXT: ret <vscale x 2 x i16> [[SUB]]
867 %sub = sub nsw <vscale x 2 x i16> %x, shufflevector (<vscale x 2 x i16> insertelement (<vscale x 2 x i16> undef, i16 -32768, i32 0), <vscale x 2 x i16> undef, <vscale x 2 x i32> zeroinitializer)
868 ret <vscale x 2 x i16> %sub
871 define i32 @test45(i32 %x, i32 %y) {
872 ; CHECK-LABEL: @test45(
873 ; CHECK-NEXT: [[SUB:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
874 ; CHECK-NEXT: ret i32 [[SUB]]
877 %xor = xor i32 %x, %y
878 %sub = sub i32 %or, %xor
882 define i32 @test45commuted(i32 %x, i32 %y) {
883 ; CHECK-LABEL: @test45commuted(
884 ; CHECK-NEXT: [[SUB:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
885 ; CHECK-NEXT: ret i32 [[SUB]]
888 %xor = xor i32 %y, %x
889 %sub = sub i32 %or, %xor
893 define i32 @test46(i32 %x, i32 %y) {
894 ; CHECK-LABEL: @test46(
895 ; CHECK-NEXT: [[X_NOT:%.*]] = xor i32 [[X:%.*]], -1
896 ; CHECK-NEXT: [[SUB:%.*]] = and i32 [[X_NOT]], [[Y:%.*]]
897 ; CHECK-NEXT: ret i32 [[SUB]]
900 %sub = sub i32 %or, %x
904 define i32 @test46commuted(i32 %x, i32 %y) {
905 ; CHECK-LABEL: @test46commuted(
906 ; CHECK-NEXT: [[X_NOT:%.*]] = xor i32 [[X:%.*]], -1
907 ; CHECK-NEXT: [[SUB:%.*]] = and i32 [[X_NOT]], [[Y:%.*]]
908 ; CHECK-NEXT: ret i32 [[SUB]]
911 %sub = sub i32 %or, %x
915 define i32 @test47(i1 %A, i32 %B, i32 %C, i32 %D) {
916 ; CHECK-LABEL: @test47(
917 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[D:%.*]], [[C:%.*]]
918 ; CHECK-NEXT: [[SUB:%.*]] = select i1 [[A:%.*]], i32 [[TMP1]], i32 0
919 ; CHECK-NEXT: ret i32 [[SUB]]
921 %sel0 = select i1 %A, i32 %D, i32 %B
922 %sel1 = select i1 %A, i32 %C, i32 %B
923 %sub = sub i32 %sel0, %sel1
927 define i32 @test48(i1 %A, i32 %B, i32 %C, i32 %D) {
928 ; CHECK-LABEL: @test48(
929 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[D:%.*]], [[C:%.*]]
930 ; CHECK-NEXT: [[SUB:%.*]] = select i1 [[A:%.*]], i32 0, i32 [[TMP1]]
931 ; CHECK-NEXT: ret i32 [[SUB]]
933 %sel0 = select i1 %A, i32 %B, i32 %D
934 %sel1 = select i1 %A, i32 %B, i32 %C
935 %sub = sub i32 %sel0, %sel1
939 define i32 @test49(i32 %X) {
940 ; CHECK-LABEL: @test49(
941 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 1, [[X:%.*]]
942 ; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 64
943 ; CHECK-NEXT: ret i32 [[RES]]
945 %sub = sub i32 129, %X
946 %res = and i32 %sub, 64
950 define i32 @test50(i32 %X) {
951 ; CHECK-LABEL: @test50(
952 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 1, [[X:%.*]]
953 ; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 127
954 ; CHECK-NEXT: ret i32 [[RES]]
956 %sub = sub i32 129, %X
957 %res = and i32 %sub, 127
961 define i32 @test51(i32 %X) {
962 ; CHECK-LABEL: @test51(
963 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 126, [[X:%.*]]
964 ; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 64
965 ; CHECK-NEXT: ret i32 [[RES]]
967 %sub = sub i32 254, %X
968 %res = and i32 %sub, 64
972 define i32 @test52(i32 %X) {
973 ; CHECK-LABEL: @test52(
974 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 126, [[X:%.*]]
975 ; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 127
976 ; CHECK-NEXT: ret i32 [[RES]]
978 %sub = sub i32 254, %X
979 %res = and i32 %sub, 127
983 define <2 x i1> @test53(<2 x i1> %A, <2 x i1> %B) {
984 ; CHECK-LABEL: @test53(
985 ; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i1> [[B:%.*]], [[A:%.*]]
986 ; CHECK-NEXT: ret <2 x i1> [[SUB]]
988 %sub = sub <2 x i1> %A, %B
992 define i32 @test54(i1 %C) {
993 ; CHECK-LABEL: @test54(
994 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 -877, i32 113
995 ; CHECK-NEXT: ret i32 [[V]]
997 %A = select i1 %C, i32 1000, i32 10
1002 define <2 x i32> @test54vec(i1 %C) {
1003 ; CHECK-LABEL: @test54vec(
1004 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 -877, i32 -877>, <2 x i32> <i32 113, i32 113>
1005 ; CHECK-NEXT: ret <2 x i32> [[V]]
1007 %A = select i1 %C, <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10>
1008 %V = sub <2 x i32> <i32 123, i32 123>, %A
1012 define <2 x i32> @test54vec2(i1 %C) {
1013 ; CHECK-LABEL: @test54vec2(
1014 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 -877, i32 -2167>, <2 x i32> <i32 113, i32 303>
1015 ; CHECK-NEXT: ret <2 x i32> [[V]]
1017 %A = select i1 %C, <2 x i32> <i32 1000, i32 2500>, <2 x i32> <i32 10, i32 30>
1018 %V = sub <2 x i32> <i32 123, i32 333>, %A
1022 define i32 @test55(i1 %which) {
1023 ; CHECK-LABEL: @test55(
1024 ; CHECK-NEXT: entry:
1025 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
1027 ; CHECK-NEXT: br label [[FINAL]]
1029 ; CHECK-NEXT: [[A_NEG:%.*]] = phi i32 [ -877, [[ENTRY:%.*]] ], [ 113, [[DELAY]] ]
1030 ; CHECK-NEXT: ret i32 [[A_NEG]]
1033 br i1 %which, label %final, label %delay
1039 %A = phi i32 [ 1000, %entry ], [ 10, %delay ]
1040 %value = sub i32 123, %A
1044 define <2 x i32> @test55vec(i1 %which) {
1045 ; CHECK-LABEL: @test55vec(
1046 ; CHECK-NEXT: entry:
1047 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
1049 ; CHECK-NEXT: br label [[FINAL]]
1051 ; CHECK-NEXT: [[A_NEG:%.*]] = phi <2 x i32> [ <i32 -877, i32 -877>, [[ENTRY:%.*]] ], [ <i32 113, i32 113>, [[DELAY]] ]
1052 ; CHECK-NEXT: ret <2 x i32> [[A_NEG]]
1055 br i1 %which, label %final, label %delay
1061 %A = phi <2 x i32> [ <i32 1000, i32 1000>, %entry ], [ <i32 10, i32 10>, %delay ]
1062 %value = sub <2 x i32> <i32 123, i32 123>, %A
1063 ret <2 x i32> %value
1066 define <2 x i32> @test55vec2(i1 %which) {
1067 ; CHECK-LABEL: @test55vec2(
1068 ; CHECK-NEXT: entry:
1069 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
1071 ; CHECK-NEXT: br label [[FINAL]]
1073 ; CHECK-NEXT: [[A_NEG:%.*]] = phi <2 x i32> [ <i32 -877, i32 -2167>, [[ENTRY:%.*]] ], [ <i32 113, i32 303>, [[DELAY]] ]
1074 ; CHECK-NEXT: ret <2 x i32> [[A_NEG]]
1077 br i1 %which, label %final, label %delay
1083 %A = phi <2 x i32> [ <i32 1000, i32 2500>, %entry ], [ <i32 10, i32 30>, %delay ]
1084 %value = sub <2 x i32> <i32 123, i32 333>, %A
1085 ret <2 x i32> %value
1088 define i32 @test56(i32 %A, i32 %B) {
1089 ; CHECK-LABEL: @test56(
1090 ; CHECK-NEXT: [[Y:%.*]] = sub i32 0, [[B:%.*]]
1091 ; CHECK-NEXT: ret i32 [[Y]]
1098 define i32 @test57(i32 %A, i32 %B) {
1099 ; CHECK-LABEL: @test57(
1100 ; CHECK-NEXT: [[Y:%.*]] = sub i32 0, [[B:%.*]]
1101 ; CHECK-NEXT: ret i32 [[Y]]
1108 @dummy_global1 = external global i8*
1109 @dummy_global2 = external global i8*
1111 define i64 @test58([100 x [100 x i8]]* %foo, i64 %i, i64 %j) {
1112 ; Note the reassociate pass and another instcombine pass will further optimize this to
1113 ; "%sub = i64 %i, %j, ret i64 %sub"
1114 ; gep1 and gep2 have only one use
1115 ; CHECK-LABEL: @test58(
1116 ; CHECK-NEXT: [[GEP1_OFFS:%.*]] = add nsw i64 [[I:%.*]], 4200
1117 ; CHECK-NEXT: [[GEP2_OFFS:%.*]] = add nsw i64 [[J:%.*]], 4200
1118 ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[GEP1_OFFS]], [[GEP2_OFFS]]
1119 ; CHECK-NEXT: ret i64 [[GEPDIFF]]
1121 %gep1 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %i
1122 %gep2 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %j
1123 %cast1 = ptrtoint i8* %gep1 to i64
1124 %cast2 = ptrtoint i8* %gep2 to i64
1125 %sub = sub i64 %cast1, %cast2
1129 define i64 @test59([100 x [100 x i8]]* %foo, i64 %i) {
1130 ; CHECK-LABEL: @test59(
1131 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO:%.*]], i64 0, i64 42, i64 [[I:%.*]]
1132 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO]], i64 0, i64 42, i64 0
1133 ; CHECK-NEXT: store i8* [[GEP1]], i8** @dummy_global1, align 8
1134 ; CHECK-NEXT: store i8* [[GEP2]], i8** @dummy_global2, align 8
1135 ; CHECK-NEXT: ret i64 [[I]]
1137 ; gep1 and gep2 have more than one uses
1138 %gep1 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %i
1139 %gep2 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 0
1140 %cast1 = ptrtoint i8* %gep1 to i64
1141 %cast2 = ptrtoint i8* %gep2 to i64
1142 %sub = sub i64 %cast1, %cast2
1143 store i8* %gep1, i8** @dummy_global1
1144 store i8* %gep2, i8** @dummy_global2
1148 define i64 @test60([100 x [100 x i8]]* %foo, i64 %i, i64 %j) {
1149 ; CHECK-LABEL: @test60(
1150 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO:%.*]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]]
1151 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO]], i64 0, i64 42, i64 0
1152 ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint i8* [[GEP1]] to i64
1153 ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint i8* [[GEP2]] to i64
1154 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]]
1155 ; CHECK-NEXT: store i8* [[GEP1]], i8** @dummy_global1, align 8
1156 ; CHECK-NEXT: ret i64 [[SUB]]
1158 ; gep1 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
1159 %gep1 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 %j, i64 %i
1160 %gep2 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 0
1161 %cast1 = ptrtoint i8* %gep1 to i64
1162 %cast2 = ptrtoint i8* %gep2 to i64
1163 %sub = sub i64 %cast1, %cast2
1164 store i8* %gep1, i8** @dummy_global1
1168 define i64 @test61([100 x [100 x i8]]* %foo, i64 %i, i64 %j) {
1169 ; CHECK-LABEL: @test61(
1170 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO:%.*]], i64 0, i64 42, i64 0
1171 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]]
1172 ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint i8* [[GEP1]] to i64
1173 ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint i8* [[GEP2]] to i64
1174 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]]
1175 ; CHECK-NEXT: store i8* [[GEP2]], i8** @dummy_global2, align 8
1176 ; CHECK-NEXT: ret i64 [[SUB]]
1178 ; gep2 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
1179 %gep1 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 0
1180 %gep2 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 %j, i64 %i
1181 %cast1 = ptrtoint i8* %gep1 to i64
1182 %cast2 = ptrtoint i8* %gep2 to i64
1183 %sub = sub i64 %cast1, %cast2
1184 store i8* %gep2, i8** @dummy_global2
1188 define i32 @test62(i32 %A) {
1189 ; CHECK-LABEL: @test62(
1190 ; CHECK-NEXT: [[B_NEG:%.*]] = mul i32 [[A:%.*]], -2
1191 ; CHECK-NEXT: [[C:%.*]] = add i32 [[B_NEG]], 2
1192 ; CHECK-NEXT: ret i32 [[C]]
1199 define <2 x i32> @test62vec(<2 x i32> %A) {
1200 ; CHECK-LABEL: @test62vec(
1201 ; CHECK-NEXT: [[B_NEG:%.*]] = mul <2 x i32> [[A:%.*]], <i32 -2, i32 -2>
1202 ; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B_NEG]], <i32 2, i32 2>
1203 ; CHECK-NEXT: ret <2 x i32> [[C]]
1205 %B = sub <2 x i32> <i32 1, i32 1>, %A
1206 %C = shl <2 x i32> %B, <i32 1, i32 1>
1210 define i32 @test63(i32 %A) {
1211 ; CHECK-LABEL: @test63(
1212 ; CHECK-NEXT: [[B_NEG_NEG:%.*]] = shl i32 [[A:%.*]], 1
1213 ; CHECK-NEXT: ret i32 [[B_NEG_NEG]]
1221 define <2 x i32> @test63vec(<2 x i32> %A) {
1222 ; CHECK-LABEL: @test63vec(
1223 ; CHECK-NEXT: [[B_NEG_NEG:%.*]] = shl <2 x i32> [[A:%.*]], <i32 1, i32 1>
1224 ; CHECK-NEXT: ret <2 x i32> [[B_NEG_NEG]]
1226 %B = sub <2 x i32> <i32 1, i32 1>, %A
1227 %C = shl <2 x i32> %B, <i32 1, i32 1>
1228 %D = sub <2 x i32> <i32 2, i32 2>, %C
1232 define i32 @test64(i32 %x) {
1233 ; CHECK-LABEL: @test64(
1234 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 255
1235 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 255
1236 ; CHECK-NEXT: [[DOTNEG:%.*]] = add nsw i32 [[TMP2]], 1
1237 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1240 %2 = icmp sgt i32 %1, -256
1241 %3 = select i1 %2, i32 %1, i32 -256
1242 %res = sub i32 0, %3
1246 define i32 @test65(i32 %x) {
1247 ; CHECK-LABEL: @test65(
1248 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], -256
1249 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 -256
1250 ; CHECK-NEXT: [[DOTNEG:%.*]] = add i32 [[TMP2]], 1
1251 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1254 %2 = icmp slt i32 %1, 255
1255 %3 = select i1 %2, i32 %1, i32 255
1256 %res = sub i32 0, %3
1260 define i32 @test66(i32 %x) {
1261 ; CHECK-LABEL: @test66(
1262 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X:%.*]], -101
1263 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 -101
1264 ; CHECK-NEXT: [[DOTNEG:%.*]] = add nuw i32 [[TMP2]], 1
1265 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1268 %2 = icmp ugt i32 %1, 100
1269 %3 = select i1 %2, i32 %1, i32 100
1270 %res = sub i32 0, %3
1274 define i32 @test67(i32 %x) {
1275 ; CHECK-LABEL: @test67(
1276 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X:%.*]], 100
1277 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 100
1278 ; CHECK-NEXT: [[DOTNEG:%.*]] = add i32 [[TMP2]], 1
1279 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1282 %2 = icmp ult i32 %1, -101
1283 %3 = select i1 %2, i32 %1, i32 -101
1284 %res = sub i32 0, %3
1288 ; Check splat vectors too
1289 define <2 x i32> @test68(<2 x i32> %x) {
1290 ; CHECK-LABEL: @test68(
1291 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <2 x i32> [[X:%.*]], <i32 255, i32 255>
1292 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i32> [[X]], <2 x i32> <i32 255, i32 255>
1293 ; CHECK-NEXT: [[DOTNEG:%.*]] = add nsw <2 x i32> [[TMP2]], <i32 1, i32 1>
1294 ; CHECK-NEXT: ret <2 x i32> [[DOTNEG]]
1296 %1 = xor <2 x i32> %x, <i32 -1, i32 -1>
1297 %2 = icmp sgt <2 x i32> %1, <i32 -256, i32 -256>
1298 %3 = select <2 x i1> %2, <2 x i32> %1, <2 x i32> <i32 -256, i32 -256>
1299 %res = sub <2 x i32> zeroinitializer, %3
1303 ; And non-splat constant vectors.
1304 define <2 x i32> @test69(<2 x i32> %x) {
1305 ; CHECK-LABEL: @test69(
1306 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <2 x i32> [[X:%.*]], <i32 255, i32 127>
1307 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i32> [[X]], <2 x i32> <i32 255, i32 127>
1308 ; CHECK-NEXT: [[DOTNEG:%.*]] = add <2 x i32> [[TMP2]], <i32 1, i32 1>
1309 ; CHECK-NEXT: ret <2 x i32> [[DOTNEG]]
1311 %1 = xor <2 x i32> %x, <i32 -1, i32 -1>
1312 %2 = icmp sgt <2 x i32> %1, <i32 -256, i32 -128>
1313 %3 = select <2 x i1> %2, <2 x i32> %1, <2 x i32> <i32 -256, i32 -128>
1314 %res = sub <2 x i32> zeroinitializer, %3
1318 ; Check (X | Y) - Y --> X & ~Y when Y is a constant
1319 define i32 @test70(i32 %A) {
1320 ; CHECK-LABEL: @test70(
1321 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -124
1322 ; CHECK-NEXT: ret i32 [[TMP1]]
1325 %C = sub i32 %B, 123
1329 ; Check (X | Y) - Y --> (X | Y) ^ Y doesn't happen where (X | Y) has multiple uses
1330 define i32 @test71(i32 %A, i32 %B) {
1331 ; CHECK-LABEL: @test71(
1332 ; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
1333 ; CHECK-NEXT: [[D:%.*]] = sub i32 [[C]], [[B]]
1334 ; CHECK-NEXT: [[E:%.*]] = mul i32 [[C]], [[D]]
1335 ; CHECK-NEXT: ret i32 [[E]]
1343 ; Check (X | Y) - Y --> X & ~Y where X and Y are vectors
1344 define <2 x i32> @test72(<2 x i32> %A, <2 x i32> %B) {
1345 ; CHECK-LABEL: @test72(
1346 ; CHECK-NEXT: [[B_NOT:%.*]] = xor <2 x i32> [[B:%.*]], <i32 -1, i32 -1>
1347 ; CHECK-NEXT: [[D:%.*]] = and <2 x i32> [[B_NOT]], [[A:%.*]]
1348 ; CHECK-NEXT: ret <2 x i32> [[D]]
1350 %C = or <2 x i32> %A, %B
1351 %D = sub <2 x i32> %C, %B
1355 ; Check reversing sub operands won't trigger (X | Y) - Y --> X & ~Y
1356 define i32 @test73(i32 %A, i32 %B) {
1357 ; CHECK-LABEL: @test73(
1358 ; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
1359 ; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[C]]
1360 ; CHECK-NEXT: ret i32 [[D]]
1367 define i32 @nsw_inference1(i32 %x, i32 %y) {
1368 ; CHECK-LABEL: @nsw_inference1(
1369 ; CHECK-NEXT: [[X2:%.*]] = or i32 [[X:%.*]], 1024
1370 ; CHECK-NEXT: [[Y2:%.*]] = and i32 [[Y:%.*]], 1
1371 ; CHECK-NEXT: [[Z:%.*]] = sub nuw nsw i32 [[X2]], [[Y2]]
1372 ; CHECK-NEXT: ret i32 [[Z]]
1374 %x2 = or i32 %x, 1024
1376 %z = sub i32 %x2, %y2
1380 define i32 @nsw_inference2(i32 %x, i32 %y) {
1381 ; CHECK-LABEL: @nsw_inference2(
1382 ; CHECK-NEXT: [[X2:%.*]] = and i32 [[X:%.*]], -1025
1383 ; CHECK-NEXT: [[Y2:%.*]] = or i32 [[Y:%.*]], -2
1384 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i32 [[X2]], [[Y2]]
1385 ; CHECK-NEXT: ret i32 [[Z]]
1387 %x2 = and i32 %x, -1025
1389 %z = sub i32 %x2, %y2
1393 define i8 @test74(i8 %x, i8 %y) {
1394 ; CHECK-LABEL: @test74(
1395 ; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
1396 ; CHECK-NEXT: call void @use8(i8 [[T0]])
1397 ; CHECK-NEXT: [[T1:%.*]] = sub i8 [[X]], [[T0]]
1398 ; CHECK-NEXT: ret i8 [[T1]]
1401 call void @use8(i8 %t0)
1402 %t1 = sub i8 %x, %t0
1406 define i8 @test75(i8 %x) {
1407 ; CHECK-LABEL: @test75(
1408 ; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], -8
1409 ; CHECK-NEXT: call void @use8(i8 [[T0]])
1410 ; CHECK-NEXT: [[T1:%.*]] = and i8 [[X]], 7
1411 ; CHECK-NEXT: ret i8 [[T1]]
1414 call void @use8(i8 %t0)
1415 %t1 = sub i8 %x, %t0
1419 ; ((w-x) + y) - z --> (w+y) - (x+z)
1421 define i8 @sub_add_sub_reassoc(i8 %w, i8 %x, i8 %y, i8 %z) {
1422 ; CHECK-LABEL: @sub_add_sub_reassoc(
1423 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[W:%.*]], [[Y:%.*]]
1424 ; CHECK-NEXT: [[TMP2:%.*]] = add i8 [[X:%.*]], [[Z:%.*]]
1425 ; CHECK-NEXT: [[S2:%.*]] = sub i8 [[TMP1]], [[TMP2]]
1426 ; CHECK-NEXT: ret i8 [[S2]]
1436 define <2 x i8> @sub_add_sub_reassoc_commute(<2 x i8> %w, <2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
1437 ; CHECK-LABEL: @sub_add_sub_reassoc_commute(
1438 ; CHECK-NEXT: [[D:%.*]] = sdiv <2 x i8> [[Y:%.*]], <i8 42, i8 -42>
1439 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[D]], [[W:%.*]]
1440 ; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i8> [[X:%.*]], [[Z:%.*]]
1441 ; CHECK-NEXT: [[S2:%.*]] = sub <2 x i8> [[TMP1]], [[TMP2]]
1442 ; CHECK-NEXT: ret <2 x i8> [[S2]]
1444 %d = sdiv <2 x i8> %y, <i8 42, i8 -42> ; thwart complexity-based canonicalization
1445 %s1 = sub <2 x i8> %w, %x
1446 %a = add <2 x i8> %d, %s1
1447 %s2 = sub <2 x i8> %a, %z
1451 ; (v-w) + (x-y) - z --> (v+x) - (w+y+z)
1453 define i8 @sub_add_sub_reassoc_twice(i8 %v, i8 %w, i8 %x, i8 %y, i8 %z) {
1454 ; CHECK-LABEL: @sub_add_sub_reassoc_twice(
1455 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[W:%.*]], [[Z:%.*]]
1456 ; CHECK-NEXT: [[TMP2:%.*]] = add i8 [[X:%.*]], [[V:%.*]]
1457 ; CHECK-NEXT: [[TMP3:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
1458 ; CHECK-NEXT: [[S3:%.*]] = sub i8 [[TMP2]], [[TMP3]]
1459 ; CHECK-NEXT: ret i8 [[S3]]
1463 %a = add i8 %s1, %s2
1468 ; negative test - uses
1470 define i8 @sub_add_sub_reassoc_use1(i8 %w, i8 %x, i8 %y, i8 %z) {
1471 ; CHECK-LABEL: @sub_add_sub_reassoc_use1(
1472 ; CHECK-NEXT: [[S1:%.*]] = sub i8 [[W:%.*]], [[X:%.*]]
1473 ; CHECK-NEXT: call void @use8(i8 [[S1]])
1474 ; CHECK-NEXT: [[A:%.*]] = add i8 [[S1]], [[Y:%.*]]
1475 ; CHECK-NEXT: [[S2:%.*]] = sub i8 [[A]], [[Z:%.*]]
1476 ; CHECK-NEXT: ret i8 [[S2]]
1479 call void @use8(i8 %s1)
1485 ; negative test - uses
1487 define i8 @sub_add_sub_reassoc_use2(i8 %w, i8 %x, i8 %y, i8 %z) {
1488 ; CHECK-LABEL: @sub_add_sub_reassoc_use2(
1489 ; CHECK-NEXT: [[S1:%.*]] = sub i8 [[W:%.*]], [[X:%.*]]
1490 ; CHECK-NEXT: [[A:%.*]] = add i8 [[S1]], [[Y:%.*]]
1491 ; CHECK-NEXT: call void @use8(i8 [[A]])
1492 ; CHECK-NEXT: [[S2:%.*]] = sub i8 [[A]], [[Z:%.*]]
1493 ; CHECK-NEXT: ret i8 [[S2]]
1497 call void @use8(i8 %a)
1502 define i8 @sub_mask_lowbits(i8 %x) {
1503 ; CHECK-LABEL: @sub_mask_lowbits(
1504 ; CHECK-NEXT: [[A1:%.*]] = add i8 [[X:%.*]], -108
1505 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A1]], -4
1506 ; CHECK-NEXT: ret i8 [[R]]
1508 %a1 = add i8 %x, 148 ; 0x94
1510 %r = sub i8 %a1, %a2
1514 ; Negative test - low-bit mask must not overlap with offset
1516 define i8 @sub_not_mask_lowbits(i8 %x) {
1517 ; CHECK-LABEL: @sub_not_mask_lowbits(
1518 ; CHECK-NEXT: [[A1:%.*]] = add i8 [[X:%.*]], 4
1519 ; CHECK-NEXT: [[A2:%.*]] = and i8 [[X]], 7
1520 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[A1]], [[A2]]
1521 ; CHECK-NEXT: ret i8 [[R]]
1525 %r = sub i8 %a1, %a2
1529 define <2 x i8> @sub_mask_lowbits_splat_extra_use(<2 x i8> %x, <2 x i8>* %p) {
1530 ; CHECK-LABEL: @sub_mask_lowbits_splat_extra_use(
1531 ; CHECK-NEXT: [[A1:%.*]] = add <2 x i8> [[X:%.*]], <i8 -64, i8 -64>
1532 ; CHECK-NEXT: [[A2:%.*]] = and <2 x i8> [[X]], <i8 10, i8 10>
1533 ; CHECK-NEXT: store <2 x i8> [[A2]], <2 x i8>* [[P:%.*]], align 2
1534 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[A1]], <i8 -11, i8 -11>
1535 ; CHECK-NEXT: ret <2 x i8> [[R]]
1537 %a1 = add <2 x i8> %x, <i8 192, i8 192> ; 0xc0
1538 %a2 = and <2 x i8> %x, <i8 10, i8 10> ; 0x0a
1539 store <2 x i8> %a2, <2 x i8>* %p
1540 %r = sub <2 x i8> %a1, %a2
1544 define i16 @sub_nsw_mul_nsw(i16 %x, i16 %y) {
1545 ; CHECK-LABEL: @sub_nsw_mul_nsw(
1546 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i16 [[X:%.*]], [[Y:%.*]]
1547 ; CHECK-NEXT: [[R:%.*]] = shl nsw i16 [[TMP1]], 3
1548 ; CHECK-NEXT: ret i16 [[R]]
1550 %x8 = mul nsw i16 %x, 8
1551 %y8 = mul nsw i16 %y, 8
1552 %r = sub nsw i16 %x8, %y8
1556 define i16 @sub_nuw_mul_nsw(i16 %x, i16 %y) {
1557 ; CHECK-LABEL: @sub_nuw_mul_nsw(
1558 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1559 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 2
1560 ; CHECK-NEXT: ret i16 [[R]]
1562 %x8 = mul nsw i16 %x, 4
1563 %y8 = mul nsw i16 %y, 4
1564 %r = sub nuw i16 %x8, %y8
1568 define i16 @sub_mul_nsw(i16 %x, i16 %y) {
1569 ; CHECK-LABEL: @sub_mul_nsw(
1570 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1571 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 4
1572 ; CHECK-NEXT: ret i16 [[R]]
1574 %x8 = mul nsw i16 %x, 16
1575 %y8 = mul nsw i16 %y, 16
1576 %r = sub i16 %x8, %y8
1580 define i16 @sub_nsw_mul_nuw(i16 %x, i16 %y) {
1581 ; CHECK-LABEL: @sub_nsw_mul_nuw(
1582 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1583 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 3
1584 ; CHECK-NEXT: ret i16 [[R]]
1586 %x8 = mul nuw i16 %x, 8
1587 %y8 = mul nuw i16 %y, 8
1588 %r = sub nsw i16 %x8, %y8
1592 define i16 @sub_nuw_mul_nuw(i16 %x, i16 %y) {
1593 ; CHECK-LABEL: @sub_nuw_mul_nuw(
1594 ; CHECK-NEXT: [[TMP1:%.*]] = sub nuw i16 [[X:%.*]], [[Y:%.*]]
1595 ; CHECK-NEXT: [[R:%.*]] = shl nuw i16 [[TMP1]], 4
1596 ; CHECK-NEXT: ret i16 [[R]]
1598 %x8 = mul nuw i16 %x, 16
1599 %y8 = mul nuw i16 %y, 16
1600 %r = sub nuw i16 %x8, %y8
1604 define i16 @sub_mul_nuw(i16 %x, i16 %y) {
1605 ; CHECK-LABEL: @sub_mul_nuw(
1606 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1607 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 5
1608 ; CHECK-NEXT: ret i16 [[R]]
1610 %x8 = mul nuw i16 %x, 32
1611 %y8 = mul nuw i16 %y, 32
1612 %r = sub i16 %x8, %y8
1615 define i32 @and_test(i32 %x, i32 %y) {
1616 ; CHECK-LABEL: @and_test(
1617 ; CHECK-NEXT: [[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
1618 ; CHECK-NEXT: ret i32 [[R]]
1626 define i32 @and_test2(i32 %x, i32 %y) {
1627 ; CHECK-LABEL: @and_test2(
1628 ; CHECK-NEXT: [[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
1629 ; CHECK-NEXT: ret i32 [[R]]
1637 define i32 @and_test3(i32 %x, i32 %y) {
1638 ; CHECK-LABEL: @and_test3(
1639 ; CHECK-NEXT: [[R:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
1640 ; CHECK-NEXT: ret i32 [[R]]
1649 define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
1650 ; CHECK-LABEL: @and_vec(
1651 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]
1652 ; CHECK-NEXT: ret <2 x i8> [[R]]
1654 %a = add <2 x i8> %X, %Y
1655 %o = or <2 x i8> %X, %Y
1656 %r = sub <2 x i8> %a, %o
1660 define i32 @or_test(i32 %x, i32 %y) {
1661 ; CHECK-LABEL: @or_test(
1662 ; CHECK-NEXT: [[R:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
1663 ; CHECK-NEXT: ret i32 [[R]]
1671 define i32 @or_test2(i32 %x, i32 %y) {
1672 ; CHECK-LABEL: @or_test2(
1673 ; CHECK-NEXT: [[R:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
1674 ; CHECK-NEXT: ret i32 [[R]]
1682 define i32 @or_test3(i32 %x, i32 %y) {
1683 ; CHECK-LABEL: @or_test3(
1684 ; CHECK-NEXT: [[R:%.*]] = or i32 [[Y:%.*]], [[X:%.*]]
1685 ; CHECK-NEXT: ret i32 [[R]]
1693 define <2 x i8> @or_vec(<2 x i8> %X, <2 x i8> %Y) {
1694 ; CHECK-LABEL: @or_vec(
1695 ; CHECK-NEXT: [[R:%.*]] = or <2 x i8> [[X:%.*]], [[Y:%.*]]
1696 ; CHECK-NEXT: ret <2 x i8> [[R]]
1698 %a = add <2 x i8> %X, %Y
1699 %b = and <2 x i8> %X, %Y
1700 %r = sub <2 x i8> %a, %b