OSDN Git Service

[ARM] Fix for 64-bit CAS expansion on ARM32 with -O0
authorOleg Ranevskyy <oranevskyy@accesssoftek.com>
Thu, 1 Dec 2016 22:58:35 +0000 (22:58 +0000)
committerOleg Ranevskyy <oranevskyy@accesssoftek.com>
Thu, 1 Dec 2016 22:58:35 +0000 (22:58 +0000)
commitc31c930cdf7d34987fb1d08e92a4532343241dd3
tree20bf3254a97a0f3c059a62f92f5c31d11ddce633
parentbc5dae72538517fbc7568fbfeda82d552dd1af6b
[ARM] Fix for 64-bit CAS expansion on ARM32 with -O0

Summary:
This patch fixes comparison of 64-bit atomic with its expected value in CMP_SWAP_64 expansion.

Currently, the low words are compared with CMP, while the high words are compared with SBC. SBC expects the carry flag to be set if CMP detects a difference. CMP might leave the carry unset for unequal arguments though if the first one is >= than the second. This might cause the comparison logic to detect false equality.

Example of the broken C++ code:
```
std::atomic<long long> at(2);

long long ll = 1;
std::atomic_compare_exchange_strong(&at, &ll, 3);
```
Even though the atomic `at` and the expected value `ll` are not equal and `atomic_compare_exchange_strong` returns `false`, `at` is changed to 3.

The patch replaces SBC with CMPEQ.

Reviewers: t.p.northover

Subscribers: aemerson, rengolin, llvm-commits, asl

Differential Revision: https://reviews.llvm.org/D27315

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288433 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/ARM/ARMExpandPseudoInsts.cpp
test/CodeGen/ARM/cmpxchg-O0.ll