[llvm] d727505 - [SimplifyCFG] Remove one-use limitation in FoldCondBranchOnPHI()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 06:56:30 PDT 2022
Author: Nikita Popov
Date: 2022-04-20T15:56:20+02:00
New Revision: d727505e40cde2ec5f8e9f4dc2220503f2b1863a
URL: https://github.com/llvm/llvm-project/commit/d727505e40cde2ec5f8e9f4dc2220503f2b1863a
DIFF: https://github.com/llvm/llvm-project/commit/d727505e40cde2ec5f8e9f4dc2220503f2b1863a.diff
LOG: [SimplifyCFG] Remove one-use limitation in FoldCondBranchOnPHI()
BlockIsSimpleEnoughToThreadThrough() already checks that the phi
(and all other instructions) are not used outside the block, so
this one-use check is not necessary for legality. I also don't
see any reason why it would be necessary for profitability (in
fact, those extra uses will be replaced with constants, which
should be generally profitable).
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/jump-threading.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index fb942bbd0574d..7a9c4b2e50750 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2984,9 +2984,7 @@ static Optional<bool> FoldCondBranchOnPHIImpl(BranchInst *BI,
AssumptionCache *AC) {
BasicBlock *BB = BI->getParent();
PHINode *PN = dyn_cast<PHINode>(BI->getCondition());
- // NOTE: we currently cannot transform this case if the PHI node is used
- // outside of the block.
- if (!PN || PN->getParent() != BB || !PN->hasOneUse())
+ if (!PN || PN->getParent() != BB)
return false;
// Degenerate case of a single entry PHI.
@@ -2996,6 +2994,8 @@ static Optional<bool> FoldCondBranchOnPHIImpl(BranchInst *BI,
}
// Now we know that this block has multiple preds and two succs.
+ // Check that the block is small enough and values defined in the block are
+ // not used outside of it.
if (!BlockIsSimpleEnoughToThreadThrough(BB))
return false;
diff --git a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
index aed090fed4640..8316710dbd0dd 100644
--- a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
+++ b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
@@ -50,18 +50,12 @@ define void @test_phi_extra_use(i1 %c) {
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
; CHECK: if:
; CHECK-NEXT: call void @foo()
-; CHECK-NEXT: br label [[JOIN:%.*]]
-; CHECK: else:
-; CHECK-NEXT: call void @bar()
-; CHECK-NEXT: br label [[JOIN]]
-; CHECK: join:
-; CHECK-NEXT: [[C2:%.*]] = phi i1 [ true, [[IF]] ], [ false, [[ELSE]] ]
-; CHECK-NEXT: call void @use.i1(i1 [[C2]])
-; CHECK-NEXT: br i1 [[C2]], label [[IF2:%.*]], label [[ELSE2:%.*]]
-; CHECK: if2:
+; CHECK-NEXT: call void @use.i1(i1 true)
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: br label [[JOIN2:%.*]]
-; CHECK: else2:
+; CHECK: else:
+; CHECK-NEXT: call void @bar()
+; CHECK-NEXT: call void @use.i1(i1 false)
; CHECK-NEXT: call void @bar()
; CHECK-NEXT: br label [[JOIN2]]
; CHECK: join2:
More information about the llvm-commits
mailing list