[llvm] [Mips][BranchFolding] Enable safe tail merging (PR #225382)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 05:41:04 PDT 2026


================
@@ -57,6 +59,23 @@ const MipsInstrInfo *MipsInstrInfo::create(MipsSubtarget &STI) {
   return createMipsSEInstrInfo(STI);
 }
 
+bool MipsInstrInfo::isLegalToSplitMBBAt(
+    MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const {
+  // Keep tail merging disabled for MIPS16, whose far branches clobber $ra.
+  if (Subtarget.inMips16Mode())
+    return false;
+
+  // Long branch expansion clobbers $at. Do not let tail merging introduce a
+  // branch while $at (or its 64-bit super-register) is live.
+  if (!MBB.getParent()->getRegInfo().tracksLiveness())
+    return false;
+  LivePhysRegs LiveRegs(*Subtarget.getRegisterInfo());
----------------
arsenm wrote:

Really shouldn't have to introduce throwaway LiveRegUnits instances 

https://github.com/llvm/llvm-project/pull/225382


More information about the llvm-commits mailing list