[llvm] [TargetInstrInfo] update INLINEASM memoperands once (PR #74135)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 11:49:02 PST 2023


https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/74135

In commit b05335989239 ("[X86InstrInfo] support memfold on spillable inline asm
(#70832)"), I had a last minute fix to update the memoperands.  I originally
did this in the parent foldInlineAsmMemOperand call, updated the mir test via
update_mir_test_checks.py, but then decided to move it to the child call of
foldInlineAsmMemOperand.

But I forgot to rerun update_mir_test_checks.py. That last minute change caused
the same memoperand to be added twice when recursion occurred (for tied
operands). I happened to get lucky that trailing content omitted from the
CHECK line doesn't result in test failure.

But rerunning update_mir_test_checks.py on the mir test added in that commit
produces updated output. This is resulting in updates to the test that:
1. conflate additions to the test in child commits with simply updating the
   test as it should have been when first committed.
2. look wrong because the same memoperand is specified twice (we don't
   deduplicate memoperands when added). Example:

    INLINEASM ... :: (load (s32) from %stack.0) (load (s32) from %stack.0)

Fix the bug, so that in child commits, we don't have additional unrelated test
changes (which would be wrong anyways) from simply running
update_mir_test_checks.py.

Link: #20571


>From 6a30b6014b17db143c7810ed3ec336cfbe73e23b Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Fri, 1 Dec 2023 11:39:11 -0800
Subject: [PATCH] [TargetInstrInfo] update INLINEASM memoperands once

In commit b05335989239 ("[X86InstrInfo] support memfold on spillable inline asm
(#70832)"), I had a last minute fix to update the memoperands.  I originally
did this in the parent foldInlineAsmMemOperand call, updated the mir test via
update_mir_test_checks.py, but then decided to move it to the child call of
foldInlineAsmMemOperand.

But I forgot to rerun update_mir_test_checks.py. That last minute change caused
the same memoperand to be added twice when recursion occurred (for tied
operands). I happened to get lucky that trailing content omitted from the
CHECK line doesn't result in test failure.

But rerunning update_mir_test_checks.py on the mir test added in that commit
produces updated output. This is resulting in updates to the test that:
1. conflate additions to the test in child commits with simply updating the
   test as it should have been when first committed.
2. look wrong because the same memoperand is specified twice (we don't
   deduplicate memoperands when added). Example:

    INLINEASM ... :: (load (s32) from %stack.0) (load (s32) from %stack.0)

Fix the bug, so that in child commits, we don't have additional unrelated test
changes (which would be wrong anyways) from simply running
update_mir_test_checks.py.

Link: #20571
---
 llvm/lib/CodeGen/TargetInstrInfo.cpp | 42 +++++++++++++---------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index ac056fea8c37942..667b35891df8caa 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -567,11 +567,8 @@ static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
 
 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()) {
+  if (MI->getOperand(OpNo).isTied()) {
     unsigned TiedTo = MI->findTiedOperandIdx(OpNo);
     MI->untieRegOperand(OpNo);
     // Intentional recursion!
@@ -591,24 +588,6 @@ static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI,
   F.setMemConstraint(InlineAsm::ConstraintCode::m);
   MachineOperand &MD = MI->getOperand(OpNo - 1);
   MD.setImm(F);
-
-  // Update mayload/maystore metadata, and memoperands.
-  MachineMemOperand::Flags Flags = MachineMemOperand::MONone;
-  MachineOperand &ExtraMO = MI->getOperand(InlineAsm::MIOp_ExtraInfo);
-  if (RI.Reads) {
-    ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayLoad);
-    Flags |= MachineMemOperand::MOLoad;
-  }
-  if (RI.Writes) {
-    ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayStore);
-    Flags |= MachineMemOperand::MOStore;
-  }
-  MachineFunction *MF = MI->getMF();
-  const MachineFrameInfo &MFI = MF->getFrameInfo();
-  MachineMemOperand *MMO = MF->getMachineMemOperand(
-      MachinePointerInfo::getFixedStack(*MF, FI), Flags, MFI.getObjectSize(FI),
-      MFI.getObjectAlign(FI));
-  MI->addMemOperand(*MF, MMO);
 }
 
 // Returns nullptr if not possible to fold.
@@ -629,6 +608,25 @@ static MachineInstr *foldInlineAsmMemOperand(MachineInstr &MI,
 
   foldInlineAsmMemOperand(&NewMI, Op, FI, TII);
 
+  // Update mayload/maystore metadata, and memoperands.
+  const VirtRegInfo &RI = AnalyzeVirtRegInBundle(MI, MI.getOperand(Op).getReg());
+  MachineOperand &ExtraMO = NewMI.getOperand(InlineAsm::MIOp_ExtraInfo);
+  MachineMemOperand::Flags Flags = MachineMemOperand::MONone;
+  if (RI.Reads) {
+    ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayLoad);
+    Flags |= MachineMemOperand::MOLoad;
+  }
+  if (RI.Writes) {
+    ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayStore);
+    Flags |= MachineMemOperand::MOStore;
+  }
+  MachineFunction *MF = NewMI.getMF();
+  const MachineFrameInfo &MFI = MF->getFrameInfo();
+  MachineMemOperand *MMO = MF->getMachineMemOperand(
+      MachinePointerInfo::getFixedStack(*MF, FI), Flags, MFI.getObjectSize(FI),
+      MFI.getObjectAlign(FI));
+  NewMI.addMemOperand(*MF, MMO);
+
   return &NewMI;
 }
 



More information about the llvm-commits mailing list