Skip to content

Commit 5f652c2

Browse files
JIT: Limit 3-opt to 1000 swaps per run (dotnet#112259)
Fixes dotnet#111988.
1 parent 7c8d89c commit 5f652c2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/coreclr/jit/compiler.h

+1
Original file line numberDiff line numberDiff line change
@@ -6352,6 +6352,7 @@ class Compiler
63526352
class ThreeOptLayout
63536353
{
63546354
static bool EdgeCmp(const FlowEdge* left, const FlowEdge* right);
6355+
static constexpr unsigned maxSwaps = 1000;
63556356

63566357
Compiler* compiler;
63576358
PriorityQueue<FlowEdge*, decltype(&ThreeOptLayout::EdgeCmp)> cutPoints;

src/coreclr/jit/fgopt.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -5343,7 +5343,8 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
53435343
// and before the destination block, and swap the partitions to create fallthrough.
53445344
// If it is, do the swap, and for the blocks before/after each cut point that lost fallthrough,
53455345
// consider adding their successors/predecessors to 'cutPoints'.
5346-
while (!cutPoints.Empty())
5346+
unsigned numSwaps = 0;
5347+
while (!cutPoints.Empty() && (numSwaps < maxSwaps))
53475348
{
53485349
FlowEdge* const candidateEdge = cutPoints.Pop();
53495350
candidateEdge->markUnvisited();
@@ -5498,8 +5499,10 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
54985499
}
54995500

55005501
modified = true;
5502+
numSwaps++;
55015503
}
55025504

5505+
cutPoints.Clear();
55035506
return modified;
55045507
}
55055508

src/coreclr/jit/priorityqueue.h

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class PriorityQueue
5858
return data.empty();
5959
}
6060

61+
void Clear()
62+
{
63+
data.clear();
64+
}
65+
6166
// Insert new element at the back of the vector.
6267
// Then, while the new element has a higher priority than its parent, move the element up.
6368
void Push(const T& value)

0 commit comments

Comments
 (0)