diff options
author | Philip Reames <listmail@philipreames.com> | 2016-02-18 19:23:27 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2016-02-18 19:23:27 +0000 |
commit | bd09e86f82ae520b804f50068ab129f3f0b72ab8 (patch) | |
tree | 98ee90733afba398793928839e7731b590b594ef | |
parent | 069a1073ddbd9fd605a98189edd682e3cc083fad (diff) | |
download | bcm5719-llvm-bd09e86f82ae520b804f50068ab129f3f0b72ab8.tar.gz bcm5719-llvm-bd09e86f82ae520b804f50068ab129f3f0b72ab8.zip |
[CaptureTracking] Support atomicrmw and cmpxchg
These atomic operations are conceptually both a load and store from the same location. As such, we can treat them as the most conservative of those two components which in practice, means we can treat them like stores. An cmpxchg or atomicrmw captures the values, but not the locations accessed.
Note: We can probably be more aggressive about the comparison value in an cmpxhg since to have it be in memory, it must already be captured, but I figured it was better to avoid that for the moment.
Note 2: It turns out that since we don't actually support cmpxchg of pointer type, writing a negative test is impossible.
Differential Revision: http://reviews.llvm.org/D17400
llvm-svn: 261245
-rw-r--r-- | llvm/lib/Analysis/CaptureTracking.cpp | 11 | ||||
-rw-r--r-- | llvm/test/Transforms/FunctionAttrs/nocapture.ll | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp index 1add2fa7756..5125a63b81b 100644 --- a/llvm/lib/Analysis/CaptureTracking.cpp +++ b/llvm/lib/Analysis/CaptureTracking.cpp @@ -271,6 +271,17 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker) { return; // Storing to the pointee does not cause the pointer to be captured. break; + case Instruction::AtomicRMW: + case Instruction::AtomicCmpXchg: + // atomicrmw and cmpxchg conceptually include both a load and store from + // the same location. As with a store, the location being accessed is + // not captured, but the value being stored is. (For cmpxchg, we + // probably don't need to capture the original comparison value, but for + // the moment, let's be conservative.) + if (V != I->getOperand(0)) + if (Tracker->captured(U)) + return; + break; case Instruction::BitCast: case Instruction::GetElementPtr: case Instruction::PHI: diff --git a/llvm/test/Transforms/FunctionAttrs/nocapture.ll b/llvm/test/Transforms/FunctionAttrs/nocapture.ll index 4057b2a86e3..3bbe8248341 100644 --- a/llvm/test/Transforms/FunctionAttrs/nocapture.ll +++ b/llvm/test/Transforms/FunctionAttrs/nocapture.ll @@ -193,3 +193,14 @@ define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) { ret void } +; CHECK: define void @test_cmpxchg(i32* nocapture %p) +define void @test_cmpxchg(i32* %p) { + cmpxchg i32* %p, i32 0, i32 1 acquire monotonic + ret void +} + +; CHECK: define void @test_atomicrmw(i32* nocapture %p) +define void @test_atomicrmw(i32* %p) { + atomicrmw add i32* %p, i32 1 seq_cst + ret void +} |