JIT: Reset compGenTreeID on failed Materialize to avoid leaking gen tree IDs#129528
JIT: Reset compGenTreeID on failed Materialize to avoid leaking gen tree IDs#129528Copilot wants to merge 4 commits into
Conversation
…ree IDs Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
|
@copilot These fields are DEBUG only, so add #ifdef DEBUG too |
…only Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
|
Fixes #129527 |
There was a problem hiding this comment.
Pull request overview
This PR updates JIT scalar-evolution IR materialization so that a failed attempt to materialize a Scev into GenTree IR does not advance the debug-only Compiler::compGenTreeID counter. This keeps Phase::Observations invariants intact when a phase reports MODIFIED_NOTHING but speculative IR construction partially occurred and then aborted.
Changes:
- Snapshot
m_compiler->compGenTreeID(DEBUG-only) before attempting IR materialization and restore it on failure. - Expand the wrapper
ScalarEvolutionContext::Materialize(Scev* scev)from a single conditional expression into an explicit success/failure path with a rollback.
Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
Added the regression test in |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
A Fuzzlyn-generated case tripped the
m_compGenTreeID == m_compiler->compGenTreeIDassertion (phase.cpp:47) during 'Optimize Induction Variables'. The phase reportedMODIFIED_NOTHING, yetcompGenTreeIDhad advanced.Root cause
The
GenTree* Materialize(Scev* scev)overload calls the internalMaterialize(scev, /*createIR*/ true, ...), which allocates IR nodes (bumpingcompGenTreeID) as it recurses but can still returnfalsepartway through — e.g. on anAddRec, a non-nullTYP_REF/TYP_BYREFconstant, or a 32-bitMULofTYP_LONG. The orphaned nodes leak their ID increments, so a phase that ultimately makes no change observes a changedcompGenTreeID.Changes
scev.cpp—GenTree* Materialize(Scev* scev): snapshotcompGenTreeIDbefore materializing IR and restore it on a false return. SincecompGenTreeIDis a DEBUG-only field, the snapshot and reset are guarded withINDEBUG.MaterializeVNusescreateIR=falseand never allocates IR, so it needs no change.