All the unrolling makes it hard for llvm to optimize it out. Sample: https://godbolt.org/g/R9nLvC
assume(index < len) but we couldn't quite get it to pass tests. Will need to give it another try with some fresh eyes.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.
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.