[llvm] [JumpThreading] Remove deleted BB from Unreachable (PR #126984)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 15:09:33 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: None (weiguozhi)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/126984.diff
2 Files Affected:
- (modified) llvm/include/llvm/Transforms/Scalar/JumpThreading.h (+4)
- (modified) llvm/lib/Transforms/Scalar/JumpThreading.cpp (+5-3)
``````````diff
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
index 7d11fc0ad6938..84292c716a0a9 100644
--- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
+++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
@@ -94,6 +94,10 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
SmallPtrSet<const BasicBlock *, 16> LoopHeaders;
#endif
+ // JumpThreading must not processes blocks unreachable from entry. It's a
+ // waste of compute time and can potentially lead to hangs.
+ SmallPtrSet<BasicBlock *, 16> Unreachable;
+
unsigned BBDupThreshold;
unsigned DefaultBBDupThreshold;
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 7b221a814aabd..dfa49ba183779 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -307,12 +307,11 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
else
BBDupThreshold = DefaultBBDupThreshold;
- // JumpThreading must not processes blocks unreachable from entry. It's a
- // waste of compute time and can potentially lead to hangs.
- SmallPtrSet<BasicBlock *, 16> Unreachable;
assert(DTU && "DTU isn't passed into JumpThreading before using it.");
assert(DTU->hasDomTree() && "JumpThreading relies on DomTree to proceed.");
DominatorTree &DT = DTU->getDomTree();
+
+ Unreachable.clear();
for (auto &BB : *F)
if (!DT.isReachableFromEntry(&BB))
Unreachable.insert(&BB);
@@ -1902,6 +1901,9 @@ bool JumpThreadingPass::maybeMergeBasicBlockIntoOnlyPred(BasicBlock *BB) {
LVI->eraseBlock(SinglePred);
MergeBasicBlockIntoOnlyPred(BB, DTU.get());
+ if (Unreachable.count(SinglePred) && DTU->isBBPendingDeletion(SinglePred))
+ Unreachable.erase(SinglePred);
+
// Now that BB is merged into SinglePred (i.e. SinglePred code followed by
// BB code within one basic block `BB`), we need to invalidate the LVI
// information associated with BB, because the LVI information need not be
``````````
</details>
https://github.com/llvm/llvm-project/pull/126984
More information about the llvm-commits
mailing list