[PATCH] D104349: [compiler-rt][atomics][RFC] Enable __atomic_exchange handling case when `val == old`

David Chisnall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 30 05:56:57 PDT 2021


theraven added a comment.

I don't believe a compiler can ever generate code that hits this code path.  The public function is:

  c
  C atomic_exchange_explicit( volatile A* obj, C desired, memory_order order );

The compiler lowers this by allocating space for the return value (`*old`) and passing `desired` by reference.  The right thing to do is probably document that the two parameters must not alias (I'd be happy with sticking `restrict` on all three pointer arguments, actually, and documenting that).

I really don't like the xor magic in the alternative path because it breaks any pointer provenance.  If the target is any kind of CHERI CPU, it will generate invalid machine code.    If we are in an LTO build and end up inlining this function then we're destroying any alias info that we might otherwise have.  If we actually need that path, I'd much rather that we copied everything via a temporary and used `intptr_t` for any chunks that are sized and aligned like an `intptr_t`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104349/new/

https://reviews.llvm.org/D104349



More information about the llvm-commits mailing list