-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redundant load-acquire elimination discrepancy between CoreCLR and Clang #47261
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Also /cc @stephentoub, who understands the |
Note that the C code makes no use of |
This looks like #6280. |
CC @AndyAyersMS |
Yes, they are related. Per ECMA-355, I.12.6.7 Volatile reads and writes:
and subsequently
and the jit is not honoring this last "shall not," either here or in #6280 or in #10268. In this case the latter two of the three reads are removed because we can clear their side effect flags during assertion prop, so only the first read remains:
The fix should be fairly simple, morph must check for volatile, but currently this involves a tree walk. Perhaps we should model volatile as a general side effect so it tends to get checked along with all the other side effects, and propagates up to the roots of trees. |
I don't see us fixing this for 6.0. Willing to reconsider if we have evidence this is causing a problem somewhere. |
I think this is ByDesign. Clang may be used with device memory with unknown sideeffects of volatile reads, so it can't drop them. In .NET reads just read ordinary memory. Since noone looks at the results, the reads can be dropped. |
There are multiple existing versions of the runtime, in and out of support, that exhibit this assumption/behavior, trying to fix it will only introduce inconsistencies. Since targeting device memory is not a supported scenario, there is a very little value in changing this (as opposed to documenting). |
C code:
C# code:
clang-11 -O3 atomic.c
results in this code forfoo
:(Note: I'm specifically using Clang because it optimizes atomics much more aggressively than GCC. In any case, GCC emits the same code.)
The C# code for
Foo
results in this:Given that both snippets are using acquire semantics, who's right? Is CoreCLR wrong to eliminate the redundant loads, or is Clang being overly conservative?
The text was updated successfully, but these errors were encountered: