Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
e9b551e to
1976602
Compare
|
@tannergooding this fix looks safe. Ran superpmi tests and JIT suite offline. CI shows some unrelated failures but overall this looks good. |
src/coreclr/jit/emitxarch.cpp
Outdated
| // as "test" instruction. | ||
| // They reset OF and CF to 0 and modifies SF, ZF and PF. | ||
| if (DoesResetOverflowAndCarryFlags(lastIns)) | ||
| if (DoesResetOverflowAndCarryFlags(lastIns) && DoesWriteSignFlag(lastIns)) |
There was a problem hiding this comment.
Is this "sufficient"? The comment seems to indicate we want to exactly match what test is looking for and this isn't checking that PF or ZF are written.
The general AreFlagsSetToZeroCmp is meant to determine if we can drop test x, x; and the flags may be incorrect for ZF/PF if we didn't check them as well.
There was a problem hiding this comment.
Edit: Some copy/paste error happened when I was checking these, have fixed the table now
-- Given our current instructions, we only have 7 instructions which reset both overflow and carry:
or - Resets_OF | Writes_SF | Writes_ZF | Undefined_AF | Writes_PF | Resets_CFand - Resets_OF | Writes_SF | Writes_ZF | Undefined_AF | Writes_PF | Resets_CFxor - Resets_OF | Writes_SF | Writes_ZF | Undefined_AF | Writes_PF | Resets_CFtest - Resets_OF | Writes_SF | Writes_ZF | Undefined_AF | Writes_PF | Resets_CFandn - Resets_OF | Writes_SF | Writes_ZF | Undefined_AF | Undefined_PF | Resets_CFbextr - Resets_OF | Undefined_SF | Writes_ZF | Undefined_AF | Undefined_PF | Resets_CFpopcnt - Resets_OF | Resets_SF | Writes_ZF | Resets_AF | Resets_PF | Resets_CF
So:
andnviolates thePFexpectation oftestbextrandpopcntviolates theSFandPFexpectation oftest
There was a problem hiding this comment.
Was a copy paste error, fixed the table of the 7 existing instructions.
Still think we need to fix to account for the other flags, except AF which shouldn't be used for test anyways since its undefined.
There was a problem hiding this comment.
True. Looks like we would see this issue with andn, popcnt as well. will refine the filter further to make sure we are only skipping test for and, or and, xor.
…setsCF and ResetsOF are true
… into kcm-105820-fix
|
Thanks for approving @tannergooding |
|
@tannergooding, should we take this fix for .NET 9? |
I would say yes as it represents a correctness issue. That is, we generate invalid code without the fix. This notably looks to also impact .NET 8, but we've not had any user reported issues so I would likely defer backporting to .NET 8 until a customer report comes in with a real world code example (as this pattern is likely rare and has several possible workarounds). |
|
Fixes #105820. |
|
@TIHan, please merge to .NET 10 and backport to .NET 9. |
|
/backport to release/9.0-rc1 |
|
Started backporting to release/9.0-rc1: https://github.com/dotnet/runtime/actions/runs/10459546355 |
This PR addresses #105820
Brief analysis of this issue -->
Debug Output -->
Release output -->
Debug Disasm -->
Release disasm -->
Probable cause --> The
test eax, eaxinstruction before thejlinstruction is not emitted in compare to zero for instructions which write CF and OF. But thebextrinstruction also falls in this category and hence ended up skipping thetestinstruction. This lead to wrong setting of flag duringjland hence the issue.