You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JIT: (bug) Volatile loads whose value is discarded are deleted, allowing CSE across an acquire read #134194
A volatile load whose result is thrown away (e.g. s_flag * 0) is removed entirely, so ordinary loads can be CSEd across it — an observable memory-model violation.
Minimal Repro
usingSystem;usingSystem.Runtime.CompilerServices;usingSystem.Threading;publicclassProgram{staticvolatileints_flag;staticints_data;[MethodImpl(MethodImplOptions.NoInlining)]publicstaticboolSawUpdate(){inta=s_data;intacquire=s_flag*0;// volatile read - must not be removedintb=s_data;returna!=b||acquire!=0;}publicstaticvoidMain(){newThread(()=>{while(true){s_data++;}}){IsBackground=true}.Start();for(inti=0;i<100000000;i++){if(SawUpdate()){Console.WriteLine("reloaded");return;}}Console.WriteLine("volatile read deleted; s_data CSEd across the acquire");}}
Expected
reloaded
Actual
volatile read deleted; s_data CSEd across the acquire
SawUpdate compiles to xor eax, eax / ret — no memory access at all remains. Removing the * 0 makes the same method reload s_data correctly.
Notes
Also repros on released .NET 10.0.12.
Two distinct paths delete the load, both because the "has side effects" predicates ignore GTF_IND_VOLATILE / GTF_ORDER_SIDEEFF: for this source Roslyn folds x * 0 and emits volatile.ldsfld + pop, and the importer's CEE_POP handling discards it. Hiding the zero behind an AggressiveInlining helper makes the JIT do the folding instead, and then gtWrapWithSideEffects/gtExtractSideEffList (via gtNodeHasSideEffects) drops it the same way.
Activity
dotnet-policy-service commentedon Sep 18, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
MihuBot commentedon Sep 18, 2026
I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):
EgorBo commentedon Sep 18, 2026
Affected SDK versions: