60 changes: 60 additions & 0 deletions llvm/test/Analysis/BasicAA/128-bit-ptr.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
; This testcase consists of alias relations on 128-bit pointers that
; should be completely resolvable by basicaa.

; RUN: opt < %s -basicaa -aa-eval -print-no-aliases -print-may-aliases -print-must-aliases -disable-output 2>&1 | FileCheck %s

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128-p100:128:64:64-p101:128:64:64"


; test0 is similar to SimpleCases.ll

%T = type { i32, [10 x i8] }

; CHECK: Function: test0
; CHECK-NOT: MayAlias:
define void @test0(%T addrspace(100)* %P) {
%A = getelementptr %T, %T addrspace(100)* %P, i64 0
%B = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 0
%C = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 1
%D = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 1, i64 0
%E = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 1, i64 5
ret void
}

; test1 checks that >64 bits of index can be considered.
; If BasicAA is truncating the arithmetic, it will conclude
; that %A and %B must alias when in fact they must not.

; CHECK: Function: test1
; CHECK-NOT: MustAlias:
; CHECK: NoAlias:
; CHECK-SAME: %A
; CHECK-SAME: %B
define void @test1(double addrspace(100)* %P, i128 %i) {
; 1180591620717411303424 is 2**70
; 590295810358705651712 is 2**69
%i70 = add i128 %i, 1180591620717411303424
%i69 = add i128 %i, 590295810358705651712
%A = getelementptr double, double addrspace(100)* %P, i128 %i70
%B = getelementptr double, double addrspace(100)* %P, i128 %i69
ret void
}

; test2 checks that >64 bits of index can be considered
; and computes the same address in two ways to ensure that
; they are considered equivalent.

; CHECK: Function: test2
; CHECK: MustAlias:
; CHECK-SAME: %A
; CHECK-SAME: %C
define void @test2(double addrspace(100)* %P, i128 %i) {
; 1180591620717411303424 is 2**70
; 590295810358705651712 is 2**69
%i70 = add i128 %i, 1180591620717411303424
%i69 = add i128 %i, 590295810358705651712
%j70 = add i128 %i69, 590295810358705651712
%A = getelementptr double, double addrspace(100)* %P, i128 %i70
%C = getelementptr double, double addrspace(100)* %P, i128 %j70
ret void
}
43 changes: 43 additions & 0 deletions llvm/test/Analysis/BasicAA/gep-and-alias-64.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; RUN: opt -S -basicaa -gvn < %s | FileCheck %s

target datalayout = "e-m:o-p:64:64-f64:32:64-f80:128-n8:16:32-S128"
target triple = "x86_64-apple-macosx10.6.0"

; The load and store address in the loop body could alias so the load
; can't be hoisted above the store and out of the loop.

declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i32, i1)

define i64 @foo(i64 %x, i64 %z, i64 %n) {
entry:
%pool = alloca [59 x i64], align 4
%tmp = bitcast [59 x i64]* %pool to i8*
call void @llvm.memset.p0i8.i64(i8* nonnull %tmp, i8 0, i64 236, i32 4, i1 false)
%cmp3 = icmp eq i64 %n, 0
br i1 %cmp3, label %for.end, label %for.body.lr.ph

for.body.lr.ph: ; preds = %entry
%add = add i64 %z, %x
%and = and i64 %add, 9223372036854775807
%sub = add nsw i64 %and, -9223372036844814062
%arrayidx = getelementptr inbounds [59 x i64], [59 x i64]* %pool, i64 0, i64 %sub
%arrayidx1 = getelementptr inbounds [59 x i64], [59 x i64]* %pool, i64 0, i64 42
br label %for.body

for.body: ; preds = %for.body.lr.ph, %for.body
%i.04 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
store i64 %i.04, i64* %arrayidx, align 4
%tmp1 = load i64, i64* %arrayidx1, align 4
%inc = add nuw i64 %i.04, 1
%exitcond = icmp ne i64 %inc, %n
br i1 %exitcond, label %for.body, label %for.end.loopexit

for.end.loopexit: ; preds = %for.body
%lcssa = phi i64 [ %tmp1, %for.body ]
br label %for.end

for.end: ; preds = %for.end.loopexit, %entry
%s = phi i64 [ 0, %entry ], [ %lcssa, %for.end.loopexit ]
; CHECK: ret i64 %s
ret i64 %s
}
1 change: 1 addition & 0 deletions llvm/test/Analysis/BasicAA/gep-and-alias.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
; RUN: opt -S -basicaa -gvn -basicaa-force-at-least-64b=0 < %s | FileCheck %s

target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
target triple = "i386-apple-macosx10.6.0"
Expand Down