Skip to content

[LoongArch] Strengthen stack size estimation for LSX/LASX extension #146455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tangaac
Copy link
Contributor

@tangaac tangaac commented Jul 1, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2025

@llvm/pr-subscribers-backend-loongarch

Author: None (tangaac)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/146455.diff

2 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArchRegisterInfo.cpp (+12-1)
  • (modified) llvm/lib/Target/LoongArch/LoongArchRegisterInfo.h (+5)
diff --git a/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.cpp b/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.cpp
index 47fce37ce59f6..b3a6ca9acad63 100644
--- a/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.cpp
@@ -29,7 +29,6 @@ using namespace llvm;
 
 #define GET_REGINFO_TARGET_DESC
 #include "LoongArchGenRegisterInfo.inc"
-
 LoongArchRegisterInfo::LoongArchRegisterInfo(unsigned HwMode)
     : LoongArchGenRegisterInfo(LoongArch::R1, /*DwarfFlavour*/ 0,
                                /*EHFlavor*/ 0,
@@ -254,3 +253,15 @@ bool LoongArchRegisterInfo::canRealignStack(const MachineFunction &MF) const {
   // reserve it.
   return MRI->canReserveReg(LoongArchABI::getBPReg());
 }
+
+bool LoongArchRegisterInfo::saveScavengerRegister(
+    MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
+    MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC,
+    Register Reg) const {
+
+  DebugLoc DL;
+  const TargetInstrInfo &TII = *MBB.getParent()->getSubtarget().getInstrInfo();
+  TII.copyPhysReg(MBB, I, DL, LoongArch::R12, Reg, true);
+  TII.copyPhysReg(MBB, UseMI, DL, Reg, LoongArch::R12, true);
+  return true;
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.h b/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.h
index d1e40254c2972..e9e7ee930f7f6 100644
--- a/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.h
+++ b/llvm/lib/Target/LoongArch/LoongArchRegisterInfo.h
@@ -52,6 +52,11 @@ struct LoongArchRegisterInfo : public LoongArchGenRegisterInfo {
     return true;
   }
   bool canRealignStack(const MachineFunction &MF) const override;
+  bool saveScavengerRegister(MachineBasicBlock &MBB,
+                             MachineBasicBlock::iterator I,
+                             MachineBasicBlock::iterator &UseMI,
+                             const TargetRegisterClass *RC,
+                             Register Reg) const override;
 };
 } // end namespace llvm
 

@tangaac tangaac changed the title [LoongArch] use register scavenger to spill the register [LoongArch] Strengthen stack size estimation for LSX/LASX extension Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants