Repository navigation
JIT: Keep volatile loads when folding full-range relational comparisons - #135724
Conversation
fgOptimizeRelationalComparisonWithFullRangeConst replaces "volatileByte >= 0" with a constant if the tree has no GTF_SIDE_EFFECT. A non-faulting volatile load only has GTF_ORDER_SIDEEFF, so it was discarded together with its acquire semantics, allowing a later load to be hoisted out of a spin loop. Check GTF_OBS_EFFECT instead. Fixes dotnet#134477 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.
🟡 Changes recommended
The regression test must be gated on multithreading support.
1 open finding
What changed in this PR
Fixes JIT folding so volatile-load ordering semantics are preserved.
Changes:
- Checks
GTF_OBS_EFFECTbefore folding full-range comparisons. - Adds a threaded regression test.
| File | Description |
|---|---|
src/coreclr/jit/morph.cpp |
Preserves ordering side effects during comparison folding. |
src/tests/JIT/Regression_ro_2/Runtime_134477.cs |
Tests volatile-load acquire semantics. |
🧠 Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot <[email protected]> Copilot-Session: 9894cfda-4521-43f5-b406-aeb318def64e
|
PTAL @dotnet/jit-contrib, trivial bug-fix |
|
/ba-g infra |
|
@EgorBo this test is failing on native AOT, the disassembly of the Test method is: Full jitdump: Clanker says: The JitDump identifies a different path from the already-fixed morphing bug. During import of With that read missing, loop hoisting moves the non-volatile |
…6149) Fixes the NativeAOT regression reported in [this comment](#135724 (comment)) on #135724. NativeAOT can infer that a never-written static field is readonly. Folding a volatile read of that field to a constant drops its acquire semantics, allowing subsequent loads to be hoisted out of a spin loop. Skip this folding for volatile accesses. Co-authored-by: Copilot <[email protected]> Copilot-Session: 4330ad35-fbb0-419e-b0b1-bfdb463e3ece

fgOptimizeRelationalComparisonWithFullRangeConst replaces "volatileByte >= 0" with a constant if the tree has no GTF_SIDE_EFFECT. A non-faulting volatile load only has GTF_ORDER_SIDEEFF, so it was discarded together with its acquire semantics, allowing a later load to be hoisted out of a spin loop. Check GTF_OBS_EFFECT instead.
Fixes #134477