Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tails calls are not being emitted as such #45499

Open
jrmuizel opened this issue Oct 24, 2017 · 3 comments
Open

Tails calls are not being emitted as such #45499

jrmuizel opened this issue Oct 24, 2017 · 3 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jrmuizel
Copy link
Contributor

The following rust code should get tail calls:

pub fn moo() -> String {
    goo()
}

#[inline(never)]
pub fn goo() -> String {
    "https://".to_string()
}

Instead we get:

example::moo:
        push    rbp
        mov     rbp, rsp
        push    rbx
        push    rax
        mov     rbx, rdi
        call    example::goo@PLT
        mov     rax, rbx
        add     rsp, 8
        pop     rbx
        pop     rbp
        ret

example::goo:
        push    rbp
        mov     rbp, rsp
        push    rbx
        push    rax
        mov     rbx, rdi
        lea     rsi, [rip + str.0]
        mov     edx, 8
        call    <alloc::string::String as core::convert::From<&'a str>>::from@PLT
        mov     rax, rbx
        add     rsp, 8
        pop     rbx
        pop     rbp
        ret

str.0:
        .ascii  "https://"
@jrmuizel
Copy link
Contributor Author

@sunfishcode thoughts?

@sunfishcode
Copy link
Member

The X86 backend currently refuses to tail-call any call with sret: llvm-mirror/llvm@a375d47. I don't know why that check is needed, and unfortunately there are no comments or testcases explaining it.

One option would be to dig into that code and figure out what the problems with struct returns are, if there are any, and then remove or refine that check.

Another might be to change Rust's lowering for things like String return types to use first-class aggregate return types rather than sret. This would have a much broader impact, and could potentially have other benefits, though it would have risks too.

@jrmuizel
Copy link
Contributor Author

@pietroalbini pietroalbini added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. labels Jan 23, 2018
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants