JIT: propagate vector constants through assertion prop#127124
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends CoreCLR JIT assertion propagation to recognize and propagate SIMD (vector) constants across equality/inequality guards, enabling more constant folding in common “guard then use” patterns for Vector64/128/256/512 integral vectors.
Changes:
- Added a new assertion operand kind
O2K_CONST_VECbacked by an arena-allocatedsimd_t, including equality/printing/factory support. - Taught
optAssertionGenJtrue/ assertion creation to recognizeVector*_op_Equality/op_Inequalitypatterns againstGT_CNS_VECand produce usable assertions (excluding FP base types). - Implemented SIMD constant materialization during propagation (including VN-based propagation into SIMD-typed loads such as byref ABI patterns).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/jit/compiler.h | Adds O2K_CONST_VEC plumbing to assertion descriptors, including storage, equality, and factory helpers; extends propagation eligibility for VN-based SIMD constants. |
| src/coreclr/jit/assertionprop.cpp | Recognizes SIMD compare patterns when generating assertions and propagates vector constants (including VN-based propagation for SIMD loads). |
This comment has been minimized.
This comment has been minimized.
This was referenced Apr 20, 2026
This comment has been minimized.
This comment has been minimized.
This was referenced Apr 20, 2026
Open
EgorBo
commented
Apr 20, 2026
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/e8f6f2ee-359c-4b32-b822-877ec029ddc6 Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
3 tasks
tannergooding
approved these changes
Apr 21, 2026
This comment was marked as resolved.
This comment was marked as resolved.
tannergooding
approved these changes
Apr 23, 2026
This was referenced Apr 23, 2026
This was referenced Apr 23, 2026
Member
Author
|
/ba-g timeouts |
EgorBo
added a commit
to EgorBo/runtime-1
that referenced
this pull request
Apr 28, 2026
…tNode When `op1` is not invariant or a local, `fgMakeMultiUse(&op1)` rewrites `op1` into `COMMA(STORE temp, LCL_VAR temp)` and returns a fresh load of `temp`. The STORE is the only place `temp` is written, so it must evaluate before any later read of `temp`. The non-AVX-512 branch passed the clean clone as the first argument of `AND_NOT` and the COMMA-wrapped tree as the second. `AND_NOT(a, b)` decomposes into `AND(a, NOT(b))`, so `a` evaluates first - meaning the `LCL_VAR temp` read happened before the STORE inside `b`, producing garbage for the non-NaN'd input. The bug was latent: prior to dotnet#127124 / dotnet#127402 the inner `IsNaN(op1)` expanded into real per-element compares that kept enough materialization around to mask the bad ordering. With SIMD32/64 constant propagation, `CompareNotEqual(temp, temp)` value-numbers as AllBitsSet and the entire right subtree collapses to constants, leaving only the broken left-side read - which is what the `Vector512Tests.ConvertToInt32Test` failure on non-AVX-512 hosts (libraries-jitstress-random, nativeaot-outerloop, iossimulator) was actually exercising. Fix: pass `op1` (the COMMA, evaluated first) as `AND_NOT`'s first argument and use the side-effect-free `op1Clone1` for the IsNaN check. Verified by repro on a non-AVX-512 host (DOTNET_EnableAVX512=0): Vector512.ConvertToInt32(Vector512.Create(float.MinValue)) now returns Vector512<int>.Create(int.MinValue) as expected. SPMI benchmarks.run replay clean. Fixes dotnet#127440. Supersedes dotnet#127499 (which gated unreachable code in `impSpecialIntrinsic` - `NI_Vector512_ConvertToInt32` is already filtered upstream by `lookupId` on non-AVX-512 hosts, so that gate did not actually fix the failure). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new kind of an assertion -
O2K_CONST_VEC.Diffs