Commit e6428cb
JIT: bail on flipping post-layout JTRUE when reversal needs new IR (#127746)
`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.
```cpp
GenTree* cond = test;
if (test->OperIs(GT_JTRUE))
{
cond = test->gtGetOp1()->gtSkipReloadOrCopy();
}
if (!gtTryReverseCond(cond))
{
continue;
}
```
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
Co-authored-by: dhartglassMSFT <248563697+dhartglassMSFT@users.noreply.github.com>1 parent 710da3b commit e6428cb
3 files changed
Lines changed: 51 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3919 | 3919 | | |
3920 | 3920 | | |
3921 | 3921 | | |
| 3922 | + | |
3922 | 3923 | | |
3923 | 3924 | | |
3924 | 3925 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3717 | 3717 | | |
3718 | 3718 | | |
3719 | 3719 | | |
3720 | | - | |
3721 | | - | |
3722 | | - | |
3723 | | - | |
3724 | | - | |
3725 | | - | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
3726 | 3733 | | |
3727 | 3734 | | |
3728 | 3735 | | |
| |||
3736 | 3743 | | |
3737 | 3744 | | |
3738 | 3745 | | |
| 3746 | + | |
3739 | 3747 | | |
3740 | | - | |
| 3748 | + | |
3741 | 3749 | | |
3742 | 3750 | | |
3743 | 3751 | | |
| 3752 | + | |
3744 | 3753 | | |
3745 | | - | |
| 3754 | + | |
3746 | 3755 | | |
3747 | 3756 | | |
3748 | 3757 | | |
| 3758 | + | |
3749 | 3759 | | |
3750 | | - | |
| 3760 | + | |
3751 | 3761 | | |
3752 | 3762 | | |
3753 | 3763 | | |
| 3764 | + | |
3754 | 3765 | | |
3755 | | - | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
3756 | 3785 | | |
3757 | 3786 | | |
3758 | 3787 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2426 | 2426 | | |
2427 | 2427 | | |
2428 | 2428 | | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
2429 | 2436 | | |
2430 | 2437 | | |
2431 | | - | |
2432 | | - | |
2433 | | - | |
2434 | | - | |
2435 | | - | |
2436 | | - | |
2437 | | - | |
2438 | | - | |
| 2438 | + | |
2439 | 2439 | | |
2440 | | - | |
| 2440 | + | |
| 2441 | + | |
2441 | 2442 | | |
2442 | | - | |
2443 | | - | |
2444 | | - | |
| 2443 | + | |
2445 | 2444 | | |
2446 | 2445 | | |
2447 | 2446 | | |
| |||
0 commit comments