[llvm] r269197 - [BasicAA] Compare GEP indices based on value (Fix PR27418)

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 08:45:43 PDT 2016


Author: vedantk
Date: Wed May 11 10:45:43 2016
New Revision: 269197

URL: http://llvm.org/viewvc/llvm-project?rev=269197&view=rev
Log:
[BasicAA] Compare GEP indices based on value (Fix PR27418)

Equivalent GEP indices with different types are treated as different
indices altogether, leading to an incorrect AA result. Fix the issue
by comparing indices based on their values.

Thanks to Mikael Holmén for reporting the issue!

Differential Revision: http://reviews.llvm.org/D19935

Modified:
    llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
    llvm/trunk/test/Analysis/BasicAA/struct-geps.ll

Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=269197&r1=269196&r2=269197&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Wed May 11 10:45:43 2016
@@ -847,7 +847,7 @@ static AliasResult aliasSameBasePointerG
 
   // If the last (struct) indices are constants and are equal, the other indices
   // might be also be dynamically equal, so the GEPs can alias.
-  if (C1 && C2 && C1 == C2)
+  if (C1 && C2 && C1->getSExtValue() == C2->getSExtValue())
     return MayAlias;
 
   // Find the last-indexed type of the GEP, i.e., the type you'd get if

Modified: llvm/trunk/test/Analysis/BasicAA/struct-geps.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/struct-geps.ll?rev=269197&r1=269196&r2=269197&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/struct-geps.ll (original)
+++ llvm/trunk/test/Analysis/BasicAA/struct-geps.ll Wed May 11 10:45:43 2016
@@ -162,3 +162,12 @@ define void @test_struct_in_array(%struc
   %y = getelementptr %struct2, %struct2* %st, i32 0, i32 0, i32 1, i32 1
   ret void
 }
+
+; PR27418 - Treat GEP indices with the same value but different types the same
+; CHECK-LABEL: test_different_index_types
+; CHECK: MustAlias: i16* %tmp1, i16* %tmp2
+define void @test_different_index_types([2 x i16]* %arr) {
+  %tmp1 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i32 1
+  %tmp2 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i16 1
+  ret void
+}




More information about the llvm-commits mailing list