[llvm] 884e9a8 - [SimplifyCFG] Replace condition value when threading
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 29 00:56:25 PDT 2022
Author: Nikita Popov
Date: 2022-04-29T09:50:27+02:00
New Revision: 884e9a877b378f5bf03f3c85a25b7a139ef6c8d8
URL: https://github.com/llvm/llvm-project/commit/884e9a877b378f5bf03f3c85a25b7a139ef6c8d8
DIFF: https://github.com/llvm/llvm-project/commit/884e9a877b378f5bf03f3c85a25b7a139ef6c8d8.diff
LOG: [SimplifyCFG] Replace condition value when threading
Replace the condition value with the known constant value on the
threaded edge. This happens implicitly with phi threading because
we replace with the incoming value, but not for non-phi threading.
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 cd47a1e7e456a..e86d253b9b9f0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3084,6 +3084,7 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
// cloned instructions outside of EdgeBB.
BasicBlock::iterator InsertPt = EdgeBB->begin();
DenseMap<Value *, Value *> TranslateMap; // Track translated values.
+ TranslateMap[Cond] = Pair.second;
for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
if (PHINode *PN = dyn_cast<PHINode>(BBI)) {
TranslateMap[PN] = PN->getIncomingValueForBlock(PredBB);
diff --git a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
index c401651c1df0c..59195660a3922 100644
--- a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
+++ b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
@@ -183,12 +183,12 @@ define void @test_same_cond_extra_use(i1 %c) {
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
; CHECK: if:
; CHECK-NEXT: call void @foo()
-; CHECK-NEXT: call void @use.i1(i1 [[C]])
+; CHECK-NEXT: call void @use.i1(i1 true)
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: br label [[JOIN2:%.*]]
; CHECK: else:
; CHECK-NEXT: call void @bar()
-; CHECK-NEXT: call void @use.i1(i1 [[C]])
+; 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