[llvm] Revert "[DFAJumpThreading] Prevent pass from using too much memory." (PR #153075)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 12:54:11 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: XChy (XChy)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->145482
---
Full diff: https://github.com/llvm/llvm-project/pull/153075.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp (+14-24)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
index a7ba54f03e61e..938aab5879044 100644
--- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
@@ -582,17 +582,15 @@ struct AllSwitchPaths {
VisitedBlocks VB;
// Get paths from the determinator BBs to SwitchPhiDefBB
std::vector<ThreadingPath> PathsToPhiDef =
- getPathsFromStateDefMap(StateDef, SwitchPhi, VB, MaxNumPaths);
+ getPathsFromStateDefMap(StateDef, SwitchPhi, VB);
if (SwitchPhiDefBB == SwitchBlock) {
TPaths = std::move(PathsToPhiDef);
return;
}
- assert(MaxNumPaths >= PathsToPhiDef.size());
- auto PathsLimit = MaxNumPaths / PathsToPhiDef.size();
// Find and append paths from SwitchPhiDefBB to SwitchBlock.
PathsType PathsToSwitchBB =
- paths(SwitchPhiDefBB, SwitchBlock, VB, /* PathDepth = */ 1, PathsLimit);
+ paths(SwitchPhiDefBB, SwitchBlock, VB, /* PathDepth = */ 1);
if (PathsToSwitchBB.empty())
return;
@@ -613,16 +611,13 @@ struct AllSwitchPaths {
typedef DenseMap<const BasicBlock *, const PHINode *> StateDefMap;
std::vector<ThreadingPath> getPathsFromStateDefMap(StateDefMap &StateDef,
PHINode *Phi,
- VisitedBlocks &VB,
- unsigned PathsLimit) {
+ VisitedBlocks &VB) {
std::vector<ThreadingPath> Res;
auto *PhiBB = Phi->getParent();
VB.insert(PhiBB);
VisitedBlocks UniqueBlocks;
for (auto *IncomingBB : Phi->blocks()) {
- if (Res.size() >= PathsLimit)
- break;
if (!UniqueBlocks.insert(IncomingBB).second)
continue;
if (!SwitchOuterLoop->contains(IncomingBB))
@@ -658,9 +653,8 @@ struct AllSwitchPaths {
// Direct predecessor, just add to the path.
if (IncomingPhiDefBB == IncomingBB) {
- assert(PathsLimit > Res.size());
- std::vector<ThreadingPath> PredPaths = getPathsFromStateDefMap(
- StateDef, IncomingPhi, VB, PathsLimit - Res.size());
+ std::vector<ThreadingPath> PredPaths =
+ getPathsFromStateDefMap(StateDef, IncomingPhi, VB);
for (ThreadingPath &Path : PredPaths) {
Path.push_back(PhiBB);
Res.push_back(std::move(Path));
@@ -673,17 +667,13 @@ struct AllSwitchPaths {
continue;
PathsType IntermediatePaths;
- assert(PathsLimit > Res.size());
- auto InterPathLimit = PathsLimit - Res.size();
- IntermediatePaths = paths(IncomingPhiDefBB, IncomingBB, VB,
- /* PathDepth = */ 1, InterPathLimit);
+ IntermediatePaths =
+ paths(IncomingPhiDefBB, IncomingBB, VB, /* PathDepth = */ 1);
if (IntermediatePaths.empty())
continue;
- assert(InterPathLimit >= IntermediatePaths.size());
- auto PredPathLimit = InterPathLimit / IntermediatePaths.size();
std::vector<ThreadingPath> PredPaths =
- getPathsFromStateDefMap(StateDef, IncomingPhi, VB, PredPathLimit);
+ getPathsFromStateDefMap(StateDef, IncomingPhi, VB);
for (const ThreadingPath &Path : PredPaths) {
for (const PathType &IPath : IntermediatePaths) {
ThreadingPath NewPath(Path);
@@ -698,7 +688,7 @@ struct AllSwitchPaths {
}
PathsType paths(BasicBlock *BB, BasicBlock *ToBB, VisitedBlocks &Visited,
- unsigned PathDepth, unsigned PathsLimit) {
+ unsigned PathDepth) {
PathsType Res;
// Stop exploring paths after visiting MaxPathLength blocks
@@ -725,8 +715,6 @@ struct AllSwitchPaths {
// is used to prevent a duplicate path from being generated
SmallSet<BasicBlock *, 4> Successors;
for (BasicBlock *Succ : successors(BB)) {
- if (Res.size() >= PathsLimit)
- break;
if (!Successors.insert(Succ).second)
continue;
@@ -748,12 +736,14 @@ struct AllSwitchPaths {
// coverage and compile time.
if (LI->getLoopFor(Succ) != CurrLoop)
continue;
- assert(PathsLimit > Res.size());
- PathsType SuccPaths =
- paths(Succ, ToBB, Visited, PathDepth + 1, PathsLimit - Res.size());
+
+ PathsType SuccPaths = paths(Succ, ToBB, Visited, PathDepth + 1);
for (PathType &Path : SuccPaths) {
Path.push_front(BB);
Res.push_back(Path);
+ if (Res.size() >= MaxNumPaths) {
+ return Res;
+ }
}
}
// This block could now be visited again from a different predecessor. Note
``````````
</details>
https://github.com/llvm/llvm-project/pull/153075
More information about the llvm-commits
mailing list