@@ -2390,11 +2390,13 @@ define <2 x i8> @sub_to_and_vector4(<2 x i8> %x) {
2390
2390
ret <2 x i8 > %r
2391
2391
}
2392
2392
2393
+ ; (X * X) - (Y * Y) --> (X + Y) * (X - Y)
2394
+
2393
2395
define i8 @diff_of_squares (i8 %x , i8 %y ) {
2394
2396
; CHECK-LABEL: @diff_of_squares(
2395
- ; CHECK-NEXT: [[X2 :%.*]] = mul i8 [[X:%.*]], [[X ]]
2396
- ; CHECK-NEXT: [[Y2 :%.*]] = mul i8 [[Y:%.* ]], [[Y]]
2397
- ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2 ]], [[Y2 ]]
2397
+ ; CHECK-NEXT: [[ADD :%.*]] = add i8 [[X:%.*]], [[Y:%.* ]]
2398
+ ; CHECK-NEXT: [[SUB :%.*]] = sub i8 [[X ]], [[Y]]
2399
+ ; CHECK-NEXT: [[R:%.*]] = mul i8 [[ADD ]], [[SUB ]]
2398
2400
; CHECK-NEXT: ret i8 [[R]]
2399
2401
;
2400
2402
%x2 = mul i8 %x , %x
@@ -2403,11 +2405,13 @@ define i8 @diff_of_squares(i8 %x, i8 %y) {
2403
2405
ret i8 %r
2404
2406
}
2405
2407
2408
+ ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2409
+
2406
2410
define i5 @diff_of_squares_nuw (i5 %x , i5 %y ) {
2407
2411
; CHECK-LABEL: @diff_of_squares_nuw(
2408
- ; CHECK-NEXT: [[X2 :%.*]] = mul nuw i5 [[X:%.*]], [[X ]]
2409
- ; CHECK-NEXT: [[Y2 :%.*]] = mul nuw i5 [[Y:%.* ]], [[Y]]
2410
- ; CHECK-NEXT: [[R:%.*]] = sub nuw i5 [[X2 ]], [[Y2 ]]
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 ]]
2411
2415
; CHECK-NEXT: ret i5 [[R]]
2412
2416
;
2413
2417
%x2 = mul nuw i5 %x , %x
@@ -2416,11 +2420,13 @@ define i5 @diff_of_squares_nuw(i5 %x, i5 %y) {
2416
2420
ret i5 %r
2417
2421
}
2418
2422
2423
+ ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2424
+
2419
2425
define i5 @diff_of_squares_partial_nuw (i5 %x , i5 %y ) {
2420
2426
; CHECK-LABEL: @diff_of_squares_partial_nuw(
2421
- ; CHECK-NEXT: [[X2 :%.*]] = mul nuw i5 [[X:%.*]], [[X ]]
2422
- ; CHECK-NEXT: [[Y2 :%.*]] = mul nuw i5 [[Y:%.* ]], [[Y]]
2423
- ; CHECK-NEXT: [[R:%.*]] = sub i5 [[X2 ]], [[Y2 ]]
2427
+ ; CHECK-NEXT: [[ADD :%.*]] = add i5 [[X:%.*]], [[Y:%.* ]]
2428
+ ; CHECK-NEXT: [[SUB :%.*]] = sub i5 [[X ]], [[Y]]
2429
+ ; CHECK-NEXT: [[R:%.*]] = mul i5 [[ADD ]], [[SUB ]]
2424
2430
; CHECK-NEXT: ret i5 [[R]]
2425
2431
;
2426
2432
%x2 = mul nuw i5 %x , %x
@@ -2429,11 +2435,13 @@ define i5 @diff_of_squares_partial_nuw(i5 %x, i5 %y) {
2429
2435
ret i5 %r
2430
2436
}
2431
2437
2438
+ ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2439
+
2432
2440
define <2 x i5 > @diff_of_squares_nsw (<2 x i5 > %x , <2 x i5 > %y ) {
2433
2441
; CHECK-LABEL: @diff_of_squares_nsw(
2434
- ; CHECK-NEXT: [[X2 :%.*]] = mul nsw <2 x i5> [[X:%.*]], [[X ]]
2435
- ; CHECK-NEXT: [[Y2 :%.*]] = mul nsw <2 x i5> [[Y:%.* ]], [[Y]]
2436
- ; CHECK-NEXT: [[R:%.*]] = sub nsw <2 x i5> [[X2 ]], [[Y2 ]]
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 ]]
2437
2445
; CHECK-NEXT: ret <2 x i5> [[R]]
2438
2446
;
2439
2447
%x2 = mul nsw <2 x i5 > %x , %x
@@ -2442,11 +2450,13 @@ define <2 x i5> @diff_of_squares_nsw(<2 x i5> %x, <2 x i5> %y) {
2442
2450
ret <2 x i5 > %r
2443
2451
}
2444
2452
2453
+ ; All-or-nothing for propagation of no-wrap flags (possibly conservative)
2454
+
2445
2455
define <2 x i5 > @diff_of_squares_partial_nsw (<2 x i5 > %x , <2 x i5 > %y ) {
2446
2456
; CHECK-LABEL: @diff_of_squares_partial_nsw(
2447
- ; CHECK-NEXT: [[X2 :%.*]] = mul nsw <2 x i5> [[X:%.*]], [[X ]]
2448
- ; CHECK-NEXT: [[Y2 :%.*]] = mul <2 x i5> [[Y:%.* ]], [[Y]]
2449
- ; CHECK-NEXT: [[R:%.*]] = sub nsw <2 x i5> [[X2 ]], [[Y2 ]]
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 ]]
2450
2460
; CHECK-NEXT: ret <2 x i5> [[R]]
2451
2461
;
2452
2462
%x2 = mul nsw <2 x i5 > %x , %x
@@ -2455,6 +2465,8 @@ define <2 x i5> @diff_of_squares_partial_nsw(<2 x i5> %x, <2 x i5> %y) {
2455
2465
ret <2 x i5 > %r
2456
2466
}
2457
2467
2468
+ ; negative test
2469
+
2458
2470
define i8 @diff_of_squares_use1 (i8 %x , i8 %y ) {
2459
2471
; CHECK-LABEL: @diff_of_squares_use1(
2460
2472
; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
@@ -2470,6 +2482,8 @@ define i8 @diff_of_squares_use1(i8 %x, i8 %y) {
2470
2482
ret i8 %r
2471
2483
}
2472
2484
2485
+ ; negative test
2486
+
2473
2487
define i8 @diff_of_squares_use2 (i8 %x , i8 %y ) {
2474
2488
; CHECK-LABEL: @diff_of_squares_use2(
2475
2489
; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
0 commit comments