llvm-project/llvm/test/CodeGen/AArch64/tail-call-stack-args.ll
Guy David 4d4b7cc69e
[AArch64] Skip storing of stack arguments when lowering tail calls (#126735)
This issue starts in the selection DAG and causes the backend to emit
the following for a trivial tail call:
```
ldr w8, [sp]
str w8, [sp]
b func
```

I'm not too sure that checking for immutability of a specific stack
object is a good enough of a gurantee, because as soon a tail-call is
done lowering,`setHasTailCall()` is called and in that case perhaps a
pass is allowed to change the value of the object in-memory?

This can be extended to the ARM backend as well.
Removed the `tailcall` keyword from a few other test assets, I'm
assuming their original intent was left intact.
2025-06-06 11:26:24 +03:00

68 lines
2.7 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc %s -mtriple=aarch64 -o - | FileCheck %s --check-prefixes=CHECK,SDAG
; RUN: llc %s -mtriple=aarch64 -global-isel -o - | FileCheck %s --check-prefixes=CHECK,GI
; Tail calls which have stack arguments in the same offsets as the caller do not
; need to load and store the arguments from the stack.
declare void @func(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 %j)
define void @wrapper_func(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 %j) {
; CHECK-LABEL: wrapper_func:
; CHECK: // %bb.0:
; CHECK-NEXT: b func
tail call void @func(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 %j)
ret void
}
define void @wrapper_func_zero_arg(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 %j) {
; CHECK-LABEL: wrapper_func_zero_arg:
; CHECK: // %bb.0:
; CHECK-NEXT: str wzr, [sp, #8]
; CHECK-NEXT: b func
tail call void @func(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 0)
ret void
}
define void @wrapper_func_overriden_arg(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 %j) {
; CHECK-LABEL: wrapper_func_overriden_arg:
; CHECK: // %bb.0:
; CHECK-NEXT: ldr w8, [sp]
; CHECK-NEXT: str wzr, [sp]
; CHECK-NEXT: str w8, [sp, #8]
; CHECK-NEXT: b func
tail call void @func(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 0, i32 %i)
ret void
}
declare void @func_i1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i1 %j)
; FIXME: Support i1 passthrough stack arguments in GlobalISel.
define void @wrapper_func_i1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i1 %j) {
; SDAG-LABEL: wrapper_func_i1:
; SDAG: // %bb.0:
; SDAG-NEXT: b func_i1
;
; GI-LABEL: wrapper_func_i1:
; GI: // %bb.0:
; GI-NEXT: ldrb w8, [sp, #8]
; GI-NEXT: strb w8, [sp, #8]
; GI-NEXT: b func_i1
tail call void @func_i1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i1 %j)
ret void
}
declare void @func_signext_i1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i1 signext %j)
; FIXME: Support zero/sign-extended stack arguments.
define void @wrapper_func_i8(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i1 signext %j) {
; CHECK-LABEL: wrapper_func_i8:
; CHECK: // %bb.0:
; CHECK-NEXT: ldrsb w8, [sp, #8]
; CHECK-NEXT: strb w8, [sp, #8]
; CHECK-NEXT: b func_signext_i1
tail call void @func_signext_i1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i1 signext %j)
ret void
}