Skip to content

Commit 884e9a8

Browse files
committed
[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.
1 parent 6830ebb commit 884e9a8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,7 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
30843084
// cloned instructions outside of EdgeBB.
30853085
BasicBlock::iterator InsertPt = EdgeBB->begin();
30863086
DenseMap<Value *, Value *> TranslateMap; // Track translated values.
3087+
TranslateMap[Cond] = Pair.second;
30873088
for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
30883089
if (PHINode *PN = dyn_cast<PHINode>(BBI)) {
30893090
TranslateMap[PN] = PN->getIncomingValueForBlock(PredBB);

llvm/test/Transforms/SimplifyCFG/jump-threading.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ define void @test_same_cond_extra_use(i1 %c) {
183183
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
184184
; CHECK: if:
185185
; CHECK-NEXT: call void @foo()
186-
; CHECK-NEXT: call void @use.i1(i1 [[C]])
186+
; CHECK-NEXT: call void @use.i1(i1 true)
187187
; CHECK-NEXT: call void @foo()
188188
; CHECK-NEXT: br label [[JOIN2:%.*]]
189189
; CHECK: else:
190190
; CHECK-NEXT: call void @bar()
191-
; CHECK-NEXT: call void @use.i1(i1 [[C]])
191+
; CHECK-NEXT: call void @use.i1(i1 false)
192192
; CHECK-NEXT: call void @bar()
193193
; CHECK-NEXT: br label [[JOIN2]]
194194
; CHECK: join2:

0 commit comments

Comments
 (0)