Improve bounds check for function that always return in-bounds index #98258
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
Consider following function:
On current rust 1.61.0 you can expect following output:
It would be nice to have some attribute or other way of saying that binary search is always returning a valid insert index and bounds check should be eliminated. You can get an expected output in current rustc versions via:
Since performing a search and then inserting is one of main
binary_search
use cases it might be worthwhile to implement such an optimization.See godbolt link for a whole example
The text was updated successfully, but these errors were encountered: