Repository navigation
Remove bounds checks for Phi indices - #121640
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull Request Overview
This PR extends bounds check elimination to handle Phi indices (conditional expressions like ternary operators). The optimization identifies when an array has been accessed with a set of potential indices and eliminates redundant bounds checks for subsequent accesses that are guaranteed to be within bounds. For example, after arr[cond ? 10 : 5], the compiler knows the array has at least 6 elements, allowing it to eliminate the bounds check for arr[2].
Key Changes
- Replaced simple constant comparison logic with phi-aware analysis
- Introduced
tryGetMaxOrMinConstlambda to find minimum/maximum constants across phi predecessors - Removed unnecessary type checks that were previously required
|
PTAL @AndyAyersMS @dotnet/jit-contrib |
Co-authored-by: Copilot <[email protected]>
|
ah. oops, copilot has noticed a bug in my logic (tests didn't find anything), let me re-run the CI diffs, they should be smaller now 🙁 |
Co-authored-by: Theodore Tsirpanis <[email protected]>
Closes #121617
In global assertion prop we have an optimization that tries to optimize bound checks for
arr[cns]if we already have ArrBnds assertion for the same array with another constant index that is greater than this one, e.g.:This PR extends this logic by handling Phi indices.
Should remove bounds checks for cases like:
or even:
Some nice diffs (although, mostly because I removed unnecessary TypeOfVN checks)