xref: /llvm-project/llvm/test/Analysis/DependenceAnalysis/MismatchingNestLevels.ll (revision 46f9cddfd7e40998422d1e34a3f1193210ee2fb8)
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
2; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 | FileCheck %s
3
4;; void test1(long n, double *A) {
5;;     long  i;
6;;     for (i = 0; i*n <= n*n; ++i) {
7;;         A[i] = i;
8;;     }
9;;     A[i] = i;
10;; }
11
12define void @test1(i64 noundef %n, ptr nocapture noundef writeonly %A) {
13; CHECK-LABEL: 'test1'
14; CHECK-NEXT:  Src: store double %conv, ptr %arrayidx, align 8 --> Dst: store double %conv, ptr %arrayidx, align 8
15; CHECK-NEXT:    da analyze - none!
16; CHECK-NEXT:  Src: store double %conv, ptr %arrayidx, align 8 --> Dst: store double %conv2, ptr %arrayidx3, align 8
17; CHECK-NEXT:    da analyze - output [|<]!
18; CHECK-NEXT:  Src: store double %conv2, ptr %arrayidx3, align 8 --> Dst: store double %conv2, ptr %arrayidx3, align 8
19; CHECK-NEXT:    da analyze - none!
20;
21entry:
22  %mul1 = mul nsw i64 %n, %n
23  br label %for.body
24
25for.body:                                         ; preds = %entry, %for.body
26  %i.012 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
27  %conv = sitofp i64 %i.012 to double
28  %arrayidx = getelementptr inbounds double, ptr %A, i64 %i.012
29  store double %conv, ptr %arrayidx, align 8
30  %inc = add nuw nsw i64 %i.012, 1
31  %mul = mul nsw i64 %inc, %n
32  %cmp.not = icmp sgt i64 %mul, %mul1
33  br i1 %cmp.not, label %for.end, label %for.body
34
35for.end:                                          ; preds = %for.body
36  %conv2 = sitofp i64 %inc to double
37  %arrayidx3 = getelementptr inbounds double, ptr %A, i64 %inc
38  store double %conv2, ptr %arrayidx3, align 8
39  ret void
40}
41
42
43;; int test2(unsigned n, float A[][n+1], float B[n+1]) {
44;;  for (int i = 0; i <= n; i++) {
45;;    long j = 0;
46;;    for (; j <= n; ++j) {
47;;      B[j] = j;
48;;    }
49;;    A[i][j] = 123;
50;;    for (int k = 0; k <= n; k++) {
51;;      A[i][k] = k;
52;;    }
53;;  }
54;;
55;; Make sure we can detect depnendence between A[i][j] and A[i][k] conservatively and without crashing.
56
57define dso_local void @test2(i32 noundef zeroext %n, ptr noundef %A, ptr noalias noundef %B) #0 {
58; CHECK-LABEL: 'test2'
59; CHECK-NEXT:  Src: store i32 %conv5, ptr %arrayidx, align 4 --> Dst: store i32 %conv5, ptr %arrayidx, align 4
60; CHECK-NEXT:    da analyze - consistent output [S 0]!
61; CHECK-NEXT:  Src: store i32 %conv5, ptr %arrayidx, align 4 --> Dst: store float 1.230000e+02, ptr %arrayidx7, align 4
62; CHECK-NEXT:    da analyze - none!
63; CHECK-NEXT:  Src: store i32 %conv5, ptr %arrayidx, align 4 --> Dst: store float %conv13, ptr %arrayidx17, align 4
64; CHECK-NEXT:    da analyze - none!
65; CHECK-NEXT:  Src: store float 1.230000e+02, ptr %arrayidx7, align 4 --> Dst: store float 1.230000e+02, ptr %arrayidx7, align 4
66; CHECK-NEXT:    da analyze - output [*]!
67; CHECK-NEXT:  Src: store float 1.230000e+02, ptr %arrayidx7, align 4 --> Dst: store float %conv13, ptr %arrayidx17, align 4
68; CHECK-NEXT:    da analyze - output [*|<]!
69; CHECK-NEXT:  Src: store float %conv13, ptr %arrayidx17, align 4 --> Dst: store float %conv13, ptr %arrayidx17, align 4
70; CHECK-NEXT:    da analyze - none!
71;
72entry:
73  %add = add i32 %n, 1
74  %0 = zext i32 %add to i64
75  %1 = zext i32 %n to i64
76  %2 = add nuw nsw i64 %1, 1
77  %wide.trip.count9 = zext i32 %add to i64
78  br label %for.i
79
80for.i:                                         ; preds = %entry, %for.inc21
81  %indvars.iv6 = phi i64 [ 0, %entry ], [ %indvars.iv.next7, %for.inc21 ]
82  br label %for.j
83
84for.j:                                        ; preds = %for.i, %for.j
85  %j.01 = phi i64 [ 0, %for.i ], [ %inc, %for.j ]
86  %conv5 = trunc i64 %j.01 to i32
87  %arrayidx = getelementptr inbounds i32, ptr %B, i64 %j.01
88  store i32 %conv5, ptr %arrayidx, align 4
89  %inc = add nuw nsw i64 %j.01, 1
90  %exitcond = icmp ne i64 %inc, %2
91  br i1 %exitcond, label %for.j, label %for.end
92
93for.end:                                          ; preds = %for.j
94  %inc.lcssa = phi i64 [ %inc, %for.j ]
95  %3 = mul nuw nsw i64 %indvars.iv6, %0
96  %arrayidx6 = getelementptr inbounds float, ptr %A, i64 %3
97  %arrayidx7 = getelementptr inbounds float, ptr %arrayidx6, i64 %inc.lcssa
98  store float 1.230000e+02, ptr %arrayidx7, align 4
99  %wide.trip.count = zext i32 %add to i64
100  br label %for.k
101
102for.k:                                       ; preds = %for.end, %for.k
103  %indvars.iv = phi i64 [ 0, %for.end ], [ %indvars.iv.next, %for.k ]
104  %4 = trunc i64 %indvars.iv to i32
105  %conv13 = sitofp i32 %4 to float
106  %5 = mul nuw nsw i64 %indvars.iv6, %0
107  %arrayidx15 = getelementptr inbounds float, ptr %A, i64 %5
108  %arrayidx17 = getelementptr inbounds float, ptr %arrayidx15, i64 %indvars.iv
109  store float %conv13, ptr %arrayidx17, align 4
110  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
111  %exitcond5 = icmp ne i64 %indvars.iv.next, %wide.trip.count
112  br i1 %exitcond5, label %for.k, label %for.inc21
113
114for.inc21:                                        ; preds = %for.k
115  %indvars.iv.next7 = add nuw nsw i64 %indvars.iv6, 1
116  %exitcond10 = icmp ne i64 %indvars.iv.next7, %wide.trip.count9
117  br i1 %exitcond10, label %for.i, label %for.end23
118
119for.end23:                                        ; preds = %for.inc21
120  ret void
121}
122
123
124;; void test3(int n, double *restrict A, double *restrict B) {
125;;   for (int i = 0; i < n; ++i) {
126;;     int s = 0;
127;;     for (; s * s < n * n; ++s) {
128;;     }
129;;     for (int k = 0; k < n; ++k)
130;;       A[s] = 0; // Invariant in innermost loop
131;;
132;;     A[i] = 1;
133;;   }
134;; }
135;;
136;; Make sure we can detect depnendence between A[i] and A[s] conservatively and without crashing.
137
138define void @test3(i32 noundef %n, ptr noalias noundef %A, ptr noalias noundef %B) {
139; CHECK-LABEL: 'test3'
140; CHECK-NEXT:  Src: store double 0.000000e+00, ptr %arrayidx, align 8 --> Dst: store double 0.000000e+00, ptr %arrayidx, align 8
141; CHECK-NEXT:    da analyze - output [* S]!
142; CHECK-NEXT:  Src: store double 0.000000e+00, ptr %arrayidx, align 8 --> Dst: store double 1.000000e+00, ptr %arrayidx21, align 8
143; CHECK-NEXT:    da analyze - output [*|<]!
144; CHECK-NEXT:  Src: store double 1.000000e+00, ptr %arrayidx21, align 8 --> Dst: store double 1.000000e+00, ptr %arrayidx21, align 8
145; CHECK-NEXT:    da analyze - none!
146;
147entry:
148  br label %for.i
149
150for.i:                                         ; preds = %for.end19, %entry
151  %i.0 = phi i32 [ 0, %entry ], [ %inc23, %for.end19 ]
152  %cmp = icmp slt i32 %i.0, %n
153  br i1 %cmp, label %for.s, label %for.end24
154
155for.s:                                        ; preds = %for.i, %for.inc
156  %s.0 = phi i32 [ %inc, %for.inc ], [ 0, %for.i ]
157  %mul = mul nsw i32 %s.0, %s.0
158  %mul2 = mul nsw i32 %n, %n
159  %cmp3 = icmp slt i32 %mul, %mul2
160  br i1 %cmp3, label %for.inc, label %for.k
161
162for.inc:                                          ; preds = %for.s
163  %inc = add nsw i32 %s.0, 1
164  br label %for.s
165
166for.k:                                        ; preds = %for.s, %for.body.k
167  %k.0 = phi i32 [ %inc10, %for.body.k ], [ 0, %for.s ]
168  %cmp6 = icmp slt i32 %k.0, %n
169  br i1 %cmp6, label %for.body.k, label %for.end19
170
171for.body.k:                                        ; preds = %for.k
172  %idxprom = sext i32 %s.0 to i64
173  %arrayidx = getelementptr inbounds double, ptr %A, i64 %idxprom
174  store double 0.000000e+00, ptr %arrayidx, align 8
175  %inc10 = add nsw i32 %k.0, 1
176  br label %for.k
177
178for.end19:                                        ; preds = %for.k
179  %idxprom20 = sext i32 %i.0 to i64
180  %arrayidx21 = getelementptr inbounds double, ptr %A, i64 %idxprom20
181  store double 1.000000e+00, ptr %arrayidx21, align 8
182  %inc23 = add nsw i32 %i.0, 1
183  br label %for.i
184
185for.end24:                                        ; preds = %for.i
186  ret void
187}
188