[llvm] e270ec4 - [X86] X86InstrInfo.cpp - Remove dead code for memory folding, NFCI
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 1 19:14:23 PST 2024
Author: Shengchen Kan
Date: 2024-02-02T11:14:07+08:00
New Revision: e270ec47cda26a8f0a3cdd195aa60992f109df8a
URL: https://github.com/llvm/llvm-project/commit/e270ec47cda26a8f0a3cdd195aa60992f109df8a
DIFF: https://github.com/llvm/llvm-project/commit/e270ec47cda26a8f0a3cdd195aa60992f109df8a.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/lib/Target/X86/X86InstrInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index 6d552e308beb2..0d30a31377727 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -7205,27 +7205,7 @@ unsigned X86InstrInfo::commuteOperandsForFold(MachineInstr &MI,
if ((HasDef && Reg0 == Reg1 && Tied1) || (HasDef && Reg0 == Reg2 && Tied2))
return Idx1;
- MachineInstr *CommutedMI = commuteInstruction(MI, false, Idx1, Idx2);
- if (!CommutedMI) {
- // Unable to commute.
- return Idx1;
- }
- if (CommutedMI != &MI) {
- // New instruction. We can't fold from this.
- CommutedMI->eraseFromParent();
- return Idx1;
- }
-
- return Idx2;
-}
-
-void X86InstrInfo::UndoCommuteForFold(MachineInstr &MI, unsigned Idx1,
- unsigned Idx2) const {
- // Folding failed again - undo the commute before returning.
- MachineInstr *UncommutedMI = commuteInstruction(MI, false, Idx1, Idx2);
- // New instruction. It doesn't need to be kept.
- if (UncommutedMI && UncommutedMI != &MI)
- UncommutedMI->eraseFromParent();
+ return commuteInstruction(MI, false, Idx1, Idx2) ? Idx2 : Idx1;
}
static void printFailMsgforFold(const MachineInstr &MI, unsigned Idx) {
@@ -7369,7 +7349,8 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
Alignment, /*AllowCommute=*/false);
if (NewMI)
return NewMI;
- UndoCommuteForFold(MI, OpNum, CommuteOpIdx2);
+ // Folding failed again - undo the commute before returning.
+ commuteInstruction(MI, false, OpNum, CommuteOpIdx2);
}
printFailMsgforFold(MI, OpNum);
@@ -8156,7 +8137,8 @@ X86InstrInfo::foldMemoryBroadcast(MachineFunction &MF, MachineInstr &MI,
/*AllowCommute=*/false);
if (NewMI)
return NewMI;
- UndoCommuteForFold(MI, OpNum, CommuteOpIdx2);
+ // Folding failed again - undo the commute before returning.
+ commuteInstruction(MI, false, OpNum, CommuteOpIdx2);
}
printFailMsgforFold(MI, OpNum);
diff --git a/llvm/lib/Target/X86/X86InstrInfo.h b/llvm/lib/Target/X86/X86InstrInfo.h
index 53e68e92f3a80..ee0d2d059df8d 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.h
+++ b/llvm/lib/Target/X86/X86InstrInfo.h
@@ -699,9 +699,6 @@ class X86InstrInfo final : public X86GenInstrInfo {
/// \returns the index of operand that is commuted with \p Idx1. If the method
/// fails to commute the operands, it will return \p Idx1.
unsigned commuteOperandsForFold(MachineInstr &MI, unsigned Idx1) const;
-
- /// Undo the commute of operands of \p MI at index \p Idx1 and index \p Idx2.
- void UndoCommuteForFold(MachineInstr &MI, unsigned Idx1, unsigned Idx2) const;
};
} // namespace llvm
More information about the llvm-commits
mailing list