[llvm] [RISCV] Support tail calls for functions with sret parameters (PR #223999)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 22:08:01 PDT 2026


================
@@ -27620,12 +27587,23 @@ bool RISCVTargetLowering::isEligibleForTailCallOptimization(
     if (VA.getLocInfo() == CCValAssign::Indirect)
       return false;
 
-  // Do not tail call opt if either caller or callee uses struct return
-  // semantics.
-  auto IsCallerStructRet = Caller.hasStructRetAttr();
+  // If the callee has an sret parameter, conservatively require it to receive
+  // the caller's sret pointer. If only the caller has an sret parameter, treat
+  // that pointer like an ordinary pointer when passing call arguments.
+  // TODO: Support other sret buffers that outlive the caller, such as globals.
+  auto IsCallerStructRet =
+      !Caller.arg_empty() && Caller.getArg(0)->hasStructRetAttr();
----------------
renndong wrote:

Yes, `Caller.hasStructRetAttr()` is the generic rule of LLVM IR, it allows return a structure through first or second argument. But under the RISC-V ABI, the sret pointer must be passed as the first argument.

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


More information about the llvm-commits mailing list