1; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
2
3; Analyze this loop:
4;   for (i = 0; i < n; i++)
5;    A[i + 1] = A[i] * B[i] * C[i];
6
7target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
8target triple = "x86_64-apple-macosx10.10.0"
9
10; CHECK: Report: unsafe dependent memory operations in loop
11; CHECK-NEXT: Dependences:
12; CHECK-NEXT:   Backward:
13; CHECK-NEXT:     %loadA = load i16, i16* %arrayidxA, align 2 ->
14; CHECK-NEXT:     store i16 %mul1, i16* %arrayidxA_plus_2, align 2
15; CHECK: Run-time memory checks:
16; CHECK-NEXT: 0:
17; CHECK-NEXT: Comparing group
18; CHECK-NEXT:   %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
19; CHECK-NEXT:   %arrayidxA_plus_2 = getelementptr inbounds i16, i16* %a, i64 %add
20; CHECK-NEXT: Against group
21; CHECK-NEXT:   %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %storemerge3
22; CHECK-NEXT: 1:
23; CHECK-NEXT: Comparing group
24; CHECK-NEXT:   %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
25; CHECK-NEXT:   %arrayidxA_plus_2 = getelementptr inbounds i16, i16* %a, i64 %add
26; CHECK-NEXT: Against group
27; CHECK-NEXT:   %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %storemerge3
28
29@B = common global i16* null, align 8
30@A = common global i16* null, align 8
31@C = common global i16* null, align 8
32
33define void @f() {
34entry:
35  %a = load i16*, i16** @A, align 8
36  %b = load i16*, i16** @B, align 8
37  %c = load i16*, i16** @C, align 8
38  br label %for.body
39
40for.body:                                         ; preds = %for.body, %entry
41  %storemerge3 = phi i64 [ 0, %entry ], [ %add, %for.body ]
42
43  %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
44  %loadA = load i16, i16* %arrayidxA, align 2
45
46  %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %storemerge3
47  %loadB = load i16, i16* %arrayidxB, align 2
48
49  %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %storemerge3
50  %loadC = load i16, i16* %arrayidxC, align 2
51
52  %mul = mul i16 %loadB, %loadA
53  %mul1 = mul i16 %mul, %loadC
54
55  %add = add nuw nsw i64 %storemerge3, 1
56  %arrayidxA_plus_2 = getelementptr inbounds i16, i16* %a, i64 %add
57  store i16 %mul1, i16* %arrayidxA_plus_2, align 2
58
59  %exitcond = icmp eq i64 %add, 20
60  br i1 %exitcond, label %for.end, label %for.body
61
62for.end:                                          ; preds = %for.body
63  ret void
64}
65