Back out 60748 for now. It's breaking SPASS, 254.gap, and 464.h264ref.
[oota-llvm.git] / lib / Analysis / BasicAliasAnalysis.cpp
index 22b73b28400c6f2f9e4f456d68575e3f512c7709..bc30c09217c27eb44dd8386c294b7f023b86183b 100644 (file)
@@ -104,14 +104,24 @@ static const Value *GetGEPOperands(const Value *V,
   return V;
 }
 
+/// isNoAliasCall - Return true if this pointer is returned by a noalias
+/// function.
+static bool isNoAliasCall(const Value *V) {
+  if (isa<CallInst>(V) || isa<InvokeInst>(V))
+    return CallSite(const_cast<Instruction*>(cast<Instruction>(V)))
+      .paramHasAttr(0, Attribute::NoAlias);
+  return false;
+}
+
 /// isIdentifiedObject - Return true if this pointer refers to a distinct and
 /// identifiable object.  This returns true for:
 ///    Global Variables and Functions
 ///    Allocas and Mallocs
 ///    ByVal and NoAlias Arguments
+///    NoAlias returns
 ///
 static bool isIdentifiedObject(const Value *V) {
-  if (isa<GlobalValue>(V) || isa<AllocationInst>(V))
+  if (isa<GlobalValue>(V) || isa<AllocationInst>(V) || isNoAliasCall(V))
     return true;
   if (const Argument *A = dyn_cast<Argument>(V))
     return A->hasNoAliasAttr() || A->hasByValAttr();
@@ -138,7 +148,7 @@ static bool isKnownNonNull(const Value *V) {
 /// object that never escapes from the function.
 static bool isNonEscapingLocalObject(const Value *V) {
   // If this is a local allocation, check to see if it escapes.
-  if (isa<AllocationInst>(V))
+  if (isa<AllocationInst>(V) || isNoAliasCall(V))
     return !AddressMightEscape(V);
       
   // If this is an argument that corresponds to a byval or noalias argument,
@@ -154,19 +164,24 @@ static bool isNonEscapingLocalObject(const Value *V) {
 /// by V is smaller than Size.
 static bool isObjectSmallerThan(const Value *V, unsigned Size,
                                 const TargetData &TD) {
-  const Type *AccessTy = 0;
-  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+  const Type *AccessTy;
+  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
     AccessTy = GV->getType()->getElementType();
-  
-  if (const AllocationInst *AI = dyn_cast<AllocationInst>(V))
+  } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(V)) {
     if (!AI->isArrayAllocation())
       AccessTy = AI->getType()->getElementType();
-
-  if (const Argument *A = dyn_cast<Argument>(V))
+    else
+      return false;
+  } else if (const Argument *A = dyn_cast<Argument>(V)) {
     if (A->hasByValAttr())
       AccessTy = cast<PointerType>(A->getType())->getElementType();
+    else
+      return false;
+  } else {
+    return false;
+  }
   
-  if (AccessTy && AccessTy->isSized())
+  if (AccessTy->isSized())
     return TD.getABITypeSize(AccessTy) < Size;
   return false;
 }
@@ -355,8 +370,7 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
   // Are we checking for alias of the same value?
   if (V1 == V2) return MustAlias;
 
-  if ((!isa<PointerType>(V1->getType()) || !isa<PointerType>(V2->getType())) &&
-      V1->getType() != Type::Int64Ty && V2->getType() != Type::Int64Ty)
+  if (!isa<PointerType>(V1->getType()) || !isa<PointerType>(V2->getType()))
     return NoAlias;  // Scalars cannot alias each other
 
   // Strip off cast instructions...
@@ -374,11 +388,11 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
     if (isIdentifiedObject(O1) && isIdentifiedObject(O2))
       return NoAlias;
   
-    // Incoming argument cannot alias locally allocated object!
-    if ((isa<Argument>(O1) && isa<AllocationInst>(O2)) ||
-        (isa<Argument>(O2) && isa<AllocationInst>(O1)))
+    // Arguments can't alias with local allocations or noalias calls.
+    if ((isa<Argument>(O1) && (isa<AllocationInst>(O2) || isNoAliasCall(O2))) ||
+        (isa<Argument>(O2) && (isa<AllocationInst>(O1) || isNoAliasCall(O1))))
       return NoAlias;
-    
+
     // Most objects can't alias null.
     if ((isa<ConstantPointerNull>(V2) && isKnownNonNull(O1)) ||
         (isa<ConstantPointerNull>(V1) && isKnownNonNull(O2)))
@@ -516,7 +530,7 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
   return MayAlias;
 }
 
-// This function is used to determin if the indices of two GEP instructions are
+// This function is used to determine if the indices of two GEP instructions are
 // equal. V1 and V2 are the indices.
 static bool IndexOperandsEqual(Value *V1, Value *V2) {
   if (V1->getType() == V2->getType())