[llvm] [RISCV] improve `musttail` support (PR #170547)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 3 12:19:37 PST 2025


================
@@ -23670,16 +23674,47 @@ bool RISCVTargetLowering::isEligibleForTailCallOptimization(
       return false;
   }
 
-  // Byval parameters hand the function a pointer directly into the stack area
-  // we want to reuse during a tail call. Working around this *is* possible
-  // but less efficient and uglier in LowerCall.
-  for (auto &Arg : Outs)
-    if (Arg.Flags.isByVal())
-      return false;
+  // If the callee takes no arguments then go on to check the results of the
+  // call.
+  const MachineRegisterInfo &MRI = MF.getRegInfo();
+  const SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
+  if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
+    return false;
 
   return true;
 }
 
+SDValue RISCVTargetLowering::addTokenForArgument(SDValue Chain,
----------------
topperc wrote:

Should this be moved to TargetLowering or SelectionDAG so AArch64, AMDGPU, LoongAArch, and RISCV can share it without duplication?

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


More information about the llvm-commits mailing list