1; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 \
2; RUN: | FileCheck %s
3
4; Test that the dependence analysis generates the correct results when using
5; an aliased object that points to a different element in the same array.
6; PR33567 - https://bugs.llvm.org/show_bug.cgi?id=33567
7
8; void test1(int *A, int *B, int N) {
9;   int *top = A;
10;   int *bot = A + N/2;
11;   for (int i = 0; i < N; i++)
12;     B[i] = top[i] + bot[i];
13; }
14
15; CHECK-LABEL: test1
16; CHECK: da analyze - input [*|<]!
17
18define void @test1(i32* nocapture %A, i32* nocapture %B, i32 %N) #0 {
19entry:
20  %cmp9 = icmp sgt i32 %N, 0
21  br i1 %cmp9, label %for.body.lr.ph, label %for.end
22
23for.body.lr.ph:
24  %div = sdiv i32 %N, 2
25  %bot.gep = getelementptr i32, i32* %A, i32 %div
26  br label %for.body
27
28for.body:
29  %i = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
30  %gep.0 = getelementptr i32, i32* %A, i32 %i
31  %gep.1 = getelementptr i32, i32* %bot.gep, i32 %i
32  %gep.B = getelementptr i32, i32* %B, i32 %i
33  %0 = load i32, i32* %gep.0, align 4
34  %1 = load i32, i32* %gep.1, align 4
35  %add = add nsw i32 %1, %0
36  store i32 %add, i32* %gep.B, align 4
37  %inc = add nsw i32 %i, 1
38  %exitcond = icmp eq i32 %inc, %N
39  br i1 %exitcond, label %for.end, label %for.body
40
41for.end:
42  ret void
43}
44
45
46; void test2(int *A, unsigned n) {
47;   int *B = A + 1;
48;   for (unsigned i = 0; i < n; ++i) {
49;     A[i] = B[i];
50;   }
51; }
52
53; CHECK-LABEL: test2
54; CHECK: da analyze - consistent anti [1]!
55
56define void @test2(i32*, i32) #3 {
57  %3 = getelementptr inbounds i32, i32* %0, i64 1
58  br label %4
59
60; <label>:4:
61  %.0 = phi i32 [ 0, %2 ], [ %14, %13 ]
62  %5 = sub i32 %1, 1
63  %6 = icmp ult i32 %.0, %5
64  br i1 %6, label %7, label %15
65
66; <label>:7:
67  %8 = zext i32 %.0 to i64
68  %9 = getelementptr inbounds i32, i32* %3, i64 %8
69  %10 = load i32, i32* %9, align 4
70  %11 = zext i32 %.0 to i64
71  %12 = getelementptr inbounds i32, i32* %0, i64 %11
72  store i32 %10, i32* %12, align 4
73  br label %13
74
75; <label>:13:
76  %14 = add i32 %.0, 1
77  br label %4
78
79; <label>:15:
80  ret void
81}
82