- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Closed
Copy link
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
In this code:
pub fn foo(g: fn()) {
    let _var: Option<Box<i32>> = None;
    g();
}Assembly:
core::ptr::drop_in_place<core::option::Option<alloc::boxed::Box<i32>>>:
        mov     rdi, qword ptr [rdi]
        test    rdi, rdi
        je      .LBB0_1
        mov     esi, 4
        mov     edx, 4
        jmp     qword ptr [rip + __rust_dealloc@GOTPCREL]
.LBB0_1:
        ret
example::foo:
        push    rbx
        sub     rsp, 16
        mov     qword ptr [rsp + 8], 0
        call    rdi
        add     rsp, 16
        pop     rbx
        ret
        mov     rbx, rax
        lea     rdi, [rsp + 8]
        call    core::ptr::drop_in_place<core::option::Option<alloc::boxed::Box<i32>>>
        mov     rdi, rbx
        call    _Unwind_Resume@PLT
        ud2
DW.ref.rust_eh_personality:
        .quad   rust_eh_personality_var is known to be None so the deallocation is optimized away in the normal flow. But in landing pad for unwinding, it still generates a branch to check if _var is null. But it's a local variable which is not able to be modified in anywhere else and should be known to be null.
I'm expecting the drop of _var should be completely elided so that g() can be a tail call.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.