- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
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.C-bugCategory: This is a bug.Category: This is a bug.I-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
This is a reopening of #37114 which was fixed in 1.28.0 but seems to have regressed again since 1.30.0.
pub fn foo(v: &mut Vec<i32>) {
    let len = v.len();
    assert!(len > 1);
    v[len - 2] += 1;
    v.pop();
}The asm for 1.38 is
example::foo:
        push    rax
        mov     rax, qword ptr [rdi + 16]
        cmp     rax, 2
        jb      .LBB7_4
        mov     rcx, qword ptr [rdi]
        add     dword ptr [rcx + 4*rax - 8], 1
; 1.28 does not generate these 3 instructions:
        mov     rax, qword ptr [rdi + 16]
        test    rax, rax
        je      .LBB7_3
; end of unnecessary code
        add     rax, -1
        mov     qword ptr [rdi + 16], rax
.LBB7_3:
        pop     rax
        ret
.LBB7_4:
        call    std::panicking::begin_panic
        ud2Metadata
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.C-bugCategory: This is a bug.Category: This is a bug.I-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.