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

Unnecessary conditional branch generated #37114

Closed
tspiteri opened this issue Oct 12, 2016 · 2 comments
Closed

Unnecessary conditional branch generated #37114

tspiteri opened this issue Oct 12, 2016 · 2 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@tspiteri
Copy link
Contributor

This function

fn foo(v: &mut Vec<i32>) {
    let len = v.len();
    assert!(len > 1);
    v[len - 2] += 1;
    v.pop();
}

gives the following assembly

    .section    .text._ZN8rust_out3foo17h5b3f981e51393a1aE,"ax",@progbits
    .p2align    4, 0x90
    .type   _ZN8rust_out3foo17h5b3f981e51393a1aE,@function
_ZN8rust_out3foo17h5b3f981e51393a1aE:
    .cfi_startproc
    pushq   %rax
.Ltmp20:
    .cfi_def_cfa_offset 16
    movq    16(%rdi), %rax
    cmpq    $1, %rax
    jbe .LBB6_4
    movq    (%rdi), %rcx
    incl    -8(%rcx,%rax,4)
    movq    16(%rdi), %rax
    testq   %rax, %rax
    je  .LBB6_3
    decq    %rax
    movq    %rax, 16(%rdi)
.LBB6_3:
    popq    %rax
    retq
.LBB6_4:
    callq   _ZN3std9panicking11begin_panic17hc03e2830c2c89a5fE
.Lfunc_end6:
    .size   _ZN8rust_out3foo17h5b3f981e51393a1aE, .Lfunc_end6-_ZN8rust_out3foo17h5b3f981e51393a1aE
    .cfi_endproc

There is a conditional branch to .LBB6_4 if the length is < 2. There is no conditional branch created for v[len - 2], which is good, as the length is >= 2. However, there is a conditional branch to .LBB6_3 created for v.pop() which can never be taken.

@bluss
Copy link
Member

bluss commented Oct 12, 2016

Possibly due to #31681

@Mark-Simulacrum Mark-Simulacrum added the I-slow Issue: Problems and improvements with respect to performance of generated code. label May 14, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jun 22, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@tspiteri
Copy link
Contributor Author

This seems to be fixed in nightly, possibly due to #31681 being fixed.

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-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

3 participants