[llvm] [X86InstrInfo] support memfold on spillable inline asm (PR #70832)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 13:46:55 PDT 2023


================
@@ -10333,5 +10333,15 @@ void X86InstrInfo::genAlternativeCodeSequence(
   }
 }
 
+// See also: X86DAGToDAGISel::SelectInlineAsmMemoryOperand().
+void X86InstrInfo::getFrameIndexOperands(SmallVectorImpl<MachineOperand> &Ops) const {
+  Ops.append({
+    MachineOperand::CreateImm(1),        // Scale
+    MachineOperand::CreateReg(0, false), // Index
+    MachineOperand::CreateImm(0),        // Disp
+    MachineOperand::CreateReg(0, false), // Segment
+  });
----------------
nickdesaulniers wrote:

> I guess if X86AddressMode isn't a per-target interface, then in foldInlineAsmMemOperand I'd have to do some target specific hack

example of what I roughly have in mind
```diff
diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index 5ede36505b5b..bfbe477f97a3 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -578,13 +578,21 @@ static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI,
     foldInlineAsmMemOperand(MI, TiedTo, FI, TII);
   }
 
+  SmallVector<MachineOperand, 4> NewOps;
+  MachineOperand *InsertPt;
+  if (isa<X86GenInstrInfo>(TII)) {
+    X86AddressMode M;
+    M.getFullAddress(NewOps);
+    InsertPt = MI->operands_begin() + OpNo;
+  } else {
   // Change the operand from a register to a frame index.
-  MO.ChangeToFrameIndex(FI, MO.getTargetFlags());
+    MO.ChangeToFrameIndex(FI, MO.getTargetFlags());
+    TII.getFrameIndexOperands(NewOps);
+    InsertPt = MI->operands_begin() + OpNo + 1;
+  }
 
-  SmallVector<MachineOperand, 4> NewOps;
-  TII.getFrameIndexOperands(NewOps);
   assert(!NewOps.empty() && "getFrameIndexOperands didn't create any operands");
-  MI->insert(MI->operands_begin() + OpNo + 1, NewOps);
+  MI->insert(InsertPt, NewOps);
 
   // Change the previous operand to a MemKind InlineAsm::Flag. The second param
   // is the per-target number of operands that represent the memory operand

```

https://github.com/llvm/llvm-project/pull/70832


More information about the llvm-commits mailing list