[llvm] 284c699 - [CalcSpillWeights] don't mark live intervals with spillable inlineasm ops as having infinite spill weight (#70747)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 12:49:11 PDT 2023


Author: Nick Desaulniers
Date: 2023-11-03T12:49:07-07:00
New Revision: 284c6990c133ed88f32de111accacc9f55a7a51d

URL: https://github.com/llvm/llvm-project/commit/284c6990c133ed88f32de111accacc9f55a7a51d
DIFF: https://github.com/llvm/llvm-project/commit/284c6990c133ed88f32de111accacc9f55a7a51d.diff

LOG: [CalcSpillWeights] don't mark live intervals with spillable inlineasm 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: https://github.com/llvm/llvm-project/issues/20571

Added: 
    

Modified: 
    llvm/lib/CodeGen/CalcSpillWeights.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp
index 6e98e2384ef975f..bf114921a7d220a 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;
   }


        


More information about the llvm-commits mailing list