Repository navigation
JIT: Respect ordering side effects on the second operand when swapping - #135722
Conversation
gtCanSwapOrder only rejected GTF_ORDER_SIDEEFF on the first operand. A divide that assertion prop proved non-faulting keeps only GTF_ORDER_SIDEEFF, so it could be commuted above the checked add that establishes its proof and throw the wrong exception. Treat ordering effects on the second operand like other non-reorderable effects. Fixes dotnet#134191 Co-authored-by: Copilot <[email protected]> Copilot-Session: 88502efb-96e2-4483-b698-59f5003a2e2c
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix matches the ordering contract and includes a targeted regression test.
0 open findings
What changed in this PR
Fixes JIT operand reordering so ordering side effects on the second operand prevent unsafe swaps.
Changes:
- Includes
GTF_ORDER_SIDEEFFin swap safety checks. - Adds a regression test verifying
OverflowExceptionremains first.
| File | Description |
|---|---|
src/coreclr/jit/gentree.cpp |
Prevents unsafe operand reordering. |
src/tests/JIT/Regression_ro_2/Runtime_134191.cs |
Covers the exception-ordering regression. |
🧠 Review effort: Balanced
|
PTAL @dotnet/jit-contrib, trivial bug-fix |
| [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] | ||
| private static int Test(int p, int q, int y, int z, int w, int u, int v) | ||
| { | ||
| return (checked(p + q) / y) + ((((z * w) + (u * v)) & 0x7FFFFF) / y); |
There was a problem hiding this comment.
Why is assertion prop able to prove the / y non-faulting here?
There was a problem hiding this comment.
Is the logic basically that if we didn't fault on the first divide, then y != 0?
There was a problem hiding this comment.
@adamperlin I think it's just bad wording in the PR description, here it's y is not-faulting.
X / Y generates an assertion that Y is never 0, but that assertion shouldn't reach divide's op1
gtCanSwapOrder only rejected GTF_ORDER_SIDEEFF on the first operand. A divide that assertion prop proved non-faulting keeps only GTF_ORDER_SIDEEFF, so it could be commuted above the checked add that establishes its proof and throw the wrong exception. Treat ordering effects on the second operand like other non-reorderable effects.
Fixes #134191
A few diffs.