Skip to content

Unify O2K_CHECKED_BOUND_ADD_CNS and O2K_VN#128165

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:remove-o2k_bound
May 16, 2026
Merged

Unify O2K_CHECKED_BOUND_ADD_CNS and O2K_VN#128165
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:remove-o2k_bound

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented May 13, 2026

I decided that it makes no sense to have these separate. So now the semantics of O2K_VN_ADD_CNS:

  1. Decomposed "X+CNS" into op2.GetVN() being X and CNS being op2.GetCNS(). Exactly like O2K_CHECKED_BOUND_ADD_CNS used to be. The decomposition allows us to avoid calling GetVNFunc in the hot loop in MergeEdgeAssertions since we usually are more interested in that X rather than the whole ADD's VN.
  2. O2K_VN_ADD_CNS alone doesn't imply that anything is non-negative and no callers assume that (we used to have a bug where IsVNCheckedBound was assumed to be unconditionally never-negative). There is GetOp2().IsVNNeverNegative() which only exists because bound check node actually produce two assertions we can't spawn today because trees may only have 1 assertion. I'm thinking of solving this by introducing an aggregate (or just allow trees to have 2 assertions), or just add a fake COMMA
  3. I intentionally tried to make this almost 0 diffs, but there are just a few improvements I couldn't shut (they're not related to the non-negativitiy).

Copilot AI review requested due to automatic review settings May 13, 2026 20:57
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 13, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

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.

Pull request overview

This PR refactors the JIT's assertion descriptor types by collapsing the two related op2 kinds — O2K_CHECKED_BOUND_ADD_CNS and O2K_VN — into a single, unified O2K_VN_ADD_CNS. The new kind always decomposes op2 as vn + cns, with an explicit IsVNNeverNegative() flag carried separately. This removes a footgun where "checked bound" was previously (incorrectly) treated by some callers as implying non-negativity, and simplifies the assertion-table bookkeeping for VN-vs-VN relop assertions in global propagation.

Changes:

  • Replace O2K_CHECKED_BOUND_ADD_CNS and O2K_VN with a single O2K_VN_ADD_CNS; rename GetCheckedBound/GetCheckedBoundConstant/IsCheckedBoundNeverNegative to GetVN/GetCns/IsVNNeverNegative and update CreateForArrLen/CreateCompareCheckedBound/CreateRelopVN and Equals accordingly.
  • Update RangeCheck::MergeEdgeAssertionsWorker to use the new accessors and add an explicit IsVNCheckedBound(GetVN()) guard on the branch that derives a keBinOpArray limit (since arbitrary VNs from CreateRelopVN now also flow through O2K_VN_ADD_CNS).
  • In optAssertionPropGlobal_RelOp, restrict the direct relop-match to cns == 0 for O2K_VN_ADD_CNS and consolidate the duplicate-registration logic in optAddAssertion to a single branch.

Reviewed changes

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

File Description
src/coreclr/jit/compiler.h Unifies the two op2 kinds into O2K_VN_ADD_CNS, renames accessors/fields, updates IsBoundsCheckNoThrow, Equals, and the three factory helpers.
src/coreclr/jit/assertionprop.cpp Updates print/debug/complement/dedup paths to the new kind; adds cns == 0 guard for the direct relop-match in global prop.
src/coreclr/jit/rangecheck.cpp Switches all MergeEdgeAssertionsWorker branches to the new accessors and adds IsVNCheckedBound guard on the keBinOpArray branch to avoid feeding arbitrary VNs into length-shaped Limits.

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented May 14, 2026

PTAL @jakobbotsch cc @dotnet/jit-contrib just a clean up, minimal diffs.

@EgorBo EgorBo requested a review from jakobbotsch May 14, 2026 11:04
Comment thread src/coreclr/jit/rangecheck.cpp
@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented May 16, 2026

/ba-g timeout

@EgorBo EgorBo enabled auto-merge (squash) May 16, 2026 00:30
@EgorBo EgorBo merged commit 88dbd11 into dotnet:main May 16, 2026
142 of 144 checks passed
@EgorBo EgorBo deleted the remove-o2k_bound branch May 16, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

3 participants