[llvm] [TargetInstrInfo] enable foldMemoryOperand for InlineAsm (PR #70743)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 13:11:35 PST 2023


================
@@ -565,6 +565,64 @@ static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
   return NewMI;
 }
 
+static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI,
+                                    const TargetInstrInfo &TII) {
+  MachineOperand &MO = MI->getOperand(OpNo);
+  const VirtRegInfo &RI = AnalyzeVirtRegInBundle(*MI, MO.getReg());
+
+  // If the machine operand is tied, untie it first.
+  if (MO.isTied()) {
+    unsigned TiedTo = MI->findTiedOperandIdx(OpNo);
+    MI->untieRegOperand(OpNo);
----------------
qcolombet wrote:

I just realized that we call this recursively on the tied operand, so we would produce:
```
@a = @a + ...
```
So in theory this is fine.

In practice, I don't believe this works all the time because IIRC, for instance, x86 cannot have a memory operand both as definition and as argument of the same instruction.

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


More information about the llvm-commits mailing list