[PowerPC] Implement XL compatible behavior of __compare_and_swap
authorKai Luo <lkail@cn.ibm.com>
Fri, 23 Jul 2021 00:57:53 +0000 (00:57 +0000)
committerKai Luo <lkail@cn.ibm.com>
Fri, 23 Jul 2021 01:16:02 +0000 (01:16 +0000)
commite4ed93cb25acc624a1d32e77d2c63c8c25fddbae
tree1c52aacb40f86192d55bba2ac7c6d9704336afc4
parentf8c40ed8f8e760cfc672dbd1b8d8b4d9357e4a16
[PowerPC] Implement XL compatible behavior of __compare_and_swap

According to https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=functions-compare-swap-compare-swaplp
XL's `__compare_and_swap` has a weird behavior that

> In either case, the contents of the memory location specified by addr are copied into the memory location specified by old_val_addr.

(unlike c11 `atomic_compare_exchange` specified in http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf)

This patch let clang's implementation follow this behavior.

Reviewed By: jsji

Differential Revision: https://reviews.llvm.org/D106344
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-ppc-xlcompat-cas.c
llvm/test/CodeGen/PowerPC/opt-builtins-ppc-xlcompat-cas.ll [new file with mode: 0644]