[all-commits] [llvm/llvm-project] 1c0ab0: [RISCV] Support tail calls for functions with sret...

renndong via All-commits all-commits at lists.llvm.org
Wed Sep 23 21:25:24 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1c0ab03c1c3e2ae36434162f78709025a0e0f66e
      https://github.com/llvm/llvm-project/commit/1c0ab03c1c3e2ae36434162f78709025a0e0f66e
  Author: renndong <liumingliang.dev at bytedance.com>
  Date:   2026-09-24 (Thu, 24 Sep 2026)

  Changed paths:
    M llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    A llvm/test/CodeGen/RISCV/tail-calls-sret.ll
    M llvm/test/CodeGen/RISCV/tail-calls.ll

  Log Message:
  -----------
  [RISCV] Support tail calls for functions with sret parameters (#223999)

This PR allows RISC-V tail calls from functions with an `sret`
parameter in a conservative set of cases.

RISC-V currently rejects a tail call whenever either the caller or the
callee has an `sret` parameter. This unnecessarily prevents tail-call
optimization.

For example:

```
%struct.Buffer = type { [7 x i32] }

; Function Attrs: mustprogress noinline nounwind uwtable
define void @foo(ptr sret(%struct.Buffer) align 4 %agg.result) {
entry:
  tail call void @bar(ptr %agg.result, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6)
  ret void
}
```

The caller-provided return buffer is passed to `foo` in a0. The same
pointer is then passed as the bar's ordinary first argument, 
which also uses a0.  Before this change, RISC-V emits a normal
call with a prologue and epilogue:

```
      addi	sp, sp, -16
	.cfi_def_cfa_offset 16
	sd	ra, 8(sp)                       # 8-byte Folded Spill
	.cfi_offset ra, -8
	li	a1, 1
	li	a2, 2
	li	a3, 3
	li	a4, 4
	li	a5, 5
	li	a6, 6
	call	bar
	ld	ra, 8(sp)                       # 8-byte Folded Reload
	.cfi_restore ra
	addi	sp, sp, 16
	.cfi_def_cfa_offset 0
	ret
```

With this change, the call can be emitted directly as:

```
	li	a1, 1
	li	a2, 2
	li	a3, 3
	li	a4, 4
	li	a5, 5
	li	a6, 6
	tail	bar
```

This change is conservative and only considers cases where the caller’s
sret pointer is passed to callees.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list