-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Permit (Release, Acquire) ordering for compare_exchange[_weak] and add appropriate compiler intrinsic #74583
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
compare_exchange[_weak]
and add appropriate compiler intrinsic
Thanks for working on this. The produced assembly doesn't respect acquire ordering on the failure (https://bugs.llvm.org/show_bug.cgi?id=33332, #68464). |
Thanks for bringing up these issues, I wasn't aware at all and it hadn't come in the course of my research. I am also not proficient enough in reading ARM assembly to have spotted the miscompilation myself. |
☔ The latest upstream changes (presumably #73265) made this pull request unmergeable. Please resolve the merge conflicts. |
@oliver-giersch we do not support merge commits in the rust repository. Would recommend rolling it back and doing a rebase instead. |
…re) ordering for CAS
Would it be a sensible compromise to leave the intrinsics in place but disallow using the |
☔ The latest upstream changes (presumably #75797) made this pull request unmergeable. Please resolve the merge conflicts. |
@oliver-giersch any updates on this? (also if you can, do resolve the conflicts) |
@Dylan-DPC I would prefer if I could get some feedback on the matter in principle before resolving further conflicts, specifically:
|
What would be the goal of adding the intrinsics if they aren't to be used? |
@cramertj my idea was to enable their use at a later point if and when LLVM fixes its codegen, which I assume has to happen at some point, given that C++20 relaxes some ordering restrictions. |
Triage: There's still merge conflict. But it seems the author is also seeking for some discussions. @oliver-giersch Could you open a thread on Zulip or file a T-lang MCP for such a change? This pr should block on such an MCP before it could proceed. |
Ping from triage: |
This will probably require further discussion, but according to my research the current rule of disallowing (
Release
,Acquire
) as memory ordering for the atomiccompare_exchange[_weak]
primitives is unnecessarily strict and not actually required by the memory model.Here is a link to a previous discussion on that topic and here a link to a question and answer I've posted to the llvm-dev mailing list (my follow-up was unfortunately not answered). According to that answer, LLVM currently does not consider
Acquire
to be a stronger ordering thanRelease
(source code) and apparently there are plans to drop the "relative strength" requirement altogether, since it is basically not really well-defined.Here is an example using
clang
on ARM that shows different assembly is generated when (Release
,Acquire
) is used instead of the next best approximation (AcqRel
,Acquire
).