[llvm] c0844de - [InstCombine] add tests for add/sub/add combines; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 21 09:17:33 PDT 2021
Author: Sanjay Patel
Date: 2021-08-21T11:45:43-04:00
New Revision: c0844de7a2a4181b8a88b3eec06a9d7bdd51bae4
URL: https://github.com/llvm/llvm-project/commit/c0844de7a2a4181b8a88b3eec06a9d7bdd51bae4
DIFF: https://github.com/llvm/llvm-project/commit/c0844de7a2a4181b8a88b3eec06a9d7bdd51bae4.diff
LOG: [InstCombine] add tests for add/sub/add combines; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/addsub-constant-folding.ll b/llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
index 2d9918737d2a..ae634ba1adc7 100644
--- a/llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
+++ b/llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
@@ -526,3 +526,63 @@ define <4 x i32> @vec_const_sub_const_sub_nonsplat(<4 x i32> %arg) {
%t1 = sub <4 x i32> <i32 2, i32 3, i32 undef, i32 2>, %t0
ret <4 x i32> %t1
}
+
+define i7 @addsub_combine_constants(i7 %x, i7 %y) {
+; CHECK-LABEL: @addsub_combine_constants(
+; CHECK-NEXT: [[A1:%.*]] = add i7 [[X:%.*]], 42
+; CHECK-NEXT: [[S:%.*]] = sub i7 10, [[Y:%.*]]
+; CHECK-NEXT: [[A2:%.*]] = add nsw i7 [[A1]], [[S]]
+; CHECK-NEXT: ret i7 [[A2]]
+;
+ %a1 = add i7 %x, 42
+ %s = sub i7 10, %y
+ %a2 = add nsw i7 %a1, %s
+ ret i7 %a2
+}
+
+define <4 x i32> @addsub_combine_constants_use1(<4 x i32> %x, <4 x i32> %y) {
+; CHECK-LABEL: @addsub_combine_constants_use1(
+; CHECK-NEXT: [[A1:%.*]] = add <4 x i32> [[X:%.*]], <i32 42, i32 -7, i32 0, i32 -1>
+; CHECK-NEXT: call void @vec_use(<4 x i32> [[A1]])
+; CHECK-NEXT: [[S:%.*]] = sub <4 x i32> <i32 -100, i32 1, i32 -1, i32 42>, [[Y:%.*]]
+; CHECK-NEXT: [[A2:%.*]] = add nuw <4 x i32> [[S]], [[A1]]
+; CHECK-NEXT: ret <4 x i32> [[A2]]
+;
+ %a1 = add <4 x i32> %x, <i32 42, i32 -7, i32 0, i32 -1>
+ call void @vec_use(<4 x i32> %a1)
+ %s = sub <4 x i32> <i32 -100, i32 1, i32 -1, i32 42>, %y
+ %a2 = add nuw <4 x i32> %s, %a1
+ ret <4 x i32> %a2
+}
+
+define i32 @addsub_combine_constants_use2(i32 %x, i32 %y) {
+; CHECK-LABEL: @addsub_combine_constants_use2(
+; CHECK-NEXT: [[A1:%.*]] = add i32 [[X:%.*]], 42
+; CHECK-NEXT: [[S:%.*]] = sub i32 100, [[Y:%.*]]
+; CHECK-NEXT: call void @use(i32 [[S]])
+; CHECK-NEXT: [[A2:%.*]] = add i32 [[A1]], [[S]]
+; CHECK-NEXT: ret i32 [[A2]]
+;
+ %a1 = add i32 %x, 42
+ %s = sub i32 100, %y
+ call void @use(i32 %s)
+ %a2 = add i32 %a1, %s
+ ret i32 %a2
+}
+
+define i32 @addsub_combine_constants_use3(i32 %x, i32 %y) {
+; CHECK-LABEL: @addsub_combine_constants_use3(
+; CHECK-NEXT: [[A1:%.*]] = add i32 [[X:%.*]], 42
+; CHECK-NEXT: call void @use(i32 [[A1]])
+; CHECK-NEXT: [[S:%.*]] = sub i32 100, [[Y:%.*]]
+; CHECK-NEXT: call void @use(i32 [[S]])
+; CHECK-NEXT: [[A2:%.*]] = add i32 [[A1]], [[S]]
+; CHECK-NEXT: ret i32 [[A2]]
+;
+ %a1 = add i32 %x, 42
+ call void @use(i32 %a1)
+ %s = sub i32 100, %y
+ call void @use(i32 %s)
+ %a2 = add i32 %a1, %s
+ ret i32 %a2
+}
More information about the llvm-commits
mailing list