Skip to content

Commit

Permalink
[CalcSpillWeights] don't mark live intervals with spillable inlineasm…
Browse files Browse the repository at this point in the history
… ops as having infinite spill weight (#70747)

This is necessary for RegAllocGreedy support for memory folding inline
asm that uses "rm" constraints.

Thanks to @qcolombet for the suggestion.

Link: llvm/llvm-project#20571
  • Loading branch information
nickdesaulniers authored Nov 3, 2023
1 parent c880fdc commit 284c699
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion llvm/lib/CodeGen/CalcSpillWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ void VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &LI) {
LI.setWeight(Weight);
}

static bool canMemFoldInlineAsm(LiveInterval &LI,
const MachineRegisterInfo &MRI) {
for (const MachineOperand &MO : MRI.reg_operands(LI.reg())) {
const MachineInstr *MI = MO.getParent();
if (MI->isInlineAsm() && MI->mayFoldInlineAsmRegOp(MI->getOperandNo(&MO)))
return true;
}

return false;
}

float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
SlotIndex *End) {
MachineRegisterInfo &MRI = MF.getRegInfo();
Expand Down Expand Up @@ -315,7 +326,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
// into instruction itself makes perfect sense.
if (ShouldUpdateLI && LI.isZeroLength(LIS.getSlotIndexes()) &&
!LI.isLiveAtIndexes(LIS.getRegMaskSlots()) &&
!isLiveAtStatepointVarArg(LI)) {
!isLiveAtStatepointVarArg(LI) && !canMemFoldInlineAsm(LI, MRI)) {
LI.markNotSpillable();
return -1.0;
}
Expand Down

0 comments on commit 284c699

Please sign in to comment.