[llvm] 6bd2b70 - [SimpleLoopUnswitch] Add freeze if branch execs for partial unswitching.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 01:44:41 PDT 2022
Author: Florian Hahn
Date: 2022-05-05T09:44:07+01:00
New Revision: 6bd2b70877615bac018f54b09bd8c97155d52a45
URL: https://github.com/llvm/llvm-project/commit/6bd2b70877615bac018f54b09bd8c97155d52a45
DIFF: https://github.com/llvm/llvm-project/commit/6bd2b70877615bac018f54b09bd8c97155d52a45.diff
LOG: [SimpleLoopUnswitch] Add freeze if branch execs for partial unswitching.
We cannot skip the freezing the condition if the unswitched branch
executes, if the condition is a chain of ANDs/ORs. For example, if if we
have an AND %c1, %c2 with %c1 == undef and %c2 == 0, there would be no
branch on undef in the original code, but a branch on undef if we
unswitch %c1.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D124603
Added:
Modified:
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 14c1fed9d2020..0272db8844c03 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -2321,9 +2321,9 @@ static void unswitchNontrivialInvariants(
buildPartialInvariantUnswitchConditionalBranch(
*SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, L, MSSAU);
else {
- buildPartialUnswitchConditionalBranch(*SplitBB, Invariants, Direction,
- *ClonedPH, *LoopPH, InsertFreeze,
- BI, &AC, DT);
+ buildPartialUnswitchConditionalBranch(
+ *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH,
+ FreezeLoopUnswitchCond, BI, &AC, DT);
}
DTUpdates.push_back({DominatorTree::Insert, SplitBB, ClonedPH});
diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
index 5b19a7507d9f3..86441591b8f3e 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
@@ -2717,7 +2717,8 @@ define i32 @test25(i1* %ptr, i1 %cond) {
entry:
br label %loop_begin
; CHECK-NEXT: entry:
-; CHECK-NEXT: br i1 %cond, label %entry.split.us, label %entry.split
+; CHECK-NEXT: [[FROZEN:%.+]] = freeze i1 %cond
+; CHECK-NEXT: br i1 [[FROZEN]], label %entry.split.us, label %entry.split
loop_begin:
%v1 = load i1, i1* %ptr
@@ -2790,7 +2791,9 @@ define i32 @test26(i1* %ptr1, i1* %ptr2, i1* %ptr3, i1 %cond1, i1 %cond2, i1 %co
entry:
br label %loop_begin
; CHECK-NEXT: entry:
-; CHECK-NEXT: %[[INV_AND:.*]] = and i1 %cond3, %cond1
+; CHECK-NEXT: [[C3_FR:%.+]] = freeze i1 %cond3
+; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1
+; CHECK-NEXT: %[[INV_AND:.*]] = and i1 [[C3_FR]], [[C1_FR]]
; CHECK-NEXT: br i1 %[[INV_AND]], label %entry.split, label %entry.split.us
loop_begin:
@@ -2871,7 +2874,9 @@ define i32 @test27(i1* %ptr1, i1* %ptr2, i1* %ptr3, i1 %cond1, i1 %cond2, i1 %co
entry:
br label %loop_begin
; CHECK-NEXT: entry:
-; CHECK-NEXT: %[[INV_OR:.*]] = or i1 %cond3, %cond1
+; CHECK-NEXT: [[C3_FR:%.+]] = freeze i1 %cond3
+; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1
+; CHECK-NEXT: %[[INV_OR:.*]] = or i1 [[C3_FR]], [[C1_FR]]
; CHECK-NEXT: br i1 %[[INV_OR]], label %entry.split.us, label %entry.split
loop_begin:
@@ -4231,7 +4236,9 @@ define i32 @test32(i1* %ptr1, i1* %ptr2, i1* %ptr3, i1 %cond1, i1 %cond2) {
entry:
br label %loop_begin
; CHECK-NEXT: entry:
-; CHECK-NEXT: %[[INV_AND:.*]] = and i1 %cond2, %cond1
+; CHECK-NEXT: [[C2_FR:%.+]] = freeze i1 %cond2
+; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1
+; CHECK-NEXT: %[[INV_AND:.*]] = and i1 [[C2_FR]], [[C1_FR]]
; CHECK-NEXT: br i1 %[[INV_AND]], label %entry.split, label %entry.split.us
loop_begin:
@@ -4309,7 +4316,9 @@ define i32 @test33(i1* %ptr1, i1* %ptr2, i1* %ptr3, i1 %cond1, i1 %cond2) {
entry:
br label %loop_begin
; CHECK-NEXT: entry:
-; CHECK-NEXT: %[[INV_OR:.*]] = or i1 %cond2, %cond1
+; CHECK-NEXT: [[C2_FR:%.+]] = freeze i1 %cond2
+; CHECK-NEXT: [[C1_FR:%.+]] = freeze i1 %cond1
+; CHECK-NEXT: %[[INV_OR:.*]] = or i1 [[C2_FR]], [[C1_FR]]
; CHECK-NEXT: br i1 %[[INV_OR]], label %entry.split.us, label %entry.split
loop_begin:
More information about the llvm-commits
mailing list