Skip to content

Commit

Permalink
[ARM] Allow functions with sret returns to be tail-called
Browse files Browse the repository at this point in the history
It is valid to tail-call a function which returns through an sret
argument, as long as we have an incoming sret pointer to pass on.
  • Loading branch information
ostannard committed Oct 25, 2024
1 parent c1eb790 commit 82e6472
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3031,7 +3031,7 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
// return semantics.
bool isCalleeStructRet = Outs.empty() ? false : Outs[0].Flags.isSRet();
bool isCallerStructRet = MF.getFunction().hasStructRetAttr();
if (isCalleeStructRet || isCallerStructRet) {
if (isCalleeStructRet != isCallerStructRet) {
LLVM_DEBUG(dbgs() << "false (struct-ret)\n");
return false;
}
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/ARM/musttail.ll
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,25 @@ define i32 @fewer_args_tail(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%ret = tail call i32 @many_args_callee(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6)
ret i32 %ret
}

declare void @sret_callee(ptr sret({ double, double }) align 8)

; Functions which return by sret can be tail-called because the incoming sret
; pointer gets passed through to the callee.
define void @sret_caller_tail(ptr sret({ double, double }) align 8 %result) {
; CHECK-LABEL: sret_caller_tail:
; CHECK: @ %bb.0: @ %entry
; CHECK-NEXT: b sret_callee
entry:
tail call void @sret_callee(ptr sret({ double, double }) align 8 %result)
ret void
}

define void @sret_caller_musttail(ptr sret({ double, double }) align 8 %result) {
; CHECK-LABEL: sret_caller_musttail:
; CHECK: @ %bb.0: @ %entry
; CHECK-NEXT: b sret_callee
entry:
musttail call void @sret_callee(ptr sret({ double, double }) align 8 %result)
ret void
}

0 comments on commit 82e6472

Please sign in to comment.