Skip to content

JIT: bail on flipping post-layout JTRUE when reversal needs new IR#127746

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-assertion-failure-jit
Draft

JIT: bail on flipping post-layout JTRUE when reversal needs new IR#127746
Copilot wants to merge 3 commits intomainfrom
copilot/fix-assertion-failure-jit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

optOptimizePostLayout runs after LSRA and called gtReverseCond, which can fall back to wrapping the operand in a fresh GT_EQ(tree, 0). The new GT_INT_CON child is never inserted into the LIR, tripping found use of a node that is not in the LIR sequence in checked builds (reported by Fuzzlyn on linux-arm32). The fallback was also reached whenever LSRA inserted a GT_COPY/GT_RELOAD on top of the JTRUE operand, since the wrapper is not itself a comparison.

Description

  • gentree.cpp / compiler.h — Extract gtTryReverseCond(GenTree*) -> bool that reverses compares, JCC/SETCC, JCMP/JTEST, and integral constants in place. gtReverseCond becomes a thin wrapper that adds the GT_EQ(tree, 0) fallback when in-place reversal isn't possible, preserving semantics for all existing callers.
  • optimizer.cpp — In optOptimizePostLayout, peel GT_COPY/GT_RELOAD off the GT_JTRUE operand via gtSkipReloadOrCopy(), then use gtTryReverseCond and skip flipping the block if it returns false rather than mutating the LIR.
GenTree* cond = test;
if (test->OperIs(GT_JTRUE))
{
    cond = test->gtGetOp1()->gtSkipReloadOrCopy();
}

if (!gtTryReverseCond(cond))
{
    continue;
}

Copilot AI self-assigned this May 4, 2026
Copilot AI review requested due to automatic review settings May 4, 2026 12:52
Copilot AI review requested due to automatic review settings May 4, 2026 12:52
Copilot AI requested review from Copilot and removed request for Copilot May 4, 2026 13:00
Copilot AI changed the title [WIP] Fix assertion failure in JIT during optimize post-layout JIT: bail on flipping post-layout JTRUE when reversal needs new IR May 4, 2026
Copilot AI requested a review from jakobbotsch May 4, 2026 13:02
Comment thread src/coreclr/jit/gentree.cpp
Copilot AI requested review from Copilot and jakobbotsch and removed request for Copilot May 4, 2026 13:10
@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 4, 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.

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.

JIT: Assertion failed found use of a node that is not in the LIR sequence during 'Optimize post-layout'

2 participants