[llvm] c0d390d - [tests] precommit tests for phi handling in GVN
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 5 14:24:26 PST 2021
Author: Philip Reames
Date: 2021-03-05T14:24:21-08:00
New Revision: c0d390d0d26b03f75d96106063fafc9feadb83a8
URL: https://github.com/llvm/llvm-project/commit/c0d390d0d26b03f75d96106063fafc9feadb83a8
DIFF: https://github.com/llvm/llvm-project/commit/c0d390d0d26b03f75d96106063fafc9feadb83a8.diff
LOG: [tests] precommit tests for phi handling in GVN
Added:
llvm/test/Transforms/GVN/phi.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/GVN/phi.ll b/llvm/test/Transforms/GVN/phi.ll
new file mode 100644
index 000000000000..6e7c954d0f66
--- /dev/null
+++ b/llvm/test/Transforms/GVN/phi.ll
@@ -0,0 +1,133 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -gvn < %s | FileCheck %s
+
+
+define i64 @test1(i1 %c, i64 %a, i64 %b) {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
+; CHECK: taken:
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: untaken:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[A:%.*]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ [[A]], [[TAKEN]] ], [ [[B]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[RET:%.*]] = sub i64 [[PHI1]], [[PHI2]]
+; CHECK-NEXT: ret i64 [[RET]]
+;
+ br i1 %c, label %taken, label %untaken
+taken:
+ br label %merge
+untaken:
+ br label %merge
+merge:
+ %phi1 = phi i64 [%a, %taken], [%b, %untaken]
+ %phi2 = phi i64 [%a, %taken], [%b, %untaken]
+ %ret = sub i64 %phi1, %phi2
+ ret i64 %ret
+}
+
+declare void @llvm.assume(i1)
+
+define i64 @test2(i1 %c, i64 %a, i64 %b) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
+; CHECK: taken:
+; CHECK-NEXT: [[ASSUMPTION:%.*]] = icmp eq i64 [[A:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUMPTION]])
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: untaken:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[A]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ 0, [[TAKEN]] ], [ [[B]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[RET:%.*]] = sub i64 [[PHI1]], [[PHI2]]
+; CHECK-NEXT: ret i64 [[RET]]
+;
+ br i1 %c, label %taken, label %untaken
+taken:
+ %assumption = icmp eq i64 %a, 0
+ call void @llvm.assume(i1 %assumption)
+ br label %merge
+untaken:
+ br label %merge
+merge:
+ %phi1 = phi i64 [%a, %taken], [%b, %untaken]
+ %phi2 = phi i64 [0, %taken], [%b, %untaken]
+ %ret = sub i64 %phi1, %phi2
+ ret i64 %ret
+}
+
+
+define i64 @test3(i1 %c, i64 %a, i64 %b) {
+; CHECK-LABEL: @test3(
+; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
+; CHECK: taken:
+; CHECK-NEXT: [[ADD1:%.*]] = add i64 [[A:%.*]], 5
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: untaken:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[ADD1]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ [[ADD1]], [[TAKEN]] ], [ [[B]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[RET:%.*]] = sub i64 [[PHI1]], [[PHI2]]
+; CHECK-NEXT: ret i64 [[RET]]
+;
+ br i1 %c, label %taken, label %untaken
+taken:
+ %add1 = add i64 %a, 5
+ %add2 = add i64 %a, 5
+ br label %merge
+untaken:
+ br label %merge
+merge:
+ %phi1 = phi i64 [%add1, %taken], [%b, %untaken]
+ %phi2 = phi i64 [%add2, %taken], [%b, %untaken]
+ %ret = sub i64 %phi1, %phi2
+ ret i64 %ret
+}
+
+define i64 @test4(i1 %c, i64 %a, i64 %b) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
+; CHECK: taken:
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: untaken:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[A:%.*]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
+; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ [[A]], [[TAKEN]] ], [ [[B]], [[UNTAKEN]] ]
+; CHECK-NEXT: br i1 [[C]], label [[TAKEN2:%.*]], label [[UNTAKEN2:%.*]]
+; CHECK: taken2:
+; CHECK-NEXT: [[ADD1:%.*]] = add i64 [[PHI1]], 5
+; CHECK-NEXT: [[ADD2:%.*]] = add i64 [[PHI2]], 5
+; CHECK-NEXT: br label [[MERGE2:%.*]]
+; CHECK: untaken2:
+; CHECK-NEXT: br label [[MERGE2]]
+; CHECK: merge2:
+; CHECK-NEXT: [[PHI3:%.*]] = phi i64 [ [[ADD1]], [[TAKEN2]] ], [ [[PHI2]], [[UNTAKEN2]] ]
+; CHECK-NEXT: [[PHI4:%.*]] = phi i64 [ [[ADD2]], [[TAKEN2]] ], [ [[PHI2]], [[UNTAKEN2]] ]
+; CHECK-NEXT: [[RET:%.*]] = sub i64 [[PHI4]], [[PHI3]]
+; CHECK-NEXT: ret i64 [[RET]]
+;
+ br i1 %c, label %taken, label %untaken
+taken:
+ br label %merge
+untaken:
+ br label %merge
+merge:
+ %phi1 = phi i64 [%a, %taken], [%b, %untaken]
+ %phi2 = phi i64 [%a, %taken], [%b, %untaken]
+ br i1 %c, label %taken2, label %untaken2
+taken2:
+ %add1 = add i64 %phi1, 5
+ %add2 = add i64 %phi2, 5
+ br label %merge2
+untaken2:
+ br label %merge2
+merge2:
+ %phi3 = phi i64 [%add1, %taken2], [%phi2, %untaken2]
+ %phi4 = phi i64 [%add2, %taken2], [%phi2, %untaken2]
+ %ret = sub i64 %phi4, %phi3
+ ret i64 %ret
+}
More information about the llvm-commits
mailing list