Teach basicaa about memcpy/memmove/memset. The length argument can be used to
authorNick Lewycky <nicholas@mxc.ca>
Thu, 15 Oct 2009 07:11:24 +0000 (07:11 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 15 Oct 2009 07:11:24 +0000 (07:11 +0000)
improve alias results if constant, and the source pointer can't be modified.

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

lib/Analysis/BasicAliasAnalysis.cpp

index a0306663e8a68144975333456a9e9c369d6c991d..c5be6167e060e46eeb9dc9eaeb54fb7cfa1069e9 100644 (file)
@@ -310,6 +310,28 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
     if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) {
       switch (II->getIntrinsicID()) {
       default: break;
+      case Intrinsic::memcpy:
+      case Intrinsic::memmove: {
+        unsigned Len = ~0U;
+        if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getOperand(3)))
+          Len = LenCI->getZExtValue();
+        Value *Dest = II->getOperand(1);
+        Value *Src = II->getOperand(2);
+        if (alias(Dest, Len, P, Size) == NoAlias) {
+          if (alias(Src, Len, P, Size) == NoAlias)
+            return NoModRef;
+          return Ref;
+        }
+        }
+        break;
+      case Intrinsic::memset:
+        if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getOperand(3))) {
+          unsigned Len = LenCI->getZExtValue();
+          Value *Dest = II->getOperand(1);
+          if (alias(Dest, Len, P, Size) == NoAlias)
+            return NoModRef;
+        }
+        break;
       case Intrinsic::atomic_cmp_swap:
       case Intrinsic::atomic_swap:
       case Intrinsic::atomic_load_add: