Wrong value for sext i1 true in BasicAliasAnalysis

Nicholas White n.j.white at gmail.com
Mon Dec 15 16:10:35 PST 2014


I've made some progress at defining the problem, at least. The "real fix"
should pass the two tests below - and my WIP patch is something like:

diff --git a/lib/Analysis/BasicAliasAnalysis.cpp
b/lib/Analysis/BasicAliasAnalysis.cpp
index 9aba0d3..ef018c0 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -263,9 +267,12 @@ static Value *GetLinearExpression(Value *V, APInt
&Scale, APInt &Offset,
                                         DL, Depth+1, AT, DT);
     Scale = Scale.zext(OldWidth);

-    // We have to sign-extend even if Extension == EK_ZeroExt as we can't
-    // decompose a sign extension (i.e. zext(x - 1) != zext(x) - zext(-1)).
-    Offset = Offset.sext(OldWidth);
+    // We have to be careful if Extension == EK_ZeroExt as we can't
+    // decompose a sign extension, e.g. zext(x - 1) != zext(x) - zext(-1).
+    // This isn't true in all cases though, as zext(-1) != sext(-1).
+    Offset = isa<SExtInst>(V)
+      ? Offset.sext(OldWidth)
+      : Offset.zext(OldWidth);

     return Result;
   }

I'll keep working on this. Thanks -

Nick

; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info
-disable-output 2>&1 | FileCheck %s
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "thumbv7--linux-gnueabi"

%struct.spec_fd_t = type { i32, i32, i32, i32, i32 }
@spec_fd = common global [280 x %struct.spec_fd_t] zeroinitializer, align 4

; CHECK-LABEL: test_path_dependent
; CHECK: MustAlias: i8* %a, i8* %b
define void @test_path_dependent(i32 %p, i8* %mem) {
  %p.64 = zext i32 %p to i64
  %a = getelementptr inbounds i8* %mem, i64 %p.64
  %p.minus1 = add nsw nuw i32 %p, -1
  %p.minus1.64 = zext i32 %p.minus1 to i64
  %p.64.again = add nsw nuw i64 %p.minus1.64, 1
  %b = getelementptr inbounds i8* %mem, i64 %p.64.again
  ret void
}

; CHECK-LABEL: uncompressStream
; CHECK: MustAlias:  i32* %offset.2.a, i32* %offset.2.b
; CHECK: PartialAlias:  [280 x %struct.spec_fd_t]* @spec_fd, i32*
%offset.2.b
; CHECK: NoAlias: [280 x %struct.spec_fd_t]* @spec_fd, i32* %offset.2.c
; CHECK: NoAlias:  i32* %offset.2.b, i32* %offset.2.c
define void @uncompressStream() {
  %offset.2.a = getelementptr inbounds [280 x %struct.spec_fd_t]* @spec_fd,
i32 0, i32 255, i32 2
  %literal.255 = zext i8 255 to i32
  %offset.2.b = getelementptr inbounds [280 x %struct.spec_fd_t]* @spec_fd,
i32 0, i32 %literal.255, i32 2
  %literal.minus1 = sext i8 255 to i32
  %offset.2.c = getelementptr inbounds [280 x %struct.spec_fd_t]* @spec_fd,
i32 0, i32 %literal.minus1, i32 2
  ret void
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141216/ba9f9086/attachment.html>


More information about the llvm-commits mailing list