Skip to content

Commit a39a382

Browse files
committed
[InstCombine] Thwart complexity-based canonicalization (NFC)
These tests did not test what they were supposed to. The transform fails to actually handle the commuted cases.
1 parent b910beb commit a39a382

File tree

1 file changed

+40
-19
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+40
-19
lines changed

llvm/test/Transforms/InstCombine/add.ll

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,12 +3284,17 @@ define i32 @add_reduce_sqr_sum_flipped(i32 %a, i32 %b) {
32843284
ret i32 %add
32853285
}
32863286

3287-
define i32 @add_reduce_sqr_sum_flipped2(i32 %a, i32 %b) {
3287+
define i32 @add_reduce_sqr_sum_flipped2(i32 %a, i32 %bx) {
32883288
; CHECK-LABEL: @add_reduce_sqr_sum_flipped2(
3289-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
3290-
; CHECK-NEXT: [[ADD:%.*]] = mul i32 [[TMP1]], [[TMP1]]
3289+
; CHECK-NEXT: [[B:%.*]] = xor i32 [[BX:%.*]], 42
3290+
; CHECK-NEXT: [[A_SQ:%.*]] = mul nsw i32 [[A:%.*]], [[A]]
3291+
; CHECK-NEXT: [[TWO_A:%.*]] = shl i32 [[A]], 1
3292+
; CHECK-NEXT: [[TWO_A_PLUS_B:%.*]] = add i32 [[TWO_A]], [[B]]
3293+
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[B]], [[TWO_A_PLUS_B]]
3294+
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[MUL]], [[A_SQ]]
32913295
; CHECK-NEXT: ret i32 [[ADD]]
32923296
;
3297+
%b = xor i32 %bx, 42 ; thwart complexity-based canonicalization
32933298
%a_sq = mul nsw i32 %a, %a
32943299
%two_a = shl i32 %a, 1
32953300
%two_a_plus_b = add i32 %two_a, %b
@@ -3342,12 +3347,17 @@ define i32 @add_reduce_sqr_sum_order2_flipped(i32 %a, i32 %b) {
33423347
ret i32 %ab2
33433348
}
33443349

3345-
define i32 @add_reduce_sqr_sum_order2_flipped2(i32 %a, i32 %b) {
3350+
define i32 @add_reduce_sqr_sum_order2_flipped2(i32 %a, i32 %bx) {
33463351
; CHECK-LABEL: @add_reduce_sqr_sum_order2_flipped2(
3347-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
3348-
; CHECK-NEXT: [[AB2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
3352+
; CHECK-NEXT: [[B:%.*]] = xor i32 [[BX:%.*]], 42
3353+
; CHECK-NEXT: [[A_SQ:%.*]] = mul nsw i32 [[A:%.*]], [[A]]
3354+
; CHECK-NEXT: [[TWOA:%.*]] = shl i32 [[A]], 1
3355+
; CHECK-NEXT: [[TWOAB1:%.*]] = add i32 [[B]], [[TWOA]]
3356+
; CHECK-NEXT: [[TWOAB_B2:%.*]] = mul i32 [[B]], [[TWOAB1]]
3357+
; CHECK-NEXT: [[AB2:%.*]] = add i32 [[A_SQ]], [[TWOAB_B2]]
33493358
; CHECK-NEXT: ret i32 [[AB2]]
33503359
;
3360+
%b = xor i32 %bx, 42 ; thwart complexity-based canonicalization
33513361
%a_sq = mul nsw i32 %a, %a
33523362
%twoa = mul i32 %a, 2
33533363
%twoab = mul i32 %twoa, %b
@@ -3357,12 +3367,17 @@ define i32 @add_reduce_sqr_sum_order2_flipped2(i32 %a, i32 %b) {
33573367
ret i32 %ab2
33583368
}
33593369

3360-
define i32 @add_reduce_sqr_sum_order2_flipped3(i32 %a, i32 %b) {
3370+
define i32 @add_reduce_sqr_sum_order2_flipped3(i32 %a, i32 %bx) {
33613371
; CHECK-LABEL: @add_reduce_sqr_sum_order2_flipped3(
3362-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
3363-
; CHECK-NEXT: [[AB2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
3372+
; CHECK-NEXT: [[B:%.*]] = xor i32 [[BX:%.*]], 42
3373+
; CHECK-NEXT: [[A_SQ:%.*]] = mul nsw i32 [[A:%.*]], [[A]]
3374+
; CHECK-NEXT: [[TWOA:%.*]] = shl i32 [[A]], 1
3375+
; CHECK-NEXT: [[B_SQ1:%.*]] = add i32 [[TWOA]], [[B]]
3376+
; CHECK-NEXT: [[TWOAB_B2:%.*]] = mul i32 [[B]], [[B_SQ1]]
3377+
; CHECK-NEXT: [[AB2:%.*]] = add i32 [[A_SQ]], [[TWOAB_B2]]
33643378
; CHECK-NEXT: ret i32 [[AB2]]
33653379
;
3380+
%b = xor i32 %bx, 42 ; thwart complexity-based canonicalization
33663381
%a_sq = mul nsw i32 %a, %a
33673382
%twoa = mul i32 %a, 2
33683383
%twoab = mul i32 %b, %twoa
@@ -3552,12 +3567,18 @@ define i32 @add_reduce_sqr_sum_order5_flipped2(i32 %a, i32 %b) {
35523567
ret i32 %ab2
35533568
}
35543569

3555-
define i32 @add_reduce_sqr_sum_order5_flipped3(i32 %a, i32 %b) {
3570+
define i32 @add_reduce_sqr_sum_order5_flipped3(i32 %ax, i32 %b) {
35563571
; CHECK-LABEL: @add_reduce_sqr_sum_order5_flipped3(
3557-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
3558-
; CHECK-NEXT: [[AB2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
3572+
; CHECK-NEXT: [[A:%.*]] = xor i32 [[AX:%.*]], 42
3573+
; CHECK-NEXT: [[A_SQ:%.*]] = mul nsw i32 [[A]], [[A]]
3574+
; CHECK-NEXT: [[TWOB:%.*]] = shl i32 [[B:%.*]], 1
3575+
; CHECK-NEXT: [[TWOAB:%.*]] = mul i32 [[A]], [[TWOB]]
3576+
; CHECK-NEXT: [[B_SQ:%.*]] = mul i32 [[B]], [[B]]
3577+
; CHECK-NEXT: [[A2_B2:%.*]] = add i32 [[A_SQ]], [[B_SQ]]
3578+
; CHECK-NEXT: [[AB2:%.*]] = add i32 [[TWOAB]], [[A2_B2]]
35593579
; CHECK-NEXT: ret i32 [[AB2]]
35603580
;
3581+
%a = xor i32 %ax, 42 ; thwart complexity-based canonicalization
35613582
%a_sq = mul nsw i32 %a, %a
35623583
%twob = mul i32 %b, 2
35633584
%twoab = mul i32 %a, %twob
@@ -4018,8 +4039,8 @@ define i32 @add_reduce_sqr_sum_varC_invalid2(i32 %a, i32 %b) {
40184039

40194040
define i32 @fold_sext_addition_or_disjoint(i8 %x) {
40204041
; CHECK-LABEL: @fold_sext_addition_or_disjoint(
4021-
; CHECK-NEXT: [[SE:%.*]] = sext i8 [[XX:%.*]] to i32
4022-
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[SE]], 1246
4042+
; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i32
4043+
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[TMP1]], 1246
40234044
; CHECK-NEXT: ret i32 [[R]]
40244045
;
40254046
%xx = or disjoint i8 %x, 12
@@ -4043,8 +4064,8 @@ define i32 @fold_sext_addition_fail(i8 %x) {
40434064

40444065
define i32 @fold_zext_addition_or_disjoint(i8 %x) {
40454066
; CHECK-LABEL: @fold_zext_addition_or_disjoint(
4046-
; CHECK-NEXT: [[SE:%.*]] = zext i8 [[XX:%.*]] to i32
4047-
; CHECK-NEXT: [[R:%.*]] = add nuw nsw i32 [[SE]], 1246
4067+
; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
4068+
; CHECK-NEXT: [[R:%.*]] = add nuw nsw i32 [[TMP1]], 1246
40484069
; CHECK-NEXT: ret i32 [[R]]
40494070
;
40504071
%xx = or disjoint i8 %x, 12
@@ -4055,9 +4076,9 @@ define i32 @fold_zext_addition_or_disjoint(i8 %x) {
40554076

40564077
define i32 @fold_zext_addition_or_disjoint2(i8 %x) {
40574078
; CHECK-LABEL: @fold_zext_addition_or_disjoint2(
4058-
; CHECK-NEXT: [[XX:%.*]] = add nuw i8 [[X:%.*]], 4
4059-
; CHECK-NEXT: [[SE:%.*]] = zext i8 [[XX]] to i32
4060-
; CHECK-NEXT: ret i32 [[SE]]
4079+
; CHECK-NEXT: [[TMP1:%.*]] = add nuw i8 [[X:%.*]], 4
4080+
; CHECK-NEXT: [[R:%.*]] = zext i8 [[TMP1]] to i32
4081+
; CHECK-NEXT: ret i32 [[R]]
40614082
;
40624083
%xx = or disjoint i8 %x, 18
40634084
%se = zext i8 %xx to i32

0 commit comments

Comments
 (0)