Skip to content

[DFAJumpThreading] Prevent pass from using too much memory. #145482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ struct AllSwitchPaths {

VisitedBlocks UniqueBlocks;
for (auto *IncomingBB : Phi->blocks()) {
if (Res.size() >= MaxNumPaths)
break;
if (!UniqueBlocks.insert(IncomingBB).second)
continue;
if (!SwitchOuterLoop->contains(IncomingBB))
Expand Down Expand Up @@ -657,6 +659,8 @@ struct AllSwitchPaths {
getPathsFromStateDefMap(StateDef, IncomingPhi, VB);
for (ThreadingPath &Path : PredPaths) {
Path.push_back(PhiBB);
if (Res.size() >= MaxNumPaths)
break;
Res.push_back(std::move(Path));
}
continue;
Expand All @@ -679,6 +683,10 @@ struct AllSwitchPaths {
ThreadingPath NewPath(Path);
NewPath.appendExcludingFirst(IPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntermediatePaths are appended to the list of PredPaths (here, and also in the run() function), so the total number of paths is the multiplication of the sizes of the two lists. IntermediatePaths are already calculated so we are wasting compute cycles here by doing wasteful computation and by breaking the loop later than we should.

Since getPathsFromStateDefMap() and paths() are called multiple times and from different places they don't see the global picture of the number of paths we already have.

My suggestion is to add an argument to these two functions and update every call to these functions with a more appropriate limit instead of MaxNumPaths.

NewPath.push_back(PhiBB);
if (Res.size() >= MaxNumPaths) {
VB.erase(PhiBB);
return Res;
}
Res.push_back(NewPath);
}
}
Expand Down
Loading