Skip to content

Bounds checks: make MergeEdgeAssertions more precise #113233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2025

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Mar 6, 2025

This PR elides bounds checks in #113054 (closes #113054)

It turned out that MergeEdgeAssertions used to depend on order of assertions when it was tightening them so the behavior was different for tightening BinOpArray vs Constant (whoever comes first). Now the logic is more sophisticated and doesn't depend on the order of assertions.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 6, 2025
@EgorBo EgorBo force-pushed the precise-mergeassertions branch from 1772734 to dc2cb16 Compare March 7, 2025 01:08
@EgorBo EgorBo marked this pull request as ready for review March 7, 2025 02:42
@Copilot Copilot AI review requested due to automatic review settings March 7, 2025 02:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@EgorBo
Copy link
Member Author

EgorBo commented Mar 7, 2025

PTAL @AndyAyersMS @jakobbotsch @dotnet/jit-contrib Diffs

@MihaZupan
Copy link
Member

A bunch of hits on Regex: https://gist.github.com/MihuBot/f104c03eb53bf3c2f724d70a520636d1

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

This method is getting pretty large/unwieldy, you might think about how it could be broken up.

I wonder if we have order dependencies elsewhere in AP, often we stop at the first assertion we find that tells us anything.

Would also be interesting to have a stress mode or something that just reverse the order of assertion iteration. If this is not zero diff then we have things to explore.

@EgorBo
Copy link
Member Author

EgorBo commented Mar 7, 2025

Yep, I plan a massive clean up (zero-diff) here and will inject stress modes.

In this case diffs appeared because of the order e.g.:

if X > 100 appears before "X > arrLen" we used to take "X > 100" and ignored "X > arrLen"
if X > arrLen appears before "X >100" then we used to intentionally ignore "X > 100" with "we think arrLen is better" comment

Now we always prefer "X > arrLen" (but only if the 'preferredBound' was set) - we can play with this heuristic and e.g. accept 0/1 constants, but the diffs are mixed

also, a few missing rules that I added

@EgorBo EgorBo merged commit 7cf676f into dotnet:main Mar 7, 2025
111 of 113 checks passed
@EgorBo EgorBo deleted the precise-mergeassertions branch March 7, 2025 22:10
@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT: Redundant bounds check depending on branch order
3 participants