Open
Conversation
Synthesize a GT_ASSERTION marker statement at the start of stayInLoopSucc in optTryInvertWhileLoop, recording that the loop guard is known to be true on entry to the loop body. This compensates for cyclic value numbers from phi merges that otherwise prevent later phases (assertion prop, range check) from proving the guard still holds inside the loop body. The node is dropped before LIR by Rationalizer and skipped by IV strength reduction so it does not pin primary IVs. Alternative for dotnet#127117. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces a new HIR-only IR node (GT_ASSERTION) to seed assertion propagation with “known-true” loop-guard facts (especially after loop inversion), improving the JIT’s ability to eliminate redundant checks inside loops.
Changes:
- Add
GT_ASSERTIONas a new unary, no-value, not-LIR GenTree operator and plumb it through core visitors/analyses (VN, operand iterators, etc.). - Insert
GT_ASSERTIONat the top of the loop body after loop inversion to record the loop guard as true on loop entry. - Extend assertion propagation to generate one-sided bounds assertions from
GT_ASSERTIONand ensureGT_ASSERTIONstatements don’t reach LIR.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/gtlist.h | Defines the new GT_ASSERTION node kind and its properties (HIR-only / not LIR). |
| src/coreclr/jit/optimizer.cpp | Inserts GT_ASSERTION at loop-body entry after loop inversion to seed later optimizations. |
| src/coreclr/jit/assertionprop.cpp | Generates one-sided bounds assertions from GT_ASSERTION; adds a “no complementary assertion” mode. |
| src/coreclr/jit/compiler.h | Updates assertion helper signature to support optional complementary assertion creation. |
| src/coreclr/jit/rationalize.cpp | Drops GT_ASSERTION root statements before converting to LIR (backstop). |
| src/coreclr/jit/valuenum.cpp | Ensures VN can traverse GT_ASSERTION as a unary node. |
| src/coreclr/jit/gentree.cpp | Adds GT_ASSERTION support to operand-use iteration utilities. |
| src/coreclr/jit/compiler.hpp | Adds GT_ASSERTION to operand-use visitation. |
| src/coreclr/jit/liveness.cpp | Accounts for GT_ASSERTION in LIR liveness/DCE switch handling. |
| src/coreclr/jit/inductionvariableopts.cpp | Skips GT_ASSERTION statements so they don’t pin IV uses during analysis. |
Comments suppressed due to low confidence (1)
src/coreclr/jit/liveness.cpp:2574
- GT_ASSERTION is introduced as a pure marker (no codegen/observable effects), but here it is grouped under LIR nodes that are treated as "always side-effecting" for dead-code elimination. If GT_ASSERTION ever leaks into LIR, this classification will prevent DCE from removing it and makes it more likely to reach Lowering/CodeGen where it isn't supported. Consider treating GT_ASSERTION as removable/no-op in LIR DCE, or asserting it should never appear in LIR.
case GT_RECORD_ASYNC_RESUME:
case GT_KEEPALIVE:
case GT_ASSERTION:
case GT_SWIFT_ERROR_RET:
case GT_GCPOLL:
case GT_WASM_JEXCEPT:
// Never remove these nodes, as they are always side-effecting.
This was referenced Apr 21, 2026
Open
Member
Author
|
PTAL @jakobbotsch this is the impl you suggested. cc @dotnet/jit-contrib |
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.
an alternative for #127117
Diffs