Be conservative about allocations that may alias the accessed pointer.
authorBob Wilson <bob.wilson@apple.com>
Tue, 4 Sep 2012 03:30:13 +0000 (03:30 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 4 Sep 2012 03:30:13 +0000 (03:30 +0000)
If an allocation has a must-alias relation to the access pointer, we treat it
as a Def.  Otherwise, without this check, the code here was just skipping over
the allocation call and ignoring it.  I noticed this by inspection and don't
have a specific testcase that it breaks, but it seems like we need to treat
a may-alias allocation as a Clobber.

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

lib/Analysis/MemoryDependenceAnalysis.cpp

index 804217a83d10c42d58541c0fbb1ea4468eebf616..5736c3569dc11ce98c6aaae0bfd6f4297da3fc6f 100644 (file)
@@ -485,6 +485,9 @@ getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad,
       
       if (AccessPtr == Inst || AA->isMustAlias(Inst, AccessPtr))
         return MemDepResult::getDef(Inst);
+      // Be conservative if the accessed pointer may alias the allocation.
+      if (AA->alias(Inst, AccessPtr) != AliasAnalysis::NoAlias)
+        return MemDepResult::getClobber(Inst);
       // If the allocation is not aliased and does not read memory (like
       // strdup), it is safe to ignore.
       if (isa<AllocaInst>(Inst) ||