Skip to content

Commit ec000a6

Browse files
[TargetInstrInfo] update INLINEASM memoperands once (#74135)
In commit b053359 ("[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
1 parent 47a40e8 commit ec000a6

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,8 @@ static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
567567

568568
static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI,
569569
const TargetInstrInfo &TII) {
570-
MachineOperand &MO = MI->getOperand(OpNo);
571-
const VirtRegInfo &RI = AnalyzeVirtRegInBundle(*MI, MO.getReg());
572-
573570
// If the machine operand is tied, untie it first.
574-
if (MO.isTied()) {
571+
if (MI->getOperand(OpNo).isTied()) {
575572
unsigned TiedTo = MI->findTiedOperandIdx(OpNo);
576573
MI->untieRegOperand(OpNo);
577574
// Intentional recursion!
@@ -591,24 +588,6 @@ static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI,
591588
F.setMemConstraint(InlineAsm::ConstraintCode::m);
592589
MachineOperand &MD = MI->getOperand(OpNo - 1);
593590
MD.setImm(F);
594-
595-
// Update mayload/maystore metadata, and memoperands.
596-
MachineMemOperand::Flags Flags = MachineMemOperand::MONone;
597-
MachineOperand &ExtraMO = MI->getOperand(InlineAsm::MIOp_ExtraInfo);
598-
if (RI.Reads) {
599-
ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayLoad);
600-
Flags |= MachineMemOperand::MOLoad;
601-
}
602-
if (RI.Writes) {
603-
ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayStore);
604-
Flags |= MachineMemOperand::MOStore;
605-
}
606-
MachineFunction *MF = MI->getMF();
607-
const MachineFrameInfo &MFI = MF->getFrameInfo();
608-
MachineMemOperand *MMO = MF->getMachineMemOperand(
609-
MachinePointerInfo::getFixedStack(*MF, FI), Flags, MFI.getObjectSize(FI),
610-
MFI.getObjectAlign(FI));
611-
MI->addMemOperand(*MF, MMO);
612591
}
613592

614593
// Returns nullptr if not possible to fold.
@@ -629,6 +608,26 @@ static MachineInstr *foldInlineAsmMemOperand(MachineInstr &MI,
629608

630609
foldInlineAsmMemOperand(&NewMI, Op, FI, TII);
631610

611+
// Update mayload/maystore metadata, and memoperands.
612+
const VirtRegInfo &RI =
613+
AnalyzeVirtRegInBundle(MI, MI.getOperand(Op).getReg());
614+
MachineOperand &ExtraMO = NewMI.getOperand(InlineAsm::MIOp_ExtraInfo);
615+
MachineMemOperand::Flags Flags = MachineMemOperand::MONone;
616+
if (RI.Reads) {
617+
ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayLoad);
618+
Flags |= MachineMemOperand::MOLoad;
619+
}
620+
if (RI.Writes) {
621+
ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayStore);
622+
Flags |= MachineMemOperand::MOStore;
623+
}
624+
MachineFunction *MF = NewMI.getMF();
625+
const MachineFrameInfo &MFI = MF->getFrameInfo();
626+
MachineMemOperand *MMO = MF->getMachineMemOperand(
627+
MachinePointerInfo::getFixedStack(*MF, FI), Flags, MFI.getObjectSize(FI),
628+
MFI.getObjectAlign(FI));
629+
NewMI.addMemOperand(*MF, MMO);
630+
632631
return &NewMI;
633632
}
634633

0 commit comments

Comments
 (0)