[llvm] r261245 - [CaptureTracking] Support atomicrmw and cmpxchg

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 18 11:23:27 PST 2016


Author: reames
Date: Thu Feb 18 13:23:27 2016
New Revision: 261245

URL: http://llvm.org/viewvc/llvm-project?rev=261245&view=rev
Log:
[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


Modified:
    llvm/trunk/lib/Analysis/CaptureTracking.cpp
    llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll

Modified: llvm/trunk/lib/Analysis/CaptureTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CaptureTracking.cpp?rev=261245&r1=261244&r2=261245&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CaptureTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/CaptureTracking.cpp Thu Feb 18 13:23:27 2016
@@ -271,6 +271,17 @@ void llvm::PointerMayBeCaptured(const Va
           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:

Modified: llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll?rev=261245&r1=261244&r2=261245&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll Thu Feb 18 13:23:27 2016
@@ -193,3 +193,14 @@ define void @test6_2(i8* %x6_2, i8* %y6_
   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
+}




More information about the llvm-commits mailing list