[llvm] r251112 - [BasicAA] Bugfix for r251016

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 23 07:17:04 PDT 2015


Author: jamesm
Date: Fri Oct 23 09:17:03 2015
New Revision: 251112

URL: http://llvm.org/viewvc/llvm-project?rev=251112&view=rev
Log:
[BasicAA] Bugfix for r251016

If the loaded type sizes don't match the element type of the sequential type, all bets are off and the addresses may, indeed, overlap.

Surprisingly, this just got caught in one test, on one builder, out of the 30+ builders testing this change. Congratulations go to http://lab.llvm.org:8011/builders/clang-aarch64-lnt/builds/5205.

Modified:
    llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
    llvm/trunk/test/Analysis/BasicAA/sequential-gep.ll

Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=251112&r1=251111&r2=251112&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Fri Oct 23 09:17:03 2015
@@ -815,11 +815,17 @@ static AliasResult aliasSameBasePointerG
     // Because array indices greater than the number of elements are valid in
     // GEPs, unless we know the intermediate indices are identical between
     // GEP1 and GEP2 we cannot guarantee that the last indexed arrays don't
-    // partially overlap.
+    // partially overlap. We also need to check that the loaded size matches
+    // the element size, otherwise we could still have overlap.
+    const uint64_t ElementSize =
+        DL.getTypeStoreSize(cast<SequentialType>(Ty)->getElementType());
+    if (V1Size != ElementSize || V2Size != ElementSize)
+      return MayAlias;
+
     for (unsigned i = 0, e = GEP1->getNumIndices() - 1; i != e; ++i)
       if (GEP1->getOperand(i + 1) != GEP2->getOperand(i + 1))
         return MayAlias;
-    
+
     // Now we know that the array/pointer that GEP1 indexes into and that
     // that GEP2 indexes into must either precisely overlap or be disjoint.
     // Because they cannot partially overlap and because fields in an array

Modified: llvm/trunk/test/Analysis/BasicAA/sequential-gep.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/sequential-gep.ll?rev=251112&r1=251111&r2=251112&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/sequential-gep.ll (original)
+++ llvm/trunk/test/Analysis/BasicAA/sequential-gep.ll Fri Oct 23 09:17:03 2015
@@ -40,4 +40,15 @@ define void @t4([8 x i32]* %p, i32 %adde
   ret void
 }
 
+; CHECK: Function: t5
+; CHECK: PartialAlias: i32* %gep2, i64* %bc
+define void @t5([8 x i32]* %p, i32 %addend, i32* %q) {
+  %knownnonzero = load i32, i32* %q, !range !0
+  %add = add nsw nuw i32 %addend, %knownnonzero
+  %gep1 = getelementptr [8 x i32], [8 x i32]* %p, i32 2, i32 %addend
+  %gep2 = getelementptr [8 x i32], [8 x i32]* %p, i32 2, i32 %add
+  %bc = bitcast i32* %gep1 to i64*
+  ret void
+}
+
 !0 = !{ i32 1, i32 5 }




More information about the llvm-commits mailing list