Skip to content

Commit 4ed8bfd

Browse files
authored
LiveRangeShrink: Early exit when encountering a code motion barrier.
Without this, we end up with quadratic behavior affecting functions with large numbers of code motion barriers, such as CFI jump tables. As a drive-by cleanup, remove a redundant store to SawStore in this pass as it is also done by isSafeToMove. Reviewers: arsenm Reviewed By: arsenm Pull Request: #136806
1 parent 37b135c commit 4ed8bfd

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

llvm/lib/CodeGen/LiveRangeShrink.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,25 @@ static MachineInstr *FindDominatedInstruction(MachineInstr &New,
9595
return Old;
9696
}
9797

98+
/// Returns whether this instruction is considered a code motion barrier by this
99+
/// pass. We can be less conservative than hasUnmodeledSideEffects() when
100+
/// deciding whether an instruction is a barrier because it is known that pseudo
101+
/// probes are safe to move in this pass specifically (see commit 1cb47a063e2b).
102+
static bool isCodeMotionBarrier(MachineInstr &MI) {
103+
return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe();
104+
}
105+
98106
/// Builds Instruction to its dominating order number map \p M by traversing
99107
/// from instruction \p Start.
100108
static void BuildInstOrderMap(MachineBasicBlock::iterator Start,
101109
InstOrderMap &M) {
102110
M.clear();
103111
unsigned i = 0;
104-
for (MachineInstr &I : make_range(Start, Start->getParent()->end()))
112+
for (MachineInstr &I : make_range(Start, Start->getParent()->end())) {
113+
if (isCodeMotionBarrier(I))
114+
break;
105115
M[&I] = i++;
116+
}
106117
}
107118

108119
bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
@@ -142,8 +153,6 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
142153
while (Next != MBB.end()) {
143154
MachineInstr &MI = *Next;
144155
Next = MBB.SkipPHIsLabelsAndDebug(++Next);
145-
if (MI.mayStore())
146-
SawStore = true;
147156

148157
unsigned CurrentOrder = IOM[&MI];
149158
unsigned Barrier = 0;
@@ -166,8 +175,7 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
166175
// If MI has side effects, it should become a barrier for code motion.
167176
// IOM is rebuild from the next instruction to prevent later
168177
// instructions from being moved before this MI.
169-
if (MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe() &&
170-
Next != MBB.end()) {
178+
if (isCodeMotionBarrier(MI) && Next != MBB.end()) {
171179
BuildInstOrderMap(Next, IOM);
172180
SawStore = false;
173181
}

0 commit comments

Comments
 (0)