Compiler do not remove slice bounds checks if index is guaranteed to be less than part of the length #110971
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
I tried this code:
I expected to see this happen: Since for any nonnegative integer
i / 2 < i
,j < i / 2
implies thatj < i
so we should not have bounds check here at indexing.Instead, this happened: Function checks j twice: first for
len / 2
then forlen
, and generates all code for panics.I noticed, that if we shorten slice first, it can remove bounds checks. E.g. this code doesn't generate any bounds checks:
Meta
rustc --version --verbose
:Godbolt link.
The text was updated successfully, but these errors were encountered: