Commit 0b9d2cc
Remove bounds checks for Phi indices (#121640)
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.:
```
arr[2] = 0; // creates an assertion that arr is at least 3 elements.
arr[1] = 0; // bound check is optimized away
```
This PR extends this logic by handling Phi indices.
Should remove bounds checks for cases like:
```cs
arr[cond1 ? 10 : 12] = 0; // means arr has at least 11 elements
arr[8] = 0; // redundant bounds check
```
or even:
```cs
arr[cond1 ? 10 : 12] = 0;
arr[cond2 ? 1 : 2] = 0;
```
Some nice
[diffs](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1203834&view=ms.vss-build-web.run-extensions-tab)
(although, mostly because I removed unnecessary TypeOfVN checks)
---------
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Theodore Tsirpanis <[email protected]>1 parent e91f40d commit 0b9d2cc
1 file changed
+30
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5437 | 5437 | | |
5438 | 5438 | | |
5439 | 5439 | | |
5440 | | - | |
5441 | | - | |
| 5440 | + | |
5442 | 5441 | | |
5443 | | - | |
5444 | | - | |
5445 | | - | |
5446 | | - | |
5447 | | - | |
| 5442 | + | |
| 5443 | + | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
| 5448 | + | |
| 5449 | + | |
| 5450 | + | |
| 5451 | + | |
| 5452 | + | |
| 5453 | + | |
| 5454 | + | |
| 5455 | + | |
| 5456 | + | |
| 5457 | + | |
| 5458 | + | |
| 5459 | + | |
| 5460 | + | |
| 5461 | + | |
| 5462 | + | |
| 5463 | + | |
| 5464 | + | |
| 5465 | + | |
| 5466 | + | |
| 5467 | + | |
| 5468 | + | |
| 5469 | + | |
| 5470 | + | |
5448 | 5471 | | |
5449 | | - | |
5450 | | - | |
5451 | | - | |
5452 | | - | |
5453 | | - | |
5454 | | - | |
5455 | 5472 | | |
5456 | 5473 | | |
5457 | 5474 | | |
| |||
0 commit comments