Skip to content

Commit e270ec4

Browse files
committed
[X86] X86InstrInfo.cpp - Remove dead code for memory folding, NFCI
`commuteInstruction(MI, false, OpNum, CommuteOpIdx2)` should never create any new instruction, so we don't need to check and erase it.
1 parent 082fe9a commit e270ec4

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7205,27 +7205,7 @@ unsigned X86InstrInfo::commuteOperandsForFold(MachineInstr &MI,
72057205
if ((HasDef && Reg0 == Reg1 && Tied1) || (HasDef && Reg0 == Reg2 && Tied2))
72067206
return Idx1;
72077207

7208-
MachineInstr *CommutedMI = commuteInstruction(MI, false, Idx1, Idx2);
7209-
if (!CommutedMI) {
7210-
// Unable to commute.
7211-
return Idx1;
7212-
}
7213-
if (CommutedMI != &MI) {
7214-
// New instruction. We can't fold from this.
7215-
CommutedMI->eraseFromParent();
7216-
return Idx1;
7217-
}
7218-
7219-
return Idx2;
7220-
}
7221-
7222-
void X86InstrInfo::UndoCommuteForFold(MachineInstr &MI, unsigned Idx1,
7223-
unsigned Idx2) const {
7224-
// Folding failed again - undo the commute before returning.
7225-
MachineInstr *UncommutedMI = commuteInstruction(MI, false, Idx1, Idx2);
7226-
// New instruction. It doesn't need to be kept.
7227-
if (UncommutedMI && UncommutedMI != &MI)
7228-
UncommutedMI->eraseFromParent();
7208+
return commuteInstruction(MI, false, Idx1, Idx2) ? Idx2 : Idx1;
72297209
}
72307210

72317211
static void printFailMsgforFold(const MachineInstr &MI, unsigned Idx) {
@@ -7369,7 +7349,8 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
73697349
Alignment, /*AllowCommute=*/false);
73707350
if (NewMI)
73717351
return NewMI;
7372-
UndoCommuteForFold(MI, OpNum, CommuteOpIdx2);
7352+
// Folding failed again - undo the commute before returning.
7353+
commuteInstruction(MI, false, OpNum, CommuteOpIdx2);
73737354
}
73747355

73757356
printFailMsgforFold(MI, OpNum);
@@ -8156,7 +8137,8 @@ X86InstrInfo::foldMemoryBroadcast(MachineFunction &MF, MachineInstr &MI,
81568137
/*AllowCommute=*/false);
81578138
if (NewMI)
81588139
return NewMI;
8159-
UndoCommuteForFold(MI, OpNum, CommuteOpIdx2);
8140+
// Folding failed again - undo the commute before returning.
8141+
commuteInstruction(MI, false, OpNum, CommuteOpIdx2);
81608142
}
81618143

81628144
printFailMsgforFold(MI, OpNum);

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,6 @@ class X86InstrInfo final : public X86GenInstrInfo {
699699
/// \returns the index of operand that is commuted with \p Idx1. If the method
700700
/// fails to commute the operands, it will return \p Idx1.
701701
unsigned commuteOperandsForFold(MachineInstr &MI, unsigned Idx1) const;
702-
703-
/// Undo the commute of operands of \p MI at index \p Idx1 and index \p Idx2.
704-
void UndoCommuteForFold(MachineInstr &MI, unsigned Idx1, unsigned Idx2) const;
705702
};
706703
} // namespace llvm
707704

0 commit comments

Comments
 (0)