-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Bounds check not optimized out after {r}position on a slice #45964
Comments
According to #44899 (comment) there was a fix in upstream LLVM. We may reopen the PR if we backport the fix. |
I already backported the fix, it's just that someone needs to make an "up the LLVM" PR that includes it. |
…k, r=dtolnay Optimize slice.{r}position result bounds check Second attempt of rust-lang#45501 Fixes rust-lang#45964 Demo: https://godbolt.org/g/N4mBHp
Use the slice length to hint the optimizer about iter.position result Using the len of the iterator doesn't give the same result. That's also why we can't generalize it to all TrustedLen iterators. Problem demo: https://godbolt.org/g/MXg2ae Fix demo: https://godbolt.org/g/P8q5aZ Second attempt of #47333 Third attempt of #45501 Fixes #45964
Reopening this because of #48209. (We can close again if it turns out the |
It's possible #49551 could help with this, as it should make it easier for LLVM to understand the length of a slice iterator 🤞 |
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. |
Rollup of 10 pull requests Successful merges: - rust-lang#74477 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm) - rust-lang#77836 (transmute_copy: explain that alignment is handled correctly) - rust-lang#78126 (Properly define va_arg and va_list for aarch64-apple-darwin) - rust-lang#78137 (Initialize tracing subscriber in compiletest tool) - rust-lang#78161 (Add issue template link to IRLO) - rust-lang#78214 (Tweak match arm semicolon removal suggestion to account for futures) - rust-lang#78247 (Fix rust-lang#78192) - rust-lang#78252 (Add codegen test for rust-lang#45964) - rust-lang#78268 (Do not try to report on closures to avoid ICE) - rust-lang#78295 (Add some regression tests) Failed merges: r? `@ghost`
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.The text was updated successfully, but these errors were encountered: