Skip to content

Commit 3af514e

Browse files
committed
[InstCombine] Add tests for improving sub X, ~Y -> add X, -Y; NFC
1 parent dfe1d35 commit 3af514e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

llvm/test/Transforms/InstCombine/fold-sub-of-not-to-inc-of-add.ll

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ define i32 @p0_scalar(i32 %x, i32 %y) {
2222
ret i32 %t1
2323
}
2424

25+
define i8 @p0_scalar_not_truly_negatable(i8 %x, i8 %y) {
26+
; CHECK-LABEL: @p0_scalar_not_truly_negatable(
27+
; CHECK-NEXT: [[XX:%.*]] = xor i8 [[X:%.*]], 123
28+
; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[Y:%.*]], -46
29+
; CHECK-NEXT: [[YY_NEG:%.*]] = add i8 [[TMP1]], 1
30+
; CHECK-NEXT: [[R:%.*]] = add i8 [[YY_NEG]], [[XX]]
31+
; CHECK-NEXT: ret i8 [[R]]
32+
;
33+
%xx = xor i8 %x, 123
34+
%yy = xor i8 %y, 45
35+
%r = sub i8 %xx, %yy
36+
ret i8 %r
37+
}
38+
2539
;------------------------------------------------------------------------------;
2640
; Vector tests
2741
;------------------------------------------------------------------------------;
@@ -79,7 +93,7 @@ define i32 @n4(i32 %x, i32 %y) {
7993
; CHECK-NEXT: ret i32 [[T1]]
8094
;
8195
%t0 = xor i32 %x, -1
82-
%t1 = sub i32 %t0, %y ; swapped
96+
%t1 = sub i32 %t0, %y ; swapped
8397
ret i32 %t1
8498
}
8599

@@ -89,7 +103,7 @@ define i32 @n5_is_not_not(i32 %x, i32 %y) {
89103
; CHECK-NEXT: [[T1:%.*]] = add i32 [[T0_NEG]], [[Y:%.*]]
90104
; CHECK-NEXT: ret i32 [[T1]]
91105
;
92-
%t0 = xor i32 %x, 2147483647 ; not -1
106+
%t0 = xor i32 %x, 2147483647 ; not -1
93107
%t1 = sub i32 %y, %t0
94108
ret i32 %t1
95109
}
@@ -100,7 +114,7 @@ define <2 x i32> @n5_is_not_not_vec_splat(<2 x i32> %x, <2 x i32> %y) {
100114
; CHECK-NEXT: [[T1:%.*]] = add <2 x i32> [[T0_NEG]], [[Y:%.*]]
101115
; CHECK-NEXT: ret <2 x i32> [[T1]]
102116
;
103-
%t0 = xor <2 x i32> %x, <i32 2147483647, i32 2147483647> ; signmask, but not -1
117+
%t0 = xor <2 x i32> %x, <i32 2147483647, i32 2147483647> ; signmask, but not -1
104118
%t1 = sub <2 x i32> %y, %t0
105119
ret <2 x i32> %t1
106120
}

0 commit comments

Comments
 (0)