diff --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp index 6e98e2384ef97..bf114921a7d22 100644 --- a/llvm/lib/CodeGen/CalcSpillWeights.cpp +++ b/llvm/lib/CodeGen/CalcSpillWeights.cpp @@ -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(); @@ -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; }