Skip to content

Commit 73ce961

Browse files
committed
[JumpThreading] Remove deleted BB from Unreachable
Although an unreachable BB is skipped by processBlock, its successor can still be handled by processBlock, and maybeMergeBasicBlockIntoOnlyPred may merge the two BBs and delete the unreachable BB. Then the garbage pointer is left in Unreachable set. This patch removes the invalid BB pointer from the Unreachable set.
1 parent 16a5f7e commit 73ce961

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

llvm/include/llvm/Transforms/Scalar/JumpThreading.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
9494
SmallPtrSet<const BasicBlock *, 16> LoopHeaders;
9595
#endif
9696

97+
// JumpThreading must not processes blocks unreachable from entry. It's a
98+
// waste of compute time and can potentially lead to hangs.
99+
SmallPtrSet<BasicBlock *, 16> Unreachable;
100+
97101
unsigned BBDupThreshold;
98102
unsigned DefaultBBDupThreshold;
99103

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,11 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
307307
else
308308
BBDupThreshold = DefaultBBDupThreshold;
309309

310-
// JumpThreading must not processes blocks unreachable from entry. It's a
311-
// waste of compute time and can potentially lead to hangs.
312-
SmallPtrSet<BasicBlock *, 16> Unreachable;
313310
assert(DTU && "DTU isn't passed into JumpThreading before using it.");
314311
assert(DTU->hasDomTree() && "JumpThreading relies on DomTree to proceed.");
315312
DominatorTree &DT = DTU->getDomTree();
313+
314+
Unreachable.clear();
316315
for (auto &BB : *F)
317316
if (!DT.isReachableFromEntry(&BB))
318317
Unreachable.insert(&BB);
@@ -1902,6 +1901,9 @@ bool JumpThreadingPass::maybeMergeBasicBlockIntoOnlyPred(BasicBlock *BB) {
19021901
LVI->eraseBlock(SinglePred);
19031902
MergeBasicBlockIntoOnlyPred(BB, DTU.get());
19041903

1904+
if (Unreachable.count(SinglePred) && DTU->isBBPendingDeletion(SinglePred))
1905+
Unreachable.erase(SinglePred);
1906+
19051907
// Now that BB is merged into SinglePred (i.e. SinglePred code followed by
19061908
// BB code within one basic block `BB`), we need to invalidate the LVI
19071909
// information associated with BB, because the LVI information need not be

0 commit comments

Comments
 (0)