Missed optimization with slice::get_unchecked
followed by <slice as Index>::index
at a lower index
#116878
Labels
A-codegen
Area: Code generation
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried this code:
Compile with
-Copt-level=3
on godbolt.org (godbolt link)I expected to see this happen: Both functions should compile to approximately the same thing, with no bounds check on the
s[0]
since the optimizer should be able to see that the slice is at least of length 2 due to the previous unchecked indexing.Instead, this happened:
cannot_elide_bounds_check
contains a bounds check (onlycan_elide_bounds_check
does not contain a bounds check).Meta
rustc stable (1.73.0), nightly (2023-10-17), and 1.58.0 (when
Option::unwrap_unchecked
was stabilized) all have approximately the same codegen.rustc --version --verbose
:(no backtrace)
@rustbot label +C-optimization -C-bug
The text was updated successfully, but these errors were encountered: