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

Jiaxun Yang via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 06:23:36 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
----------------
FlyGoat wrote:

Or maybe allow `insertBranch` to reject a unsafe insertion? Adding a `caninsertBranch` hook? All seems to be a little bit awkward to me.

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


More information about the llvm-commits mailing list