[llvm] [CodeGen][Spill2Reg] Initial patch (PR #118832)
Wei Xiao via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 31 19:59:06 PST 2024
================
@@ -10893,5 +10947,208 @@ void X86InstrInfo::getFrameIndexOperands(SmallVectorImpl<MachineOperand> &Ops,
M.getFullAddress(Ops);
}
+bool X86InstrInfo::isLegalToSpill2Reg(Register Reg,
+ const TargetRegisterInfo *TRI,
+ const MachineRegisterInfo *MRI) const {
+ // Skip instructions like `$k1 = KMOVWkm %stack.1` because replacing stack
+ // with xmm0 results in an illegal instruction `movq %k1, %xmm0`.
+ if (X86::VK16RegClass.contains(Reg))
+ return false;
+
+ switch (unsigned Bits = TRI->getRegSizeInBits(Reg, *MRI)) {
+ case 64:
+ case 32:
+ case 16:
+ case 8:
+ return true;
+ }
+ return false;
+}
+
+bool X86InstrInfo::targetSupportsSpill2Reg(
+ const TargetSubtargetInfo *STI) const {
+ const X86Subtarget *X86STI = static_cast<const X86Subtarget *>(STI);
+ return X86STI->hasSSE41();
+}
+
+static inline bool useAVX(const TargetSubtargetInfo *STI) {
+ const X86Subtarget *X86STI = static_cast<const X86Subtarget *>(STI);
+ bool UseAVX = X86STI->hasAVX() && !Spill2RegNoAVX;
+ return UseAVX;
+}
+
+const TargetRegisterClass *
+X86InstrInfo::getVectorRegisterClassForSpill2Reg(const TargetRegisterInfo *TRI,
+ const TargetSubtargetInfo *STI,
+ Register SpilledReg) const {
+ const TargetRegisterClass *VecRegClass = TRI->getRegClass(
+ useAVX(STI) ? X86::VR128XRegClassID : X86::VR128RegClassID);
+ return VecRegClass;
+}
+
+bool X86InstrInfo::isSpill2RegProfitable(const MachineInstr *MI,
+ const TargetRegisterInfo *TRI,
+ const MachineRegisterInfo *MRI) const {
+ auto IsVecMO = [TRI, MI](const MachineOperand &MO) {
+ const MachineFunction *MF = MI->getParent()->getParent();
+ if (MO.isReg() && MO.getReg().isPhysical()) {
+ for (auto ClassID :
+ {X86::VR128RegClassID, X86::VR256RegClassID, X86::VR512RegClassID})
+ if (TRI->getRegClass(ClassID)->contains(MO.getReg()))
+ return true;
+ }
+ if (MO.isFI()) {
+ const unsigned MinVecBits =
+ TRI->getRegSizeInBits(*TRI->getRegClass(X86::VR128RegClassID));
+ if (MF->getFrameInfo().getObjectSize(MO.getIndex()) >= MinVecBits)
+ return true;
----------------
williamweixiao wrote:
could you please give me an instruction example that can return "true" here (i.e., vector-size stack access without any vector register operand)?
https://github.com/llvm/llvm-project/pull/118832
More information about the llvm-commits
mailing list