Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

oliver-giersch
Copy link
Contributor

@oliver-giersch oliver-giersch commented Jul 21, 2020

This will probably require further discussion, but according to my research the current rule of disallowing (Release, Acquire) as memory ordering for the atomic compare_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 than Release (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).

@rust-highfive
Copy link
Collaborator

r? @cramertj

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2020
@oliver-giersch oliver-giersch changed the title Permit (Release, Acquire) ordering for compare_exchange[_weak] and add appropriate compiler intrinsic Permit (Release, Acquire) ordering for compare_exchange[_weak] and add appropriate compiler intrinsic Jul 21, 2020
@tmiasko
Copy link
Contributor

tmiasko commented Jul 21, 2020

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).

@oliver-giersch
Copy link
Contributor Author

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.

@bors
Copy link
Contributor

bors commented Jul 28, 2020

☔ The latest upstream changes (presumably #73265) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC-zz
Copy link

@oliver-giersch we do not support merge commits in the rust repository. Would recommend rolling it back and doing a rebase instead.

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2020
@oliver-giersch
Copy link
Contributor Author

Would it be a sensible compromise to leave the intrinsics in place but disallow using the (Release, Acquire) order for CAS operations, until there is progress on the LLVM codegen bugs are resolved?

@bors
Copy link
Contributor

bors commented Aug 22, 2020

☔ The latest upstream changes (presumably #75797) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC-zz
Copy link

@oliver-giersch any updates on this? (also if you can, do resolve the conflicts)

@oliver-giersch
Copy link
Contributor Author

@Dylan-DPC I would prefer if I could get some feedback on the matter in principle before resolving further conflicts, specifically:

  1. Should this ordering combination be permitted at all? In my opinion the memory model allows it, but I know from previous discussion that this issue is somewhat controversial
  2. Given that LLVM currently does not compile this ordering combination correctly on some platforms, should perhaps for now only the intrinsics be added but not publicly exposed?

@cramertj
Copy link
Member

Given that LLVM currently does not compile this ordering combination correctly on some platforms, should perhaps for now only the intrinsics be added but not publicly exposed?

What would be the goal of adding the intrinsics if they aren't to be used?

@oliver-giersch
Copy link
Contributor Author

@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.

@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. A-intrinsics Area: intrinsics labels Oct 8, 2020
@crlf0710
Copy link
Member

crlf0710 commented Oct 8, 2020

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.

@crlf0710 crlf0710 added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Oct 8, 2020
@camelid camelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2020
@JohnCSimon
Copy link
Member

Ping from triage:
@oliver-giersch - Thanks for your contribution, but unfortunately I'll have to close this due to inactivity, please feel free to reopen when you are ready to proceed.

@JohnCSimon JohnCSimon added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Nov 9, 2020
@JohnCSimon JohnCSimon closed this Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intrinsics Area: intrinsics S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants