Fix bugs that Chris noticed in my last patch.
authorOwen Anderson <resistor@mac.com>
Mon, 18 Feb 2008 02:31:23 +0000 (02:31 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 18 Feb 2008 02:31:23 +0000 (02:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47252 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BasicAliasAnalysis.cpp

index 4c7259f7f4c594b980880dd959c3c48306f7d96e..b19ce2b8c484d2766344e0ab82eef08ddb31466d 100644 (file)
@@ -250,22 +250,30 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
     const Value *Object = getUnderlyingObject(P);
     // Allocations and byval arguments are "new" objects.
     if (Object &&
-        (isa<AllocationInst>(Object) ||
-         (isa<Argument>(Object) &&
-                                 (cast<Argument>(Object)->hasByValAttr() ||
-                                  cast<Argument>(Object)->hasNoAliasAttr())))) {
+        (isa<AllocationInst>(Object) || isa<Argument>(Object))) {
       // Okay, the pointer is to a stack allocated (or effectively so, for 
       // for noalias parameters) object.  If we can prove that
       // the pointer never "escapes", then we know the call cannot clobber it,
       // because it simply can't get its address.
-      if (!AddressMightEscape(Object))
-        return NoModRef;
+      if (isa<AllocationInst>(Object) ||
+          cast<Argument>(Object)->hasByValAttr() ||
+          cast<Argument>(Object)->hasNoAliasAttr())
+        if (!AddressMightEscape(Object)) {
+          for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
+              CI != CE; ++CI)
+            if (getUnderlyingObject(CI->get()) == P)
+              return AliasAnalysis::getModRefInfo(CS, P, Size);
+        
+          return NoModRef;
+        }
 
       // If this is a tail call and P points to a stack location, we know that
       // the tail call cannot access or modify the local stack.
-      if (CallInst *CI = dyn_cast<CallInst>(CS.getInstruction()))
-        if (CI->isTailCall() && !isa<MallocInst>(Object))
-          return NoModRef;
+      if (isa<AllocationInst>(Object) ||
+          cast<Argument>(Object)->hasByValAttr())
+        if (CallInst *CI = dyn_cast<CallInst>(CS.getInstruction()))
+          if (CI->isTailCall() && !isa<MallocInst>(Object))
+            return NoModRef;
     }
   }