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