Rust: Bounds check not optimized out after {r}position on a slice

Created on 13 Nov 2017  路  6Comments  路  Source: rust-lang/rust

All the unrolling makes it hard for llvm to optimize it out. Sample: https://godbolt.org/g/R9nLvC

45501 has a fix that involves assume(index < len) but we couldn't quite get it to pass tests. Will need to give it another try with some fresh eyes.

A-LLVM C-enhancement E-needs-test I-slow T-compiler

Most helpful comment

@kennytm

I already backported the fix, it's just that someone needs to make an "up the LLVM" PR that includes it.

All 6 comments

According to https://github.com/rust-lang/rust/issues/44899#issuecomment-342487870 there was a fix in upstream LLVM. We may reopen the PR if we backport the fix.

@kennytm

I already backported the fix, it's just that someone needs to make an "up the LLVM" PR that includes it.

Reopening this because of #48209.

(We can close again if it turns out the assume is not necessary for optimizing out the bounds check on LLVM 6.)

It's possible https://github.com/rust-lang/rust/pull/49551 could help with this, as it should make it easier for LLVM to understand the length of a slice iterator :crossed_fingers:

I think this can be closed, they put the assume back after patching LLVM.

Could we have a codegen test? I'm marking this as E-needstest.

Was this page helpful?
0 / 5 - 0 ratings