Teach BasicAA a little something about the atomic intrinsics: they can only
authorNick Lewycky <nicholas@mxc.ca>
Tue, 13 Oct 2009 07:48:38 +0000 (07:48 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Tue, 13 Oct 2009 07:48:38 +0000 (07:48 +0000)
modify through the pointer they're given.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83959 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BasicAliasAnalysis.cpp
test/Analysis/BasicAA/2009-10-13-AtomicModRef.ll [new file with mode: 0644]

index 5fa87ff365599a67c711b08777971230cde29b07..2e3c75de506c7d11ea28398dd712bb990f809d93 100644 (file)
@@ -284,6 +284,27 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
       if (!passedAsArg)
         return NoModRef;
     }
+
+    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) {
+      switch (II->getIntrinsicID()) {
+      default: break;
+      case Intrinsic::atomic_cmp_swap:
+      case Intrinsic::atomic_swap:
+      case Intrinsic::atomic_load_add:
+      case Intrinsic::atomic_load_sub:
+      case Intrinsic::atomic_load_and:
+      case Intrinsic::atomic_load_nand:
+      case Intrinsic::atomic_load_or:
+      case Intrinsic::atomic_load_xor:
+      case Intrinsic::atomic_load_max:
+      case Intrinsic::atomic_load_min:
+      case Intrinsic::atomic_load_umax:
+      case Intrinsic::atomic_load_umin:
+        if (alias(II->getOperand(1), Size, P, Size) == NoAlias)
+          return NoModRef;
+        break;
+      }
+    }
   }
 
   // The AliasAnalysis base class has some smarts, lets use them.
diff --git a/test/Analysis/BasicAA/2009-10-13-AtomicModRef.ll b/test/Analysis/BasicAA/2009-10-13-AtomicModRef.ll
new file mode 100644 (file)
index 0000000..3ccbc2f
--- /dev/null
@@ -0,0 +1,16 @@
+; RUN: opt -gvn -S < %s | FileCheck %s
+
+declare i8 @llvm.atomic.load.add.i8.p0i8(i8*, i8)
+
+define void @foo(i8* %ptr) {
+  %P = getelementptr i8* %ptr, i32 0
+  %Q = getelementptr i8* %ptr, i32 1
+; CHECK: getelementptr
+  %X = load i8* %P
+; CHECK: = load
+  %Y = call i8 @llvm.atomic.load.add.i8.p0i8(i8* %Q, i8 1)
+  %Z = load i8* %P
+; CHECK-NOT: = load
+  ret void
+; CHECK: ret void
+}