[PATCH] D12338: Make `llvm::expandAtomicRMWToCmpXchg`'s initial load atomic.

Jeffrey Yasskin via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 2 09:38:05 PDT 2015


jyasskin added a comment.

In http://reviews.llvm.org/D12338#236924, @morisset wrote:

> After thinking some more about it, I realized that having the load stay non-atomic is actually unsound because there might be a race, which would make it undefined behaviour.
>  Sadly, making it monotonic would still introduce these redundant cmpxchg8b/16b since monotonic requires the access to be atomic.
>  I don't know well enough the semantics of unordered accesses to know if they would do the trick, and the llvm reference manual description of them is fairly lightweight on details.
>
> @reames: do you know if unordered has the right strength for allowing races without forcing the backend to use cmpxchg8b/16b instead of two mov ? If no, do you have a better suggestion ?


>From http://llvm.org/docs/Atomics.html#unordered, "note that an unordered load or store cannot be split into multiple instructions."

You can't use a normal access because that allows a later pass to change it to:

%1 = load %ptr
%2 = op %1
%oops = load %ptr
cmpxchg %ptr, %oops, %2

Bleh. With the current instructions, I don't think there's a good answer here.


http://reviews.llvm.org/D12338





More information about the llvm-commits mailing list