[llvm] [X86] Elect to tail call when `sret` ptr is passed to the callee (PR #146575)
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 11:01:27 PDT 2025
================
@@ -725,27 +662,17 @@ define fastcc void @t21_sret_to_sret_more_args2(ptr noalias sret(%struct.foo) %a
;
; X64-LABEL: t21_sret_to_sret_more_args2:
; X64: # %bb.0:
-; X64-NEXT: pushq %rbx
; X64-NEXT: movl %esi, %eax
-; X64-NEXT: movq %rdi, %rbx
; X64-NEXT: movl %edx, %esi
; X64-NEXT: movl %eax, %edx
-; X64-NEXT: callq f_sret at PLT
-; X64-NEXT: movq %rbx, %rax
-; X64-NEXT: popq %rbx
-; X64-NEXT: retq
+; X64-NEXT: jmp f_sret at PLT # TAILCALL
;
; X32-LABEL: t21_sret_to_sret_more_args2:
; X32: # %bb.0:
-; X32-NEXT: pushq %rbx
; X32-NEXT: movl %esi, %eax
-; X32-NEXT: movq %rdi, %rbx
; X32-NEXT: movl %edx, %esi
; X32-NEXT: movl %eax, %edx
-; X32-NEXT: callq f_sret at PLT
-; X32-NEXT: movl %ebx, %eax
-; X32-NEXT: popq %rbx
-; X32-NEXT: retq
+; X32-NEXT: jmp f_sret at PLT # TAILCALL
----------------
rnk wrote:
Please add new whitebox test cases that try to fool your heuristic. The C code that comes to mind for me looks like:
```
typedef struct SRet {
long x, y, z;
} SRet;
SRet foo();
SRet bar(SRet *p) {
SRet r = {0, 0, 0};
*p = foo();
return r;
}
```
The call to `foo` could end up in the tail position, but the implicit sret arg is not forwarded to `foo` here.
https://github.com/llvm/llvm-project/pull/146575
More information about the llvm-commits
mailing list