Skip to content

Commit fc89372

Browse files
[CalcSpillWeights] don't mark live intervals with spillable inlineasm ops as having infinite spill weight
This is necessary for RegAllocGreedy support for memory folding inline asm that uses "rm" constraints. Thanks to @qcolombet for the suggestion. Link: #20571
1 parent 778a484 commit fc89372

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

llvm/lib/CodeGen/CalcSpillWeights.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ void VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &LI) {
146146
LI.setWeight(Weight);
147147
}
148148

149+
static bool canMemFoldInlineAsm(LiveInterval &LI,
150+
const MachineRegisterInfo &MRI) {
151+
for (const MachineOperand &MO : MRI.reg_operands(LI.reg())) {
152+
const MachineInstr *MI = MO.getParent();
153+
if (MI->isInlineAsm() && MI->mayFoldInlineAsmRegOp(MI->getOperandNo(&MO)))
154+
return true;
155+
}
156+
157+
return false;
158+
}
159+
149160
float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
150161
SlotIndex *End) {
151162
MachineRegisterInfo &MRI = MF.getRegInfo();
@@ -315,7 +326,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
315326
// into instruction itself makes perfect sense.
316327
if (ShouldUpdateLI && LI.isZeroLength(LIS.getSlotIndexes()) &&
317328
!LI.isLiveAtIndexes(LIS.getRegMaskSlots()) &&
318-
!isLiveAtStatepointVarArg(LI)) {
329+
!isLiveAtStatepointVarArg(LI) && !canMemFoldInlineAsm(LI, MRI)) {
319330
LI.markNotSpillable();
320331
return -1.0;
321332
}

0 commit comments

Comments
 (0)