1 ; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 | FileCheck %s
3 ;; void test1(long n, double *A) {
5 ;; for (i = 0; i*n <= n*n; ++i) {
11 ; CHECK-LABEL: 'Dependence Analysis' for function 'test1':
12 ; CHECK: Src: store double %conv, ptr %arrayidx, align 8 --> Dst: store double %conv, ptr %arrayidx, align 8
13 ; CHECK-NEXT: da analyze - none!
14 ; CHECK: Src: store double %conv, ptr %arrayidx, align 8 --> Dst: store double %conv2, ptr %arrayidx3, align 8
15 ; CHECK-NEXT: da analyze - output [|<]!
16 ; CHECK: Src: store double %conv2, ptr %arrayidx3, align 8 --> Dst: store double %conv2, ptr %arrayidx3, align 8
17 ; CHECK-NEXT: da analyze - none!
19 define void @test1(i64 noundef %n, ptr nocapture noundef writeonly %A) {
21 %mul1 = mul nsw i64 %n, %n
24 for.body: ; preds = %entry, %for.body
25 %i.012 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
26 %conv = sitofp i64 %i.012 to double
27 %arrayidx = getelementptr inbounds double, ptr %A, i64 %i.012
28 store double %conv, ptr %arrayidx, align 8
29 %inc = add nuw nsw i64 %i.012, 1
30 %mul = mul nsw i64 %inc, %n
31 %cmp.not = icmp sgt i64 %mul, %mul1
32 br i1 %cmp.not, label %for.end, label %for.body
34 for.end: ; preds = %for.body
35 %conv2 = sitofp i64 %inc to double
36 %arrayidx3 = getelementptr inbounds double, ptr %A, i64 %inc
37 store double %conv2, ptr %arrayidx3, align 8
42 ;; int test2(unsigned n, float A[][n+1], float B[n+1]) {
43 ;; for (int i = 0; i <= n; i++) {
45 ;; for (; j <= n; ++j) {
49 ;; for (int k = 0; k <= n; k++) {
54 ;; Make sure we can detect depnendence between A[i][j] and A[i][k] conservatively and without crashing.
56 ; CHECK-LABEL: 'Dependence Analysis' for function 'test2':
57 ; CHECK: Src: store float 1.230000e+02, ptr %arrayidx7, align 4 --> Dst: store float %conv13, ptr %arrayidx17, align 4
58 ; CHECK-NEXT: da analyze - output [*|<]!
60 define dso_local void @test2(i32 noundef zeroext %n, ptr noundef %A, ptr noalias noundef %B) #0 {
63 %0 = zext i32 %add to i64
64 %1 = zext i32 %n to i64
65 %2 = add nuw nsw i64 %1, 1
66 %wide.trip.count9 = zext i32 %add to i64
69 for.i: ; preds = %entry, %for.inc21
70 %indvars.iv6 = phi i64 [ 0, %entry ], [ %indvars.iv.next7, %for.inc21 ]
73 for.j: ; preds = %for.i, %for.j
74 %j.01 = phi i64 [ 0, %for.i ], [ %inc, %for.j ]
75 %conv5 = trunc i64 %j.01 to i32
76 %arrayidx = getelementptr inbounds i32, ptr %B, i64 %j.01
77 store i32 %conv5, ptr %arrayidx, align 4
78 %inc = add nuw nsw i64 %j.01, 1
79 %exitcond = icmp ne i64 %inc, %2
80 br i1 %exitcond, label %for.j, label %for.end
82 for.end: ; preds = %for.j
83 %inc.lcssa = phi i64 [ %inc, %for.j ]
84 %3 = mul nuw nsw i64 %indvars.iv6, %0
85 %arrayidx6 = getelementptr inbounds float, ptr %A, i64 %3
86 %arrayidx7 = getelementptr inbounds float, ptr %arrayidx6, i64 %inc.lcssa
87 store float 1.230000e+02, ptr %arrayidx7, align 4
88 %wide.trip.count = zext i32 %add to i64
91 for.k: ; preds = %for.end, %for.k
92 %indvars.iv = phi i64 [ 0, %for.end ], [ %indvars.iv.next, %for.k ]
93 %4 = trunc i64 %indvars.iv to i32
94 %conv13 = sitofp i32 %4 to float
95 %5 = mul nuw nsw i64 %indvars.iv6, %0
96 %arrayidx15 = getelementptr inbounds float, ptr %A, i64 %5
97 %arrayidx17 = getelementptr inbounds float, ptr %arrayidx15, i64 %indvars.iv
98 store float %conv13, ptr %arrayidx17, align 4
99 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
100 %exitcond5 = icmp ne i64 %indvars.iv.next, %wide.trip.count
101 br i1 %exitcond5, label %for.k, label %for.inc21
103 for.inc21: ; preds = %for.k
104 %indvars.iv.next7 = add nuw nsw i64 %indvars.iv6, 1
105 %exitcond10 = icmp ne i64 %indvars.iv.next7, %wide.trip.count9
106 br i1 %exitcond10, label %for.i, label %for.end23
108 for.end23: ; preds = %for.inc21
113 ;; void test3(int n, double *restrict A, double *restrict B) {
114 ;; for (int i = 0; i < n; ++i) {
116 ;; for (; s * s < n * n; ++s) {
118 ;; for (int k = 0; k < n; ++k)
119 ;; A[s] = 0; // Invariant in innermost loop
125 ;; Make sure we can detect depnendence between A[i] and A[s] conservatively and without crashing.
127 ; CHECK-LABEL: 'Dependence Analysis' for function 'test3':
128 ; CHECK: Src: store double 0.000000e+00, ptr %arrayidx, align 8 --> Dst: store double 1.000000e+00, ptr %arrayidx21, align 8
129 ; CHECK-NEXT: da analyze - output [*|<]!
131 define void @test3(i32 noundef %n, ptr noalias noundef %A, ptr noalias noundef %B) {
135 for.i: ; preds = %for.end19, %entry
136 %i.0 = phi i32 [ 0, %entry ], [ %inc23, %for.end19 ]
137 %cmp = icmp slt i32 %i.0, %n
138 br i1 %cmp, label %for.s, label %for.end24
140 for.s: ; preds = %for.i, %for.inc
141 %s.0 = phi i32 [ %inc, %for.inc ], [ 0, %for.i ]
142 %mul = mul nsw i32 %s.0, %s.0
143 %mul2 = mul nsw i32 %n, %n
144 %cmp3 = icmp slt i32 %mul, %mul2
145 br i1 %cmp3, label %for.inc, label %for.k
147 for.inc: ; preds = %for.s
148 %inc = add nsw i32 %s.0, 1
151 for.k: ; preds = %for.s, %for.body.k
152 %k.0 = phi i32 [ %inc10, %for.body.k ], [ 0, %for.s ]
153 %cmp6 = icmp slt i32 %k.0, %n
154 br i1 %cmp6, label %for.body.k, label %for.end19
156 for.body.k: ; preds = %for.k
157 %idxprom = sext i32 %s.0 to i64
158 %arrayidx = getelementptr inbounds double, ptr %A, i64 %idxprom
159 store double 0.000000e+00, ptr %arrayidx, align 8
160 %inc10 = add nsw i32 %k.0, 1
163 for.end19: ; preds = %for.k
164 %idxprom20 = sext i32 %i.0 to i64
165 %arrayidx21 = getelementptr inbounds double, ptr %A, i64 %idxprom20
166 store double 1.000000e+00, ptr %arrayidx21, align 8
167 %inc23 = add nsw i32 %i.0, 1
170 for.end24: ; preds = %for.i