Skip to content

One more missed bounds check optimization #75525

Closed

Description

https://godbolt.org/z/3TGbK9

It looks like bounds checks are not eliminated when more than one restriction is applied to the index variable (i.e. when it's range checked from two sides). Late edit: It's also interesting that the issue disappears for certain lower limits. For example if idx > 2 && idx < 8 is optimized, while if idx > 5 && idx < 8 is not.

Using assumptions, the bounds checks are removed as expected: https://godbolt.org/z/Ksn8dW
However, if any of the assumptions is a GE or LE instead of a GT or LT, the bounds checks are back: https://godbolt.org/z/YhK1rT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions