Skip to content
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

JIT: Limit 3-opt to 1000 swaps per run #112259

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6357,6 +6357,7 @@ class Compiler
class ThreeOptLayout
{
static bool EdgeCmp(const FlowEdge* left, const FlowEdge* right);
static constexpr unsigned maxSwaps = 1000;

Compiler* compiler;
PriorityQueue<FlowEdge*, decltype(&ThreeOptLayout::EdgeCmp)> cutPoints;
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5343,7 +5343,8 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
// and before the destination block, and swap the partitions to create fallthrough.
// If it is, do the swap, and for the blocks before/after each cut point that lost fallthrough,
// consider adding their successors/predecessors to 'cutPoints'.
while (!cutPoints.Empty())
unsigned numSwaps = 0;
while (!cutPoints.Empty() && (numSwaps < maxSwaps))
{
FlowEdge* const candidateEdge = cutPoints.Pop();
candidateEdge->markUnvisited();
Expand Down Expand Up @@ -5498,8 +5499,10 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
}

modified = true;
numSwaps++;
}

cutPoints.Clear();
return modified;
}

Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/priorityqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class PriorityQueue
return data.empty();
}

void Clear()
{
data.clear();
}

// Insert new element at the back of the vector.
// Then, while the new element has a higher priority than its parent, move the element up.
void Push(const T& value)
Expand Down
Loading