[PATCH] D19935: [BasicAA] Compare GEP indices based on value

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 13:20:55 PDT 2016


vsk created this revision.
vsk added a reviewer: ab.
vsk added subscribers: llvm-commits, spatel, hfinkel.

Equivalent GEP indices with different types are treated as different
indices altogether, leading to a loss in AA precision. Fix the issue
(PR27418) by comparing indices based on their values.

http://reviews.llvm.org/D19935

Files:
  lib/Analysis/BasicAliasAnalysis.cpp
  test/Analysis/BasicAA/gep-alias.ll

Index: test/Analysis/BasicAA/gep-alias.ll
===================================================================
--- test/Analysis/BasicAA/gep-alias.ll
+++ test/Analysis/BasicAA/gep-alias.ll
@@ -275,4 +275,21 @@
   ret void
 }
 
+; PR27418 - Treat GEP indices with the same value but different types the same
+; CHECK-LABEL: @f(
+define i1 @f() {
+ %arr = alloca [2 x i16]
+ %tmp1 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i32 1
+ store i16 0, i16* %tmp1
+ %tmp2 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i16 1
+ %tmp3 = load i16, i16* %tmp2
+ %tmp4 = icmp ne i16 %tmp3, 0
+ br i1 %tmp4, label %bb1, label %bb2
+; CHECK-NOT: br i1 undef, label %bb1, label %bb2
+bb1:
+ ret i1 false
+bb2:
+ ret i1 true
+}
+
 declare i32 @printf(i8*, ...)
Index: lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- lib/Analysis/BasicAliasAnalysis.cpp
+++ lib/Analysis/BasicAliasAnalysis.cpp
@@ -819,7 +819,7 @@
 
   // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19935.56196.patch
Type: text/x-patch
Size: 1300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160504/fb3b42f5/attachment.bin>


More information about the llvm-commits mailing list