[llvm] c891f51 - [JumpThreading] Add a test that threads jumps with frozen branch conditions
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 27 03:05:12 PDT 2020
Author: Juneyoung Lee
Date: 2020-07-27T19:04:50+09:00
New Revision: c891f519e17e38ec466deab1730c48e9d7a2eca8
URL: https://github.com/llvm/llvm-project/commit/c891f519e17e38ec466deab1730c48e9d7a2eca8
DIFF: https://github.com/llvm/llvm-project/commit/c891f519e17e38ec466deab1730c48e9d7a2eca8.diff
LOG: [JumpThreading] Add a test that threads jumps with frozen branch conditions
Added:
llvm/test/Transforms/JumpThreading/freeze-lvi-edgevaluelocal.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/JumpThreading/freeze-lvi-edgevaluelocal.ll b/llvm/test/Transforms/JumpThreading/freeze-lvi-edgevaluelocal.ll
new file mode 100644
index 000000000000..07dd956777f6
--- /dev/null
+++ b/llvm/test/Transforms/JumpThreading/freeze-lvi-edgevaluelocal.ll
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -jump-threading -S < %s | FileCheck %s
+
+declare void @f()
+declare void @f2()
+declare void @f3()
+
+; br on cond.fr should be removed & ENTRY -> A -> B should be threaded
+define i32 @simple(i1 %cond) {
+; CHECK-LABEL: @simple(
+; CHECK-NEXT: ENTRY:
+; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[COND:%.*]]
+; CHECK-NEXT: br i1 [[COND]], label [[A:%.*]], label [[EXIT:%.*]]
+; CHECK: A:
+; CHECK-NEXT: br i1 [[COND_FR]], label [[B:%.*]], label [[EXIT]]
+; CHECK: B:
+; CHECK-NEXT: call void @f()
+; CHECK-NEXT: ret i32 1
+; CHECK: EXIT:
+; CHECK-NEXT: ret i32 0
+;
+ENTRY:
+ %cond.fr = freeze i1 %cond
+ br i1 %cond, label %A, label %EXIT
+A:
+ br i1 %cond.fr, label %B, label %EXIT
+B:
+ call void @f()
+ ret i32 1
+EXIT:
+ ret i32 0
+}
+
+define void @switch(i32 %cond) {
+; CHECK-LABEL: @switch(
+; CHECK-NEXT: ENTRY:
+; CHECK-NEXT: [[COND_FR:%.*]] = freeze i32 [[COND:%.*]]
+; CHECK-NEXT: switch i32 [[COND]], label [[DEFAULT:%.*]] [
+; CHECK-NEXT: i32 0, label [[A:%.*]]
+; CHECK-NEXT: i32 1, label [[B:%.*]]
+; CHECK-NEXT: ]
+; CHECK: DEFAULT:
+; CHECK-NEXT: switch i32 [[COND_FR]], label [[PRESERVED1:%.*]] [
+; CHECK-NEXT: i32 0, label [[PRESERVED2:%.*]]
+; CHECK-NEXT: ]
+; CHECK: PRESERVED1:
+; CHECK-NEXT: call void @f()
+; CHECK-NEXT: ret void
+; CHECK: PRESERVED2:
+; CHECK-NEXT: call void @f2()
+; CHECK-NEXT: ret void
+; CHECK: A:
+; CHECK-NEXT: switch i32 [[COND_FR]], label [[A_NOTTAKEN:%.*]] [
+; CHECK-NEXT: i32 0, label [[A_TAKEN:%.*]]
+; CHECK-NEXT: ]
+; CHECK: A_TAKEN:
+; CHECK-NEXT: call void @f()
+; CHECK-NEXT: ret void
+; CHECK: A_NOTTAKEN:
+; CHECK-NEXT: call void @f2()
+; CHECK-NEXT: ret void
+; CHECK: B:
+; CHECK-NEXT: switch i32 [[COND_FR]], label [[B_TAKEN:%.*]] [
+; CHECK-NEXT: i32 0, label [[B_NOTTAKEN:%.*]]
+; CHECK-NEXT: ]
+; CHECK: B_TAKEN:
+; CHECK-NEXT: call void @f()
+; CHECK-NEXT: ret void
+; CHECK: B_NOTTAKEN:
+; CHECK-NEXT: call void @f2()
+; CHECK-NEXT: ret void
+;
+ENTRY:
+ %cond.fr = freeze i32 %cond
+ switch i32 %cond, label %DEFAULT [
+ i32 0, label %A
+ i32 1, label %B
+ ]
+DEFAULT:
+ switch i32 %cond.fr, label %PRESERVED1 [
+ i32 0, label %PRESERVED2
+ ]
+PRESERVED1:
+ call void @f()
+ ret void
+PRESERVED2:
+ call void @f2()
+ ret void
+
+A:
+ switch i32 %cond.fr, label %A_NOTTAKEN [
+ i32 0, label %A_TAKEN
+ ]
+A_TAKEN:
+ call void @f()
+ ret void
+A_NOTTAKEN:
+ call void @f2()
+ ret void
+
+B:
+ switch i32 %cond.fr, label %B_TAKEN [
+ i32 0, label %B_NOTTAKEN
+ ]
+B_TAKEN:
+ call void @f()
+ ret void
+B_NOTTAKEN:
+ call void @f2()
+ ret void
+}
More information about the llvm-commits
mailing list