1; RUN: opt -aa-pipeline=basic-aa -passes='require<scalar-evolution>,require<aa>,loop(print-access-info)' -disable-output  < %s 2>&1 | FileCheck %s
2
3target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4
5; We shouldn't quit the analysis if we encounter a pointer without known
6; bounds *unless* we actually need to emit a memcheck for it.  (We only
7; compute bounds for SCEVAddRecs so A[i*i] is deemed not having known bounds.)
8;
9; for (i = 0; i < 20; ++i)
10;   A[i*i] *= 2;
11
12; CHECK-LABEL: addrec_squared
13; CHECK-NEXT: for.body:
14; CHECK-NEXT:   Report: unsafe dependent memory operations in loop
15; CHECK-NOT:    Report: cannot identify array bounds
16; CHECK-NEXT:     Dependences:
17; CHECK-NEXT:       Unknown:
18; CHECK-NEXT:         %loadA = load i16, i16* %arrayidxA, align 2 ->
19; CHECK-NEXT:         store i16 %mul, i16* %arrayidxA, align 2
20
21define void @addrec_squared(i16* %a) {
22entry:
23  br label %for.body
24
25for.body:                                         ; preds = %for.body, %entry
26  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
27
28  %access_ind = mul i64 %ind, %ind
29
30  %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %access_ind
31  %loadA = load i16, i16* %arrayidxA, align 2
32
33  %mul = mul i16 %loadA, 2
34
35  store i16 %mul, i16* %arrayidxA, align 2
36
37  %add = add nuw nsw i64 %ind, 1
38  %exitcond = icmp eq i64 %add, 20
39  br i1 %exitcond, label %for.end, label %for.body
40
41for.end:                                          ; preds = %for.body
42  ret void
43}
44
45; TODO: We cannot compute the bound for %arrayidxA_ub, because the index is
46; loaded on each iteration. As %a and %b are no-alias, no memchecks are required
47; and unknown bounds should not prevent further analysis.
48define void @loaded_bound(i16* noalias %a, i16* noalias %b) {
49; CHECK-LABEL: loaded_bound
50; CHECK-NEXT:  for.body:
51; CHECK-NEXT:    Report: cannot identify array bounds
52; CHECK-NEXT:    Dependences:
53; CHECK-NEXT:    Run-time memory checks:
54
55entry:
56  br label %for.body
57
58for.body:                                         ; preds = %for.body, %entry
59  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
60
61  %iv.next = add nuw nsw i64 %iv, 1
62
63  %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %iv
64  %loadB = load i16, i16* %arrayidxB, align 2
65
66  %arrayidxA_ub = getelementptr inbounds i16, i16* %a, i16 %loadB
67  %loadA_ub = load i16, i16* %arrayidxA_ub, align 2
68
69  %mul = mul i16 %loadB, %loadA_ub
70
71  %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %iv
72  store i16 %mul, i16* %arrayidxA, align 2
73
74  %exitcond = icmp eq i64 %iv, 20
75  br i1 %exitcond, label %for.end, label %for.body
76
77for.end:                                          ; preds = %for.body
78  ret void
79}
80