llvm / llvm/llvm-project

sret unnecessarily blocks tail calls on X86

Open
#222,274 2 comments 0 reactions 0 assignees View on GitHub
backend:X86 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```llvm
%"string" = type { i64, i64, ptr }

define void @string_ctor(ptr sret(%"string") %agg.result) {
tail call void @func(ptr %agg.result)
ret void
}

declare dso_local void @func(ptr)
```
Currently causes a `call func` on X86, even though it should be perfectly safe to tail-call AFAICT. For some reason the `sret` breaks the tail call.

This has been reduced from libc++'s `string` implementation.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided LLVM IR on X86 and inspect the tail-call lowering path for functions with an sret parameter. Done means the generated X86 code uses a tail call to func while preserving correct sret behavior, with a regression test covering the reduced case.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.