1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=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 (ptr @g to i32)
20 ; CHECK-NEXT: ret i32 [[R]]
22 %r = sub i32 %x, ptrtoint (ptr @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 (ptr @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 (ptr @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, ptr %p) {
440 ; CHECK-LABEL: @test_neg_shl_sub_extra_use1(
441 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[A:%.*]], [[B:%.*]]
442 ; CHECK-NEXT: store i64 [[SUB]], ptr [[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, ptr %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, ptr %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]], ptr [[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, ptr %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 nsw 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 nuw 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, ptr %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]], ptr [[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, ptr %p
517 define i64 @test_neg_sext_i1_extra_use(i1 %a, i64 %b, ptr %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]], ptr [[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, ptr %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 nuw 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 nsw 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, i64 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, i64 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 ptr
1109 @dummy_global2 = external global ptr
1111 define i64 @test58(ptr %foo, i64 %i, i64 %j) {
1112 ; CHECK-LABEL: @test58(
1113 ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub i64 [[I:%.*]], [[J:%.*]]
1114 ; CHECK-NEXT: ret i64 [[GEPDIFF]]
1116 %gep1 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 42, i64 %i
1117 %gep2 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 42, i64 %j
1118 %cast1 = ptrtoint ptr %gep1 to i64
1119 %cast2 = ptrtoint ptr %gep2 to i64
1120 %sub = sub i64 %cast1, %cast2
1124 define i64 @test59(ptr %foo, i64 %i) {
1125 ; CHECK-LABEL: @test59(
1126 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO:%.*]], i64 0, i64 42, i64 [[I:%.*]]
1127 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO]], i64 0, i64 42, i64 0
1128 ; CHECK-NEXT: store ptr [[GEP1]], ptr @dummy_global1, align 8
1129 ; CHECK-NEXT: store ptr [[GEP2]], ptr @dummy_global2, align 8
1130 ; CHECK-NEXT: ret i64 [[I]]
1132 ; gep1 and gep2 have more than one uses
1133 %gep1 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 42, i64 %i
1134 %gep2 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 42, i64 0
1135 %cast1 = ptrtoint ptr %gep1 to i64
1136 %cast2 = ptrtoint ptr %gep2 to i64
1137 %sub = sub i64 %cast1, %cast2
1138 store ptr %gep1, ptr @dummy_global1
1139 store ptr %gep2, ptr @dummy_global2
1143 define i64 @test60(ptr %foo, i64 %i, i64 %j) {
1144 ; CHECK-LABEL: @test60(
1145 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO:%.*]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]]
1146 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO]], i64 0, i64 42, i64 0
1147 ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint ptr [[GEP1]] to i64
1148 ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint ptr [[GEP2]] to i64
1149 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]]
1150 ; CHECK-NEXT: store ptr [[GEP1]], ptr @dummy_global1, align 8
1151 ; CHECK-NEXT: ret i64 [[SUB]]
1153 ; gep1 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
1154 %gep1 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 %j, i64 %i
1155 %gep2 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 42, i64 0
1156 %cast1 = ptrtoint ptr %gep1 to i64
1157 %cast2 = ptrtoint ptr %gep2 to i64
1158 %sub = sub i64 %cast1, %cast2
1159 store ptr %gep1, ptr @dummy_global1
1163 define i64 @test61(ptr %foo, i64 %i, i64 %j) {
1164 ; CHECK-LABEL: @test61(
1165 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO:%.*]], i64 0, i64 42, i64 0
1166 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]]
1167 ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint ptr [[GEP1]] to i64
1168 ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint ptr [[GEP2]] to i64
1169 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]]
1170 ; CHECK-NEXT: store ptr [[GEP2]], ptr @dummy_global2, align 8
1171 ; CHECK-NEXT: ret i64 [[SUB]]
1173 ; gep2 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
1174 %gep1 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 42, i64 0
1175 %gep2 = getelementptr inbounds [100 x [100 x i8]], ptr %foo, i64 0, i64 %j, i64 %i
1176 %cast1 = ptrtoint ptr %gep1 to i64
1177 %cast2 = ptrtoint ptr %gep2 to i64
1178 %sub = sub i64 %cast1, %cast2
1179 store ptr %gep2, ptr @dummy_global2
1183 define i32 @test62(i32 %A) {
1184 ; CHECK-LABEL: @test62(
1185 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A:%.*]], 1
1186 ; CHECK-NEXT: [[C:%.*]] = sub i32 2, [[TMP1]]
1187 ; CHECK-NEXT: ret i32 [[C]]
1194 define <2 x i32> @test62vec(<2 x i32> %A) {
1195 ; CHECK-LABEL: @test62vec(
1196 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[A:%.*]], <i32 1, i32 1>
1197 ; CHECK-NEXT: [[C:%.*]] = sub <2 x i32> <i32 2, i32 2>, [[TMP1]]
1198 ; CHECK-NEXT: ret <2 x i32> [[C]]
1200 %B = sub <2 x i32> <i32 1, i32 1>, %A
1201 %C = shl <2 x i32> %B, <i32 1, i32 1>
1205 define i32 @test63(i32 %A) {
1206 ; CHECK-LABEL: @test63(
1207 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A:%.*]], 1
1208 ; CHECK-NEXT: ret i32 [[TMP1]]
1216 define <2 x i32> @test63vec(<2 x i32> %A) {
1217 ; CHECK-LABEL: @test63vec(
1218 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[A:%.*]], <i32 1, i32 1>
1219 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
1221 %B = sub <2 x i32> <i32 1, i32 1>, %A
1222 %C = shl <2 x i32> %B, <i32 1, i32 1>
1223 %D = sub <2 x i32> <i32 2, i32 2>, %C
1227 define i32 @test64(i32 %x) {
1228 ; CHECK-LABEL: @test64(
1229 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 255)
1230 ; CHECK-NEXT: [[DOTNEG:%.*]] = add nsw i32 [[TMP1]], 1
1231 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1234 %2 = icmp sgt i32 %1, -256
1235 %3 = select i1 %2, i32 %1, i32 -256
1236 %res = sub i32 0, %3
1240 define i32 @test65(i32 %x) {
1241 ; CHECK-LABEL: @test65(
1242 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.smax.i32(i32 [[X:%.*]], i32 -256)
1243 ; CHECK-NEXT: [[DOTNEG:%.*]] = add i32 [[TMP1]], 1
1244 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1247 %2 = icmp slt i32 %1, 255
1248 %3 = select i1 %2, i32 %1, i32 255
1249 %res = sub i32 0, %3
1253 define i32 @test66(i32 %x) {
1254 ; CHECK-LABEL: @test66(
1255 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[X:%.*]], i32 -101)
1256 ; CHECK-NEXT: [[DOTNEG:%.*]] = add nuw i32 [[TMP1]], 1
1257 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1260 %2 = icmp ugt i32 %1, 100
1261 %3 = select i1 %2, i32 %1, i32 100
1262 %res = sub i32 0, %3
1266 define i32 @test67(i32 %x) {
1267 ; CHECK-LABEL: @test67(
1268 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[X:%.*]], i32 100)
1269 ; CHECK-NEXT: [[DOTNEG:%.*]] = add i32 [[TMP1]], 1
1270 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1273 %2 = icmp ult i32 %1, -101
1274 %3 = select i1 %2, i32 %1, i32 -101
1275 %res = sub i32 0, %3
1279 ; Check splat vectors too
1280 define <2 x i32> @test68(<2 x i32> %x) {
1281 ; CHECK-LABEL: @test68(
1282 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[X:%.*]], <2 x i32> <i32 255, i32 255>)
1283 ; CHECK-NEXT: [[DOTNEG:%.*]] = add nsw <2 x i32> [[TMP1]], <i32 1, i32 1>
1284 ; CHECK-NEXT: ret <2 x i32> [[DOTNEG]]
1286 %1 = xor <2 x i32> %x, <i32 -1, i32 -1>
1287 %2 = icmp sgt <2 x i32> %1, <i32 -256, i32 -256>
1288 %3 = select <2 x i1> %2, <2 x i32> %1, <2 x i32> <i32 -256, i32 -256>
1289 %res = sub <2 x i32> zeroinitializer, %3
1293 ; And non-splat constant vectors.
1294 define <2 x i32> @test69(<2 x i32> %x) {
1295 ; CHECK-LABEL: @test69(
1296 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[X:%.*]], <2 x i32> <i32 255, i32 127>)
1297 ; CHECK-NEXT: [[DOTNEG:%.*]] = add <2 x i32> [[TMP1]], <i32 1, i32 1>
1298 ; CHECK-NEXT: ret <2 x i32> [[DOTNEG]]
1300 %1 = xor <2 x i32> %x, <i32 -1, i32 -1>
1301 %2 = icmp sgt <2 x i32> %1, <i32 -256, i32 -128>
1302 %3 = select <2 x i1> %2, <2 x i32> %1, <2 x i32> <i32 -256, i32 -128>
1303 %res = sub <2 x i32> zeroinitializer, %3
1307 ; Check (X | Y) - Y --> X & ~Y when Y is a constant
1308 define i32 @test70(i32 %A) {
1309 ; CHECK-LABEL: @test70(
1310 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], -124
1311 ; CHECK-NEXT: ret i32 [[C]]
1314 %C = sub i32 %B, 123
1318 ; Check (X | Y) - Y --> (X | Y) ^ Y doesn't happen where (X | Y) has multiple uses
1319 define i32 @test71(i32 %A, i32 %B) {
1320 ; CHECK-LABEL: @test71(
1321 ; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
1322 ; CHECK-NEXT: [[D:%.*]] = sub i32 [[C]], [[B]]
1323 ; CHECK-NEXT: [[E:%.*]] = mul i32 [[C]], [[D]]
1324 ; CHECK-NEXT: ret i32 [[E]]
1332 ; Check (X | Y) - Y --> X & ~Y where X and Y are vectors
1333 define <2 x i32> @test72(<2 x i32> %A, <2 x i32> %B) {
1334 ; CHECK-LABEL: @test72(
1335 ; CHECK-NEXT: [[B_NOT:%.*]] = xor <2 x i32> [[B:%.*]], <i32 -1, i32 -1>
1336 ; CHECK-NEXT: [[D:%.*]] = and <2 x i32> [[B_NOT]], [[A:%.*]]
1337 ; CHECK-NEXT: ret <2 x i32> [[D]]
1339 %C = or <2 x i32> %A, %B
1340 %D = sub <2 x i32> %C, %B
1344 ; Check reversing sub operands won't trigger (X | Y) - Y --> X & ~Y
1345 define i32 @test73(i32 %A, i32 %B) {
1346 ; CHECK-LABEL: @test73(
1347 ; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
1348 ; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[C]]
1349 ; CHECK-NEXT: ret i32 [[D]]
1356 define i32 @nsw_inference1(i32 %x, i32 %y) {
1357 ; CHECK-LABEL: @nsw_inference1(
1358 ; CHECK-NEXT: [[X2:%.*]] = or i32 [[X:%.*]], 1024
1359 ; CHECK-NEXT: [[Y2:%.*]] = and i32 [[Y:%.*]], 1
1360 ; CHECK-NEXT: [[Z:%.*]] = sub nuw nsw i32 [[X2]], [[Y2]]
1361 ; CHECK-NEXT: ret i32 [[Z]]
1363 %x2 = or i32 %x, 1024
1365 %z = sub i32 %x2, %y2
1369 define i32 @nsw_inference2(i32 %x, i32 %y) {
1370 ; CHECK-LABEL: @nsw_inference2(
1371 ; CHECK-NEXT: [[X2:%.*]] = and i32 [[X:%.*]], -1025
1372 ; CHECK-NEXT: [[Y2:%.*]] = or i32 [[Y:%.*]], -2
1373 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i32 [[X2]], [[Y2]]
1374 ; CHECK-NEXT: ret i32 [[Z]]
1376 %x2 = and i32 %x, -1025
1378 %z = sub i32 %x2, %y2
1382 define i8 @test74(i8 %x, i8 %y) {
1383 ; CHECK-LABEL: @test74(
1384 ; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
1385 ; CHECK-NEXT: call void @use8(i8 [[T0]])
1386 ; CHECK-NEXT: [[T1:%.*]] = sub i8 [[X]], [[T0]]
1387 ; CHECK-NEXT: ret i8 [[T1]]
1390 call void @use8(i8 %t0)
1391 %t1 = sub i8 %x, %t0
1395 define i8 @test75(i8 %x) {
1396 ; CHECK-LABEL: @test75(
1397 ; CHECK-NEXT: [[T0:%.*]] = and i8 [[X:%.*]], -8
1398 ; CHECK-NEXT: call void @use8(i8 [[T0]])
1399 ; CHECK-NEXT: [[T1:%.*]] = and i8 [[X]], 7
1400 ; CHECK-NEXT: ret i8 [[T1]]
1403 call void @use8(i8 %t0)
1404 %t1 = sub i8 %x, %t0
1408 ; ((w-x) + y) - z --> (w+y) - (x+z)
1410 define i8 @sub_add_sub_reassoc(i8 %w, i8 %x, i8 %y, i8 %z) {
1411 ; CHECK-LABEL: @sub_add_sub_reassoc(
1412 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[W:%.*]], [[Y:%.*]]
1413 ; CHECK-NEXT: [[TMP2:%.*]] = add i8 [[X:%.*]], [[Z:%.*]]
1414 ; CHECK-NEXT: [[S2:%.*]] = sub i8 [[TMP1]], [[TMP2]]
1415 ; CHECK-NEXT: ret i8 [[S2]]
1425 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) {
1426 ; CHECK-LABEL: @sub_add_sub_reassoc_commute(
1427 ; CHECK-NEXT: [[D:%.*]] = sdiv <2 x i8> [[Y:%.*]], <i8 42, i8 -42>
1428 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[D]], [[W:%.*]]
1429 ; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i8> [[X:%.*]], [[Z:%.*]]
1430 ; CHECK-NEXT: [[S2:%.*]] = sub <2 x i8> [[TMP1]], [[TMP2]]
1431 ; CHECK-NEXT: ret <2 x i8> [[S2]]
1433 %d = sdiv <2 x i8> %y, <i8 42, i8 -42> ; thwart complexity-based canonicalization
1434 %s1 = sub <2 x i8> %w, %x
1435 %a = add <2 x i8> %d, %s1
1436 %s2 = sub <2 x i8> %a, %z
1440 ; (v-w) + (x-y) - z --> (v+x) - (w+y+z)
1442 define i8 @sub_add_sub_reassoc_twice(i8 %v, i8 %w, i8 %x, i8 %y, i8 %z) {
1443 ; CHECK-LABEL: @sub_add_sub_reassoc_twice(
1444 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[W:%.*]], [[Z:%.*]]
1445 ; CHECK-NEXT: [[TMP2:%.*]] = add i8 [[X:%.*]], [[V:%.*]]
1446 ; CHECK-NEXT: [[TMP3:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
1447 ; CHECK-NEXT: [[S3:%.*]] = sub i8 [[TMP2]], [[TMP3]]
1448 ; CHECK-NEXT: ret i8 [[S3]]
1452 %a = add i8 %s1, %s2
1457 ; negative test - uses
1459 define i8 @sub_add_sub_reassoc_use1(i8 %w, i8 %x, i8 %y, i8 %z) {
1460 ; CHECK-LABEL: @sub_add_sub_reassoc_use1(
1461 ; CHECK-NEXT: [[S1:%.*]] = sub i8 [[W:%.*]], [[X:%.*]]
1462 ; CHECK-NEXT: call void @use8(i8 [[S1]])
1463 ; CHECK-NEXT: [[A:%.*]] = add i8 [[S1]], [[Y:%.*]]
1464 ; CHECK-NEXT: [[S2:%.*]] = sub i8 [[A]], [[Z:%.*]]
1465 ; CHECK-NEXT: ret i8 [[S2]]
1468 call void @use8(i8 %s1)
1474 ; negative test - uses
1476 define i8 @sub_add_sub_reassoc_use2(i8 %w, i8 %x, i8 %y, i8 %z) {
1477 ; CHECK-LABEL: @sub_add_sub_reassoc_use2(
1478 ; CHECK-NEXT: [[S1:%.*]] = sub i8 [[W:%.*]], [[X:%.*]]
1479 ; CHECK-NEXT: [[A:%.*]] = add i8 [[S1]], [[Y:%.*]]
1480 ; CHECK-NEXT: call void @use8(i8 [[A]])
1481 ; CHECK-NEXT: [[S2:%.*]] = sub i8 [[A]], [[Z:%.*]]
1482 ; CHECK-NEXT: ret i8 [[S2]]
1486 call void @use8(i8 %a)
1491 define i8 @sub_mask_lowbits(i8 %x) {
1492 ; CHECK-LABEL: @sub_mask_lowbits(
1493 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -4
1494 ; CHECK-NEXT: [[R:%.*]] = add i8 [[TMP1]], -108
1495 ; CHECK-NEXT: ret i8 [[R]]
1497 %a1 = add i8 %x, 148 ; 0x94
1499 %r = sub i8 %a1, %a2
1503 ; Negative test - low-bit mask must not overlap with offset
1505 define i8 @sub_not_mask_lowbits(i8 %x) {
1506 ; CHECK-LABEL: @sub_not_mask_lowbits(
1507 ; CHECK-NEXT: [[A1:%.*]] = add i8 [[X:%.*]], 4
1508 ; CHECK-NEXT: [[A2:%.*]] = and i8 [[X]], 7
1509 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[A1]], [[A2]]
1510 ; CHECK-NEXT: ret i8 [[R]]
1514 %r = sub i8 %a1, %a2
1518 define <2 x i8> @sub_mask_lowbits_splat_extra_use(<2 x i8> %x, ptr %p) {
1519 ; CHECK-LABEL: @sub_mask_lowbits_splat_extra_use(
1520 ; CHECK-NEXT: [[A2:%.*]] = and <2 x i8> [[X:%.*]], <i8 10, i8 10>
1521 ; CHECK-NEXT: store <2 x i8> [[A2]], ptr [[P:%.*]], align 2
1522 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X]], <i8 -11, i8 -11>
1523 ; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[TMP1]], <i8 -64, i8 -64>
1524 ; CHECK-NEXT: ret <2 x i8> [[R]]
1526 %a1 = add <2 x i8> %x, <i8 192, i8 192> ; 0xc0
1527 %a2 = and <2 x i8> %x, <i8 10, i8 10> ; 0x0a
1528 store <2 x i8> %a2, ptr %p
1529 %r = sub <2 x i8> %a1, %a2
1533 define i16 @sub_nsw_mul_nsw(i16 %x, i16 %y) {
1534 ; CHECK-LABEL: @sub_nsw_mul_nsw(
1535 ; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i16 [[X:%.*]], [[Y:%.*]]
1536 ; CHECK-NEXT: [[R:%.*]] = shl nsw i16 [[TMP1]], 3
1537 ; CHECK-NEXT: ret i16 [[R]]
1539 %x8 = mul nsw i16 %x, 8
1540 %y8 = mul nsw i16 %y, 8
1541 %r = sub nsw i16 %x8, %y8
1545 define i16 @sub_nuw_mul_nsw(i16 %x, i16 %y) {
1546 ; CHECK-LABEL: @sub_nuw_mul_nsw(
1547 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1548 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 2
1549 ; CHECK-NEXT: ret i16 [[R]]
1551 %x8 = mul nsw i16 %x, 4
1552 %y8 = mul nsw i16 %y, 4
1553 %r = sub nuw i16 %x8, %y8
1557 define i16 @sub_mul_nsw(i16 %x, i16 %y) {
1558 ; CHECK-LABEL: @sub_mul_nsw(
1559 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1560 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 4
1561 ; CHECK-NEXT: ret i16 [[R]]
1563 %x8 = mul nsw i16 %x, 16
1564 %y8 = mul nsw i16 %y, 16
1565 %r = sub i16 %x8, %y8
1569 define i16 @sub_nsw_mul_nuw(i16 %x, i16 %y) {
1570 ; CHECK-LABEL: @sub_nsw_mul_nuw(
1571 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1572 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 3
1573 ; CHECK-NEXT: ret i16 [[R]]
1575 %x8 = mul nuw i16 %x, 8
1576 %y8 = mul nuw i16 %y, 8
1577 %r = sub nsw i16 %x8, %y8
1581 define i16 @sub_nuw_mul_nuw(i16 %x, i16 %y) {
1582 ; CHECK-LABEL: @sub_nuw_mul_nuw(
1583 ; CHECK-NEXT: [[TMP1:%.*]] = sub nuw i16 [[X:%.*]], [[Y:%.*]]
1584 ; CHECK-NEXT: [[R:%.*]] = shl nuw i16 [[TMP1]], 4
1585 ; CHECK-NEXT: ret i16 [[R]]
1587 %x8 = mul nuw i16 %x, 16
1588 %y8 = mul nuw i16 %y, 16
1589 %r = sub nuw i16 %x8, %y8
1593 define i16 @sub_mul_nuw(i16 %x, i16 %y) {
1594 ; CHECK-LABEL: @sub_mul_nuw(
1595 ; CHECK-NEXT: [[TMP1:%.*]] = sub i16 [[X:%.*]], [[Y:%.*]]
1596 ; CHECK-NEXT: [[R:%.*]] = shl i16 [[TMP1]], 5
1597 ; CHECK-NEXT: ret i16 [[R]]
1599 %x8 = mul nuw i16 %x, 32
1600 %y8 = mul nuw i16 %y, 32
1601 %r = sub i16 %x8, %y8
1604 define i32 @and_test(i32 %x, i32 %y) {
1605 ; CHECK-LABEL: @and_test(
1606 ; CHECK-NEXT: [[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
1607 ; CHECK-NEXT: ret i32 [[R]]
1615 define i32 @and_test2(i32 %x, i32 %y) {
1616 ; CHECK-LABEL: @and_test2(
1617 ; CHECK-NEXT: [[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
1618 ; CHECK-NEXT: ret i32 [[R]]
1626 define i32 @and_test3(i32 %x, i32 %y) {
1627 ; CHECK-LABEL: @and_test3(
1628 ; CHECK-NEXT: [[R:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
1629 ; CHECK-NEXT: ret i32 [[R]]
1638 define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
1639 ; CHECK-LABEL: @and_vec(
1640 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]
1641 ; CHECK-NEXT: ret <2 x i8> [[R]]
1643 %a = add <2 x i8> %X, %Y
1644 %o = or <2 x i8> %X, %Y
1645 %r = sub <2 x i8> %a, %o
1649 define i32 @or_test(i32 %x, i32 %y) {
1650 ; CHECK-LABEL: @or_test(
1651 ; CHECK-NEXT: [[R:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
1652 ; CHECK-NEXT: ret i32 [[R]]
1660 define i32 @or_test2(i32 %x, i32 %y) {
1661 ; CHECK-LABEL: @or_test2(
1662 ; CHECK-NEXT: [[R:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
1663 ; CHECK-NEXT: ret i32 [[R]]
1671 define i32 @or_test3(i32 %x, i32 %y) {
1672 ; CHECK-LABEL: @or_test3(
1673 ; CHECK-NEXT: [[R:%.*]] = or i32 [[Y:%.*]], [[X:%.*]]
1674 ; CHECK-NEXT: ret i32 [[R]]
1682 define <2 x i8> @or_vec(<2 x i8> %X, <2 x i8> %Y) {
1683 ; CHECK-LABEL: @or_vec(
1684 ; CHECK-NEXT: [[R:%.*]] = or <2 x i8> [[X:%.*]], [[Y:%.*]]
1685 ; CHECK-NEXT: ret <2 x i8> [[R]]
1687 %a = add <2 x i8> %X, %Y
1688 %b = and <2 x i8> %X, %Y
1689 %r = sub <2 x i8> %a, %b
1693 define i32 @pr51584(i32 %a, i32 %b) {
1694 ; CHECK-LABEL: @pr51584(
1695 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
1696 ; CHECK-NEXT: [[DOTNEG:%.*]] = sub i32 -11, [[TMP1]]
1697 ; CHECK-NEXT: ret i32 [[DOTNEG]]
1699 %sub = sub i32 0, %a
1700 %add = add nsw i32 11, %b
1701 %sub1 = sub i32 %sub, %add
1705 define i8 @sub_srem(i8 noundef %x, i8 %y) {
1706 ; CHECK-LABEL: @sub_srem(
1707 ; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X:%.*]], [[Y:%.*]]
1708 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 [[X]], [[REM]]
1709 ; CHECK-NEXT: ret i8 [[SUB]]
1711 %rem = srem i8 %x, %y
1712 %sub = sub i8 %x, %rem
1716 define <2 x i5> @sub_urem(<2 x i5> noundef %x, <2 x i5> %y) {
1717 ; CHECK-LABEL: @sub_urem(
1718 ; CHECK-NEXT: [[REM:%.*]] = urem <2 x i5> [[X:%.*]], [[Y:%.*]]
1719 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw <2 x i5> [[X]], [[REM]]
1720 ; CHECK-NEXT: ret <2 x i5> [[SUB]]
1722 %rem = urem <2 x i5> %x, %y
1723 %sub = sub <2 x i5> %x, %rem
1727 define <3 x i32> @nuw_const_zext(<3 x i8> %y) {
1728 ; CHECK-LABEL: @nuw_const_zext(
1729 ; CHECK-NEXT: [[ZY:%.*]] = zext <3 x i8> [[Y:%.*]] to <3 x i32>
1730 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw <3 x i32> <i32 255, i32 128, i32 0>, [[ZY]]
1731 ; CHECK-NEXT: ret <3 x i32> [[S]]
1733 %zy = zext <3 x i8> %y to <3 x i32>
1734 %s = sub nuw <3 x i32> <i32 255, i32 128, i32 0>, %zy
1738 define i32 @nuw_const_zext_big(i8 %y) {
1739 ; CHECK-LABEL: @nuw_const_zext_big(
1740 ; CHECK-NEXT: [[ZY:%.*]] = zext i8 [[Y:%.*]] to i32
1741 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i32 257, [[ZY]]
1742 ; CHECK-NEXT: ret i32 [[S]]
1744 %zy = zext i8 %y to i32
1745 %s = sub nuw i32 257, %zy
1749 define i32 @nuw_zext_zext(i8 %x, i8 %y) {
1750 ; CHECK-LABEL: @nuw_zext_zext(
1751 ; CHECK-NEXT: [[ZX:%.*]] = zext i8 [[X:%.*]] to i32
1752 ; CHECK-NEXT: [[ZY:%.*]] = zext i8 [[Y:%.*]] to i32
1753 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i32 [[ZX]], [[ZY]]
1754 ; CHECK-NEXT: ret i32 [[S]]
1756 %zx = zext i8 %x to i32
1757 %zy = zext i8 %y to i32
1758 %s = sub nuw i32 %zx, %zy
1762 define <2 x i16> @nuw_zext_sext(<2 x i8> %x, <2 x i8> %y) {
1763 ; CHECK-LABEL: @nuw_zext_sext(
1764 ; CHECK-NEXT: [[ZX:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
1765 ; CHECK-NEXT: [[SY:%.*]] = sext <2 x i8> [[Y:%.*]] to <2 x i16>
1766 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw <2 x i16> [[ZX]], [[SY]]
1767 ; CHECK-NEXT: ret <2 x i16> [[S]]
1769 %zx = zext <2 x i8> %x to <2 x i16>
1770 %sy = sext <2 x i8> %y to <2 x i16>
1771 %s = sub nuw <2 x i16> %zx, %sy
1775 define i32 @nuw_sext_zext(i8 %x, i8 %y) {
1776 ; CHECK-LABEL: @nuw_sext_zext(
1777 ; CHECK-NEXT: [[SX:%.*]] = sext i8 [[X:%.*]] to i32
1778 ; CHECK-NEXT: [[ZY:%.*]] = zext i8 [[Y:%.*]] to i32
1779 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i32 [[SX]], [[ZY]]
1780 ; CHECK-NEXT: ret i32 [[S]]
1782 %sx = sext i8 %x to i32
1783 %zy = zext i8 %y to i32
1784 %s = sub nuw i32 %sx, %zy
1788 define i8 @nuw_zext_zext_use1(i5 %x, i5 %y) {
1789 ; CHECK-LABEL: @nuw_zext_zext_use1(
1790 ; CHECK-NEXT: [[ZX:%.*]] = zext i5 [[X:%.*]] to i8
1791 ; CHECK-NEXT: call void @use8(i8 [[ZX]])
1792 ; CHECK-NEXT: [[ZY:%.*]] = zext i5 [[Y:%.*]] to i8
1793 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i8 [[ZX]], [[ZY]]
1794 ; CHECK-NEXT: ret i8 [[S]]
1796 %zx = zext i5 %x to i8
1797 call void @use8(i8 %zx)
1798 %zy = zext i5 %y to i8
1799 %s = sub nuw i8 %zx, %zy
1803 define i8 @nuw_zext_zext_use2(i5 %x, i5 %y) {
1804 ; CHECK-LABEL: @nuw_zext_zext_use2(
1805 ; CHECK-NEXT: [[ZX:%.*]] = zext i5 [[X:%.*]] to i8
1806 ; CHECK-NEXT: [[ZY:%.*]] = zext i5 [[Y:%.*]] to i8
1807 ; CHECK-NEXT: call void @use8(i8 [[ZY]])
1808 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i8 [[ZX]], [[ZY]]
1809 ; CHECK-NEXT: ret i8 [[S]]
1811 %zx = zext i5 %x to i8
1812 %zy = zext i5 %y to i8
1813 call void @use8(i8 %zy)
1814 %s = sub nuw i8 %zx, %zy
1818 define i8 @nuw_zext_zext_use3(i5 %x, i5 %y) {
1819 ; CHECK-LABEL: @nuw_zext_zext_use3(
1820 ; CHECK-NEXT: [[ZX:%.*]] = zext i5 [[X:%.*]] to i8
1821 ; CHECK-NEXT: call void @use8(i8 [[ZX]])
1822 ; CHECK-NEXT: [[ZY:%.*]] = zext i5 [[Y:%.*]] to i8
1823 ; CHECK-NEXT: call void @use8(i8 [[ZY]])
1824 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i8 [[ZX]], [[ZY]]
1825 ; CHECK-NEXT: ret i8 [[S]]
1827 %zx = zext i5 %x to i8
1828 call void @use8(i8 %zx)
1829 %zy = zext i5 %y to i8
1830 call void @use8(i8 %zy)
1831 %s = sub nuw i8 %zx, %zy
1835 define i32 @nuw_zext_zext_different_width(i8 %x, i7 %y) {
1836 ; CHECK-LABEL: @nuw_zext_zext_different_width(
1837 ; CHECK-NEXT: [[ZX:%.*]] = zext i8 [[X:%.*]] to i32
1838 ; CHECK-NEXT: [[ZY:%.*]] = zext i7 [[Y:%.*]] to i32
1839 ; CHECK-NEXT: [[S:%.*]] = sub nuw nsw i32 [[ZX]], [[ZY]]
1840 ; CHECK-NEXT: ret i32 [[S]]
1842 %zx = zext i8 %x to i32
1843 %zy = zext i7 %y to i32
1844 %s = sub nuw i32 %zx, %zy
1848 define i16 @sext_nsw_noundef(i8 noundef %x, i8 %y) {
1849 ; CHECK-LABEL: @sext_nsw_noundef(
1850 ; CHECK-NEXT: [[Z:%.*]] = sext i8 [[Y:%.*]] to i16
1851 ; CHECK-NEXT: ret i16 [[Z]]
1853 %d = sub nsw i8 %x, %y
1854 %ex = sext i8 %x to i16
1855 %ed = sext i8 %d to i16
1856 %z = sub i16 %ex, %ed
1860 ; negative test - requires noundef
1862 define i16 @sext_nsw(i8 %x, i8 %y) {
1863 ; CHECK-LABEL: @sext_nsw(
1864 ; CHECK-NEXT: [[D:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
1865 ; CHECK-NEXT: [[EX:%.*]] = sext i8 [[X]] to i16
1866 ; CHECK-NEXT: [[ED:%.*]] = sext i8 [[D]] to i16
1867 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
1868 ; CHECK-NEXT: ret i16 [[Z]]
1870 %d = sub nsw i8 %x, %y
1871 %ex = sext i8 %x to i16
1872 %ed = sext i8 %d to i16
1873 %z = sub i16 %ex, %ed
1877 ; negative test - requires nsw
1879 define i16 @sext_noundef(i8 noundef %x, i8 %y) {
1880 ; CHECK-LABEL: @sext_noundef(
1881 ; CHECK-NEXT: [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
1882 ; CHECK-NEXT: [[EX:%.*]] = sext i8 [[X]] to i16
1883 ; CHECK-NEXT: [[ED:%.*]] = sext i8 [[D]] to i16
1884 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
1885 ; CHECK-NEXT: ret i16 [[Z]]
1888 %ex = sext i8 %x to i16
1889 %ed = sext i8 %d to i16
1890 %z = sub i16 %ex, %ed
1894 ; negative test - must have common operand
1896 define i16 @sext_nsw_noundef_wrong_val(i8 noundef %x, i8 noundef %y, i8 noundef %q) {
1897 ; CHECK-LABEL: @sext_nsw_noundef_wrong_val(
1898 ; CHECK-NEXT: [[D:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
1899 ; CHECK-NEXT: [[EQ:%.*]] = sext i8 [[Q:%.*]] to i16
1900 ; CHECK-NEXT: [[ED:%.*]] = sext i8 [[D]] to i16
1901 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i16 [[EQ]], [[ED]]
1902 ; CHECK-NEXT: ret i16 [[Z]]
1904 %d = sub nsw i8 %x, %y
1905 %eq = sext i8 %q to i16
1906 %ed = sext i8 %d to i16
1907 %z = sub i16 %eq, %ed
1911 ; two no-wrap analyses combine to allow reduction
1913 define i16 @srem_sext_noundef(i8 noundef %x, i8 %y) {
1914 ; CHECK-LABEL: @srem_sext_noundef(
1915 ; CHECK-NEXT: [[R:%.*]] = srem i8 [[X:%.*]], [[Y:%.*]]
1916 ; CHECK-NEXT: [[Z:%.*]] = sext i8 [[R]] to i16
1917 ; CHECK-NEXT: ret i16 [[Z]]
1921 %sd = sext i8 %d to i16
1922 %sx = sext i8 %x to i16
1923 %z = sub i16 %sx, %sd
1927 define i16 @zext_nuw_noundef(i8 noundef %x, i8 %y) {
1928 ; CHECK-LABEL: @zext_nuw_noundef(
1929 ; CHECK-NEXT: [[Z:%.*]] = zext i8 [[Y:%.*]] to i16
1930 ; CHECK-NEXT: ret i16 [[Z]]
1932 %d = sub nuw i8 %x, %y
1933 %ex = zext i8 %x to i16
1934 %ed = zext i8 %d to i16
1935 %z = sub i16 %ex, %ed
1939 ; negative test - requires noundef
1941 define i16 @zext_nuw(i8 %x, i8 %y) {
1942 ; CHECK-LABEL: @zext_nuw(
1943 ; CHECK-NEXT: [[D:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
1944 ; CHECK-NEXT: [[EX:%.*]] = zext i8 [[X]] to i16
1945 ; CHECK-NEXT: [[ED:%.*]] = zext i8 [[D]] to i16
1946 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
1947 ; CHECK-NEXT: ret i16 [[Z]]
1949 %d = sub nuw i8 %x, %y
1950 %ex = zext i8 %x to i16
1951 %ed = zext i8 %d to i16
1952 %z = sub i16 %ex, %ed
1956 ; negative test - requires nuw
1958 define i16 @zext_noundef(i8 noundef %x, i8 %y) {
1959 ; CHECK-LABEL: @zext_noundef(
1960 ; CHECK-NEXT: [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
1961 ; CHECK-NEXT: [[EX:%.*]] = zext i8 [[X]] to i16
1962 ; CHECK-NEXT: [[ED:%.*]] = zext i8 [[D]] to i16
1963 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i16 [[EX]], [[ED]]
1964 ; CHECK-NEXT: ret i16 [[Z]]
1967 %ex = zext i8 %x to i16
1968 %ed = zext i8 %d to i16
1969 %z = sub i16 %ex, %ed
1973 ; negative test - must have common operand
1975 define i16 @zext_nsw_noundef_wrong_val(i8 noundef %x, i8 noundef %y, i8 noundef %q) {
1976 ; CHECK-LABEL: @zext_nsw_noundef_wrong_val(
1977 ; CHECK-NEXT: [[D:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
1978 ; CHECK-NEXT: [[EQ:%.*]] = zext i8 [[Q:%.*]] to i16
1979 ; CHECK-NEXT: [[ED:%.*]] = zext i8 [[D]] to i16
1980 ; CHECK-NEXT: [[Z:%.*]] = sub nsw i16 [[EQ]], [[ED]]
1981 ; CHECK-NEXT: ret i16 [[Z]]
1983 %d = sub nuw i8 %x, %y
1984 %eq = zext i8 %q to i16
1985 %ed = zext i8 %d to i16
1986 %z = sub i16 %eq, %ed
1990 ; two no-wrap analyses combine to allow reduction
1992 define i16 @urem_zext_noundef(i8 noundef %x, i8 %y) {
1993 ; CHECK-LABEL: @urem_zext_noundef(
1994 ; CHECK-NEXT: [[R:%.*]] = urem i8 [[X:%.*]], [[Y:%.*]]
1995 ; CHECK-NEXT: [[Z:%.*]] = zext i8 [[R]] to i16
1996 ; CHECK-NEXT: ret i16 [[Z]]
2000 %ed = zext i8 %d to i16
2001 %ex = zext i8 %x to i16
2002 %z = sub i16 %ex, %ed
2006 ; x * y - x --> (y - 1) * x
2007 ; TODO: The mul could retain nsw.
2009 define i8 @mul_sub_common_factor_commute1(i8 %x, i8 %y) {
2010 ; CHECK-LABEL: @mul_sub_common_factor_commute1(
2011 ; CHECK-NEXT: [[X1:%.*]] = add i8 [[Y:%.*]], -1
2012 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X1]], [[X:%.*]]
2013 ; CHECK-NEXT: ret i8 [[A]]
2015 %m = mul nsw i8 %x, %y
2016 %a = sub nsw i8 %m, %x
2020 ; TODO: The mul could retain nuw.
2022 define <2 x i8> @mul_sub_common_factor_commute2(<2 x i8> %x, <2 x i8> %y) {
2023 ; CHECK-LABEL: @mul_sub_common_factor_commute2(
2024 ; CHECK-NEXT: [[M1:%.*]] = add <2 x i8> [[Y:%.*]], <i8 -1, i8 -1>
2025 ; CHECK-NEXT: [[A:%.*]] = mul <2 x i8> [[M1]], [[X:%.*]]
2026 ; CHECK-NEXT: ret <2 x i8> [[A]]
2028 %m = mul nuw <2 x i8> %y, %x
2029 %a = sub nuw <2 x i8> %m, %x
2033 ; x - (x * y) --> (1 - y) * x
2035 define i8 @mul_sub_common_factor_commute3(i8 %x, i8 %y) {
2036 ; CHECK-LABEL: @mul_sub_common_factor_commute3(
2037 ; CHECK-NEXT: [[M1:%.*]] = sub i8 1, [[Y:%.*]]
2038 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[M1]], [[X:%.*]]
2039 ; CHECK-NEXT: ret i8 [[A]]
2041 %m = mul nuw i8 %x, %y
2042 %a = sub nsw i8 %x, %m
2046 define i8 @mul_sub_common_factor_commute4(i8 %x, i8 %y) {
2047 ; CHECK-LABEL: @mul_sub_common_factor_commute4(
2048 ; CHECK-NEXT: [[M1:%.*]] = sub i8 1, [[Y:%.*]]
2049 ; CHECK-NEXT: [[A:%.*]] = mul i8 [[M1]], [[X:%.*]]
2050 ; CHECK-NEXT: ret i8 [[A]]
2052 %m = mul nsw i8 %y, %x
2053 %a = sub nuw i8 %x, %m
2057 ; negative test - uses
2059 define i8 @mul_sub_common_factor_use(i8 %x, i8 %y) {
2060 ; CHECK-LABEL: @mul_sub_common_factor_use(
2061 ; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
2062 ; CHECK-NEXT: call void @use8(i8 [[M]])
2063 ; CHECK-NEXT: [[A:%.*]] = sub i8 [[M]], [[X]]
2064 ; CHECK-NEXT: ret i8 [[A]]
2067 call void @use8(i8 %m)
2072 define i5 @demand_low_bits_uses(i8 %x, i8 %y) {
2073 ; CHECK-LABEL: @demand_low_bits_uses(
2074 ; CHECK-NEXT: [[M:%.*]] = and i8 [[X:%.*]], 96
2075 ; CHECK-NEXT: [[A:%.*]] = sub i8 [[Y:%.*]], [[M]]
2076 ; CHECK-NEXT: call void @use8(i8 [[A]])
2077 ; CHECK-NEXT: [[R:%.*]] = trunc i8 [[Y]] to i5
2078 ; CHECK-NEXT: ret i5 [[R]]
2080 %m = and i8 %x, 96 ; 0x60
2082 call void @use8(i8 %a)
2083 %r = trunc i8 %a to i5
2087 ; negative test - demands one more bit
2089 define i6 @demand_low_bits_uses_extra_bit(i8 %x, i8 %y) {
2090 ; CHECK-LABEL: @demand_low_bits_uses_extra_bit(
2091 ; CHECK-NEXT: [[M:%.*]] = and i8 [[X:%.*]], 96
2092 ; CHECK-NEXT: [[A:%.*]] = sub i8 [[Y:%.*]], [[M]]
2093 ; CHECK-NEXT: call void @use8(i8 [[A]])
2094 ; CHECK-NEXT: [[R:%.*]] = trunc i8 [[A]] to i6
2095 ; CHECK-NEXT: ret i6 [[R]]
2097 %m = and i8 %x, 96 ; 0x60
2099 call void @use8(i8 %a)
2100 %r = trunc i8 %a to i6
2104 ; negative test - must be operand 1
2106 define i8 @demand_low_bits_uses_commute(i8 %x, i8 %y, i8 %z) {
2107 ; CHECK-LABEL: @demand_low_bits_uses_commute(
2108 ; CHECK-NEXT: [[M:%.*]] = and i8 [[X:%.*]], -64
2109 ; CHECK-NEXT: [[A:%.*]] = sub i8 [[M]], [[Y:%.*]]
2110 ; CHECK-NEXT: call void @use8(i8 [[A]])
2111 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[Z:%.*]]
2112 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[S]], 2
2113 ; CHECK-NEXT: ret i8 [[R]]
2115 %m = and i8 %x, -64 ; 0xC0
2117 call void @use8(i8 %a)
2123 ; sub becomes negate and combines with shl
2125 define i8 @shrink_sub_from_constant_lowbits(i8 %x) {
2126 ; CHECK-LABEL: @shrink_sub_from_constant_lowbits(
2127 ; CHECK-NEXT: [[X000_NEG:%.*]] = mul i8 [[X:%.*]], -8
2128 ; CHECK-NEXT: ret i8 [[X000_NEG]]
2130 %x000 = shl i8 %x, 3 ; 3 low bits are known zero
2131 %sub = sub i8 7, %x000
2132 %r = and i8 %sub, -8 ; 3 low bits are not demanded
2136 ; negative test - extra use prevents shrinking '7'
2138 define i8 @shrink_sub_from_constant_lowbits_uses(i8 %x) {
2139 ; CHECK-LABEL: @shrink_sub_from_constant_lowbits_uses(
2140 ; CHECK-NEXT: [[X000:%.*]] = shl i8 [[X:%.*]], 3
2141 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 7, [[X000]]
2142 ; CHECK-NEXT: call void @use8(i8 [[SUB]])
2143 ; CHECK-NEXT: [[R:%.*]] = and i8 [[SUB]], -8
2144 ; CHECK-NEXT: ret i8 [[R]]
2146 %x000 = shl i8 %x, 3 ; 3 low bits are known zero
2147 %sub = sub i8 7, %x000
2148 call void @use8(i8 %sub)
2149 %r = and i8 %sub, -8 ; 3 low bits are not demanded
2153 ; safe to clear 3 low bits (2 higher bits remain set)
2155 define i8 @shrink_sub_from_constant_lowbits2(i8 %x) {
2156 ; CHECK-LABEL: @shrink_sub_from_constant_lowbits2(
2157 ; CHECK-NEXT: [[X000:%.*]] = and i8 [[X:%.*]], -8
2158 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 24, [[X000]]
2159 ; CHECK-NEXT: [[R:%.*]] = and i8 [[SUB]], -16
2160 ; CHECK-NEXT: ret i8 [[R]]
2162 %x000 = and i8 %x, -8 ; 3 low bits are known zero
2163 %sub = sub nsw i8 30, %x000 ; 0b0001_1110
2164 %r = and i8 %sub, -16 ; 4 low bits are not demanded
2168 ; safe to clear 3 low bits (2 higher bits remain set)
2170 define <2 x i8> @shrink_sub_from_constant_lowbits3(<2 x i8> %x) {
2171 ; CHECK-LABEL: @shrink_sub_from_constant_lowbits3(
2172 ; CHECK-NEXT: [[X0000:%.*]] = shl <2 x i8> [[X:%.*]], <i8 4, i8 4>
2173 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw <2 x i8> <i8 24, i8 24>, [[X0000]]
2174 ; CHECK-NEXT: [[R:%.*]] = lshr exact <2 x i8> [[SUB]], <i8 3, i8 3>
2175 ; CHECK-NEXT: ret <2 x i8> [[R]]
2177 %x0000 = shl <2 x i8> %x, <i8 4, i8 4> ; 4 low bits are known zero
2178 %sub = sub nuw <2 x i8> <i8 31, i8 31>, %x0000
2179 %r = lshr <2 x i8> %sub, <i8 3, i8 3> ; 3 low bits are not demanded
2183 ; eliminate the mask of y or the mask of the result
2185 define i8 @demand_sub_from_variable_lowbits(i8 %x, i8 %y) {
2186 ; CHECK-LABEL: @demand_sub_from_variable_lowbits(
2187 ; CHECK-NEXT: [[X000:%.*]] = shl i8 [[X:%.*]], 3
2188 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[Y:%.*]], [[X000]]
2189 ; CHECK-NEXT: [[R:%.*]] = and i8 [[SUB]], -8
2190 ; CHECK-NEXT: ret i8 [[R]]
2192 %x000 = shl i8 %x, 3 ; 3 low bits are known zero
2193 %y000 = and i8 %y, -8
2194 %sub = sub i8 %y000, %x000
2195 %r = and i8 %sub, -8 ; 3 low bits are not demanded
2199 ; setting the low 3 bits of y doesn't change anything
2201 define i8 @demand_sub_from_variable_lowbits2(i8 %x, i8 %y) {
2202 ; CHECK-LABEL: @demand_sub_from_variable_lowbits2(
2203 ; CHECK-NEXT: [[X0000:%.*]] = shl i8 [[X:%.*]], 4
2204 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i8 [[Y:%.*]], [[X0000]]
2205 ; CHECK-NEXT: [[R:%.*]] = lshr i8 [[SUB]], 4
2206 ; CHECK-NEXT: ret i8 [[R]]
2208 %x0000 = shl i8 %x, 4 ; 4 low bits are known zero
2210 %sub = sub nsw nuw i8 %y111, %x0000
2211 %r = lshr i8 %sub, 4 ; 4 low bits are not demanded
2215 ; negative test - the mask of y removes an extra bit, so that instruction is needed
2217 define i8 @demand_sub_from_variable_lowbits3(i8 %x, i8 %y) {
2218 ; CHECK-LABEL: @demand_sub_from_variable_lowbits3(
2219 ; CHECK-NEXT: [[X0000:%.*]] = shl i8 [[X:%.*]], 4
2220 ; CHECK-NEXT: [[Y00000:%.*]] = and i8 [[Y:%.*]], -32
2221 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[Y00000]], [[X0000]]
2222 ; CHECK-NEXT: [[R:%.*]] = lshr exact i8 [[SUB]], 4
2223 ; CHECK-NEXT: ret i8 [[R]]
2225 %x0000 = shl i8 %x, 4 ; 4 low bits are known zero
2226 %y00000 = and i8 %y, -32
2227 %sub = sub i8 %y00000, %x0000
2228 %r = lshr i8 %sub, 4 ; 4 low bits are not demanded
2232 ; C - ((C3 - X) & C2) --> (C - (C2 & C3)) + (X & C2) when:
2233 ; (C3 - ((C2 & C3) - 1)) is pow2
2234 ; ((C2 + C3) & ((C2 & C3) - 1)) == ((C2 & C3) - 1)
2235 ; C2 is negative pow2
2236 define i10 @sub_to_and_nuw(i10 %x) {
2237 ; CHECK-LABEL: @sub_to_and_nuw(
2238 ; CHECK-NEXT: [[TMP1:%.*]] = and i10 [[X:%.*]], 120
2239 ; CHECK-NEXT: [[R:%.*]] = add nuw nsw i10 [[TMP1]], 379
2240 ; CHECK-NEXT: ret i10 [[R]]
2242 %sub = sub nuw i10 71, %x
2243 %and = and i10 %sub, 120
2244 %r = sub i10 443, %and
2248 ; C - ((C3 -nuw X) & C2) --> (C - (C2 & C3)) + (X & C2) when:
2249 ; (C3 - ((C2 & C3) - 1)) is pow2
2250 ; ((C2 + C3) & ((C2 & C3) - 1)) == ((C2 & C3) - 1)
2251 define i10 @sub_to_and_negpow2(i10 %x) {
2252 ; CHECK-LABEL: @sub_to_and_negpow2(
2253 ; CHECK-NEXT: [[TMP1:%.*]] = and i10 [[X:%.*]], -8
2254 ; CHECK-NEXT: [[R:%.*]] = add i10 [[TMP1]], -31
2255 ; CHECK-NEXT: ret i10 [[R]]
2257 %sub = sub i10 71, %x
2258 %and = and i10 %sub, -8
2259 %r = sub i10 33, %and
2264 ; C + ((C3 -nuw X) & C2) --> (C + (C2 & C3)) - (X & C2) when:
2265 define i10 @add_to_and_nuw(i10 %x) {
2266 ; CHECK-LABEL: @add_to_and_nuw(
2267 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i10 71, [[X:%.*]]
2268 ; CHECK-NEXT: [[AND:%.*]] = and i10 [[SUB]], 120
2269 ; CHECK-NEXT: [[R:%.*]] = add nuw nsw i10 [[AND]], 224
2270 ; CHECK-NEXT: ret i10 [[R]]
2272 %sub = sub nuw i10 71, %x
2273 %and = and i10 %sub, 120
2274 %r = add i10 224, %and
2278 ; (C3 - (C2 & C3) + 1) is not pow2
2279 define i10 @sub_to_and_negative1(i10 %x) {
2280 ; CHECK-LABEL: @sub_to_and_negative1(
2281 ; CHECK-NEXT: [[SUB:%.*]] = sub i10 71, [[X:%.*]]
2282 ; CHECK-NEXT: [[AND:%.*]] = and i10 [[SUB]], 248
2283 ; CHECK-NEXT: [[R:%.*]] = sub nuw nsw i10 444, [[AND]]
2284 ; CHECK-NEXT: ret i10 [[R]]
2286 %sub = sub nuw i10 327, %x
2287 %and = and i10 %sub, 248
2288 %r = sub i10 444, %and
2292 ; ((C2 + C3) & ((C2 & C3) - 1)) == ((C2 & C3) - 1)
2293 define i10 @sub_to_and_negative2(i10 %x) {
2294 ; CHECK-LABEL: @sub_to_and_negative2(
2295 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i10 71, [[X:%.*]]
2296 ; CHECK-NEXT: [[AND:%.*]] = and i10 [[SUB]], 88
2297 ; CHECK-NEXT: [[R:%.*]] = sub nsw i10 64, [[AND]]
2298 ; CHECK-NEXT: ret i10 [[R]]
2300 %sub = sub nuw i10 71, %x
2301 %and = and i10 %sub, 88
2302 %r = sub i10 64, %and
2306 ; no nuw && C2 is not neg-pow2
2307 define i10 @sub_to_and_negative3(i10 %x) {
2308 ; CHECK-LABEL: @sub_to_and_negative3(
2309 ; CHECK-NEXT: [[SUB:%.*]] = sub i10 71, [[X:%.*]]
2310 ; CHECK-NEXT: [[AND:%.*]] = and i10 [[SUB]], 120
2311 ; CHECK-NEXT: [[R:%.*]] = sub nsw i10 64, [[AND]]
2312 ; CHECK-NEXT: ret i10 [[R]]
2314 %sub = sub i10 71, %x
2315 %and = and i10 %sub, 120
2316 %r = sub i10 64, %and
2320 declare void @use10(i10)
2322 ; and is not one-use
2323 define i10 @sub_to_and_negative4(i10 %x) {
2324 ; CHECK-LABEL: @sub_to_and_negative4(
2325 ; CHECK-NEXT: [[SUB:%.*]] = sub i10 71, [[X:%.*]]
2326 ; CHECK-NEXT: [[AND:%.*]] = and i10 [[SUB]], 120
2327 ; CHECK-NEXT: [[R:%.*]] = sub nsw i10 64, [[AND]]
2328 ; CHECK-NEXT: call void @use10(i10 [[AND]])
2329 ; CHECK-NEXT: ret i10 [[R]]
2331 %sub = sub i10 71, %x
2332 %and = and i10 %sub, 120
2333 %r = sub i10 64, %and
2334 call void @use10(i10 %and)
2339 define <2 x i8> @sub_to_and_vector1(<2 x i8> %x) {
2340 ; CHECK-LABEL: @sub_to_and_vector1(
2341 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 120, i8 120>
2342 ; CHECK-NEXT: [[R:%.*]] = add nsw <2 x i8> [[TMP1]], <i8 -9, i8 -9>
2343 ; CHECK-NEXT: ret <2 x i8> [[R]]
2345 %sub = sub nuw <2 x i8> <i8 71, i8 71>, %x
2346 %and = and <2 x i8> %sub, <i8 120, i8 120>
2347 %r = sub <2 x i8> <i8 55, i8 55>, %and
2352 define <2 x i8> @sub_to_and_vector2(<2 x i8> %x) {
2353 ; CHECK-LABEL: @sub_to_and_vector2(
2354 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw <2 x i8> <i8 71, i8 undef>, [[X:%.*]]
2355 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[SUB]], <i8 120, i8 120>
2356 ; CHECK-NEXT: [[R:%.*]] = sub nsw <2 x i8> <i8 77, i8 77>, [[AND]]
2357 ; CHECK-NEXT: ret <2 x i8> [[R]]
2359 %sub = sub nuw <2 x i8> <i8 71, i8 undef>, %x
2360 %and = and <2 x i8> %sub, <i8 120, i8 120>
2361 %r = sub <2 x i8> <i8 77, i8 77>, %and
2366 define <2 x i8> @sub_to_and_vector3(<2 x i8> %x) {
2367 ; CHECK-LABEL: @sub_to_and_vector3(
2368 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw <2 x i8> <i8 71, i8 71>, [[X:%.*]]
2369 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[SUB]], <i8 120, i8 undef>
2370 ; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> <i8 44, i8 44>, [[AND]]
2371 ; CHECK-NEXT: ret <2 x i8> [[R]]
2373 %sub = sub nuw <2 x i8> <i8 71, i8 71>, %x
2374 %and = and <2 x i8> %sub, <i8 120, i8 undef>
2375 %r = sub <2 x i8> <i8 44, i8 44>, %and
2380 define <2 x i8> @sub_to_and_vector4(<2 x i8> %x) {
2381 ; CHECK-LABEL: @sub_to_and_vector4(
2382 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw <2 x i8> <i8 71, i8 71>, [[X:%.*]]
2383 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[SUB]], <i8 120, i8 120>
2384 ; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> <i8 88, i8 undef>, [[AND]]
2385 ; CHECK-NEXT: ret <2 x i8> [[R]]
2387 %sub = sub nuw <2 x i8> <i8 71, i8 71>, %x
2388 %and = and <2 x i8> %sub, <i8 120, i8 120>
2389 %r = sub <2 x i8> <i8 88, i8 undef>, %and
2393 ; (X * X) - (Y * Y) --> (X + Y) * (X - Y)
2395 define i8 @diff_of_squares(i8 %x, i8 %y) {
2396 ; CHECK-LABEL: @diff_of_squares(
2397 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
2398 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[Y]]
2399 ; CHECK-NEXT: [[R:%.*]] = mul i8 [[ADD]], [[SUB]]
2400 ; CHECK-NEXT: ret i8 [[R]]
2404 %r = sub i8 %x2, %y2
2408 ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2410 define i5 @diff_of_squares_nuw(i5 %x, i5 %y) {
2411 ; CHECK-LABEL: @diff_of_squares_nuw(
2412 ; CHECK-NEXT: [[ADD:%.*]] = add nuw i5 [[X:%.*]], [[Y:%.*]]
2413 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i5 [[X]], [[Y]]
2414 ; CHECK-NEXT: [[R:%.*]] = mul nuw i5 [[ADD]], [[SUB]]
2415 ; CHECK-NEXT: ret i5 [[R]]
2417 %x2 = mul nuw i5 %x, %x
2418 %y2 = mul nuw i5 %y, %y
2419 %r = sub nuw i5 %x2, %y2
2423 ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2425 define i5 @diff_of_squares_partial_nuw(i5 %x, i5 %y) {
2426 ; CHECK-LABEL: @diff_of_squares_partial_nuw(
2427 ; CHECK-NEXT: [[ADD:%.*]] = add i5 [[X:%.*]], [[Y:%.*]]
2428 ; CHECK-NEXT: [[SUB:%.*]] = sub i5 [[X]], [[Y]]
2429 ; CHECK-NEXT: [[R:%.*]] = mul i5 [[ADD]], [[SUB]]
2430 ; CHECK-NEXT: ret i5 [[R]]
2432 %x2 = mul nuw i5 %x, %x
2433 %y2 = mul nuw i5 %y, %y
2434 %r = sub i5 %x2, %y2
2438 ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2440 define <2 x i5> @diff_of_squares_nsw(<2 x i5> %x, <2 x i5> %y) {
2441 ; CHECK-LABEL: @diff_of_squares_nsw(
2442 ; CHECK-NEXT: [[ADD:%.*]] = add nsw <2 x i5> [[X:%.*]], [[Y:%.*]]
2443 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i5> [[X]], [[Y]]
2444 ; CHECK-NEXT: [[R:%.*]] = mul nsw <2 x i5> [[ADD]], [[SUB]]
2445 ; CHECK-NEXT: ret <2 x i5> [[R]]
2447 %x2 = mul nsw <2 x i5> %x, %x
2448 %y2 = mul nsw <2 x i5> %y, %y
2449 %r = sub nsw <2 x i5> %x2, %y2
2453 ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2455 define <2 x i5> @diff_of_squares_partial_nsw(<2 x i5> %x, <2 x i5> %y) {
2456 ; CHECK-LABEL: @diff_of_squares_partial_nsw(
2457 ; CHECK-NEXT: [[ADD:%.*]] = add <2 x i5> [[X:%.*]], [[Y:%.*]]
2458 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i5> [[X]], [[Y]]
2459 ; CHECK-NEXT: [[R:%.*]] = mul <2 x i5> [[ADD]], [[SUB]]
2460 ; CHECK-NEXT: ret <2 x i5> [[R]]
2462 %x2 = mul nsw <2 x i5> %x, %x
2463 %y2 = mul <2 x i5> %y, %y
2464 %r = sub nsw <2 x i5> %x2, %y2
2468 define i1 @diff_of_squares_nsw_i1(i1 %x, i1 %y) {
2469 ; CHECK-LABEL: @diff_of_squares_nsw_i1(
2470 ; CHECK-NEXT: ret i1 false
2472 %x2 = mul nsw i1 %x, %x
2473 %y2 = mul nsw i1 %y, %y
2474 %r = sub nsw i1 %x2, %y2
2478 define i1 @diff_of_squares_nuw_i1(i1 %x, i1 %y) {
2479 ; CHECK-LABEL: @diff_of_squares_nuw_i1(
2480 ; CHECK-NEXT: [[R:%.*]] = xor i1 [[Y:%.*]], [[X:%.*]]
2481 ; CHECK-NEXT: ret i1 [[R]]
2483 %x2 = mul nuw i1 %x, %x
2484 %y2 = mul nuw i1 %y, %y
2485 %r = sub nuw i1 %x2, %y2
2489 ; It is not correct to propagate nsw.
2490 ; TODO: This should reduce more.
2492 define i2 @diff_of_squares_nsw_i2(i2 %x, i2 %y) {
2493 ; CHECK-LABEL: @diff_of_squares_nsw_i2(
2494 ; CHECK-NEXT: [[ADD:%.*]] = add i2 [[X:%.*]], [[Y:%.*]]
2495 ; CHECK-NEXT: [[SUB:%.*]] = sub i2 [[X]], [[Y]]
2496 ; CHECK-NEXT: [[R:%.*]] = mul i2 [[ADD]], [[SUB]]
2497 ; CHECK-NEXT: ret i2 [[R]]
2499 %x2 = mul nsw i2 %x, %x
2500 %y2 = mul nsw i2 %y, %y
2501 %r = sub nsw i2 %x2, %y2
2505 ; TODO: This should reduce more.
2507 define i2 @diff_of_squares_nuw_i2(i2 %x, i2 %y) {
2508 ; CHECK-LABEL: @diff_of_squares_nuw_i2(
2509 ; CHECK-NEXT: [[ADD:%.*]] = add nuw i2 [[X:%.*]], [[Y:%.*]]
2510 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i2 [[X]], [[Y]]
2511 ; CHECK-NEXT: [[R:%.*]] = mul nuw i2 [[ADD]], [[SUB]]
2512 ; CHECK-NEXT: ret i2 [[R]]
2514 %x2 = mul nuw i2 %x, %x
2515 %y2 = mul nuw i2 %y, %y
2516 %r = sub nuw i2 %x2, %y2
2522 define i8 @diff_of_squares_use1(i8 %x, i8 %y) {
2523 ; CHECK-LABEL: @diff_of_squares_use1(
2524 ; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
2525 ; CHECK-NEXT: call void @use8(i8 [[X2]])
2526 ; CHECK-NEXT: [[Y2:%.*]] = mul i8 [[Y:%.*]], [[Y]]
2527 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2]], [[Y2]]
2528 ; CHECK-NEXT: ret i8 [[R]]
2531 call void @use8(i8 %x2)
2533 %r = sub i8 %x2, %y2
2539 define i8 @diff_of_squares_use2(i8 %x, i8 %y) {
2540 ; CHECK-LABEL: @diff_of_squares_use2(
2541 ; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
2542 ; CHECK-NEXT: [[Y2:%.*]] = mul i8 [[Y:%.*]], [[Y]]
2543 ; CHECK-NEXT: call void @use8(i8 [[Y2]])
2544 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2]], [[Y2]]
2545 ; CHECK-NEXT: ret i8 [[R]]
2549 call void @use8(i8 %y2)
2550 %r = sub i8 %x2, %y2
2554 ; negative test - must be squares
2556 define i8 @diff_of_muls1(i8 %x, i8 %y, i8 %z) {
2557 ; CHECK-LABEL: @diff_of_muls1(
2558 ; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Z:%.*]]
2559 ; CHECK-NEXT: [[Y2:%.*]] = mul i8 [[Y:%.*]], [[Y]]
2560 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[M]], [[Y2]]
2561 ; CHECK-NEXT: ret i8 [[R]]
2569 ; negative test - must be squares
2571 define i8 @diff_of_muls2(i8 %x, i8 %y, i8 %z) {
2572 ; CHECK-LABEL: @diff_of_muls2(
2573 ; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
2574 ; CHECK-NEXT: [[M:%.*]] = mul i8 [[Y:%.*]], [[Z:%.*]]
2575 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2]], [[M]]
2576 ; CHECK-NEXT: ret i8 [[R]]
2584 define i8 @sub_of_adds_2xz_multiuse(i8 %x, i8 %y, i8 %z) {
2585 ; CHECK-LABEL: @sub_of_adds_2xz_multiuse(
2586 ; CHECK-NEXT: [[XZ:%.*]] = add i8 [[X:%.*]], [[Z:%.*]]
2587 ; CHECK-NEXT: [[YZ:%.*]] = add i8 [[Z]], [[Y:%.*]]
2588 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[Y]]
2589 ; CHECK-NEXT: call void @use8(i8 [[XZ]])
2590 ; CHECK-NEXT: call void @use8(i8 [[YZ]])
2591 ; CHECK-NEXT: ret i8 [[R]]
2595 %r = sub i8 %xz, %yz
2596 call void @use8(i8 %xz)
2597 call void @use8(i8 %yz)
2601 define i8 @sub_of_adds_2xc_multiuse2_fail(i8 %x, i8 %y) {
2602 ; CHECK-LABEL: @sub_of_adds_2xc_multiuse2_fail(
2603 ; CHECK-NEXT: [[XC:%.*]] = add i8 [[X:%.*]], 10
2604 ; CHECK-NEXT: [[YC:%.*]] = add i8 [[Y:%.*]], 11
2605 ; CHECK-NEXT: [[R:%.*]] = sub i8 [[XC]], [[YC]]
2606 ; CHECK-NEXT: call void @use8(i8 [[XC]])
2607 ; CHECK-NEXT: call void @use8(i8 [[YC]])
2608 ; CHECK-NEXT: ret i8 [[R]]
2612 %r = sub i8 %xc, %yc
2613 call void @use8(i8 %xc)
2614 call void @use8(i8 %yc)
2618 define i8 @sub_of_adds_2xc(i8 %x, i8 %y) {
2619 ; CHECK-LABEL: @sub_of_adds_2xc(
2620 ; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
2621 ; CHECK-NEXT: [[R:%.*]] = add i8 [[TMP1]], 2
2622 ; CHECK-NEXT: ret i8 [[R]]
2626 %r = sub i8 %xc, %yc