https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116415
Bug ID: 116415 Summary: [13 Regression][PPC64LE] atomics wrongly use vector instructions in DWCAS. Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: torsten.mandel at sap dot com Target Milestone: --- Using g++ 13.2.1 the subsequently following code produces this output: 2 1 instead of g++ 11.3.0: 1 2 on a Power 64 LE machine. CODE: #include <iostream> #include <atomic> using ::std::memory_order_seq_cst; using ::std::memory_order_acquire; struct DblCnt { union Value { struct { uint64_t a; uint64_t b; } t; __uint128_t raw_data; } value; inline void atomic_inc(const uint64_t delta1, const uint64_t &delta2) noexcept { Value cur; cur.raw_data = const_cast<__uint128_t&>(value.raw_data); for (;;) { Value next; next.t.a = cur.t.a+delta1; next.t.b = cur.t.b+delta2; if (__atomic_compare_exchange(&value.raw_data, &cur.raw_data, &next.raw_data, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE)) break; } } DblCnt() : value() {} }; int main() { uint64_t i(1),j(2); DblCnt c; c.atomic_inc(i,j); std::cout << c.value.t.a << " " << c.value.t.b << std::endl; } Compile with: g++ -O2 -Werror -Wall -o dwcas -latomic ./test.cpp