blob: 8018994009957c7e2778c121c4a8ea814dcddf05 [file] [log] [blame]
Adam Nemet26da8e92015-04-14 01:12:55 +00001; RUN: opt -basicaa -loop-accesses -analyze < %s | FileCheck %s
Sean Silva284b0322016-07-07 01:01:53 +00002; RUN: opt -passes='require<aa>,require<scalar-evolution>,require<aa>,loop(print-access-info)' -aa-pipeline='basic-aa' -disable-output < %s 2>&1 | FileCheck %s
Adam Nemet26da8e92015-04-14 01:12:55 +00003
4; If the arrays don't alias this loop is safe with no memchecks:
5; for (i = 0; i < n; i++)
6; A[i] = A[i+1] * B[i] * C[i];
7
8target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
9target triple = "x86_64-apple-macosx10.10.0"
10
Adam Nemetb45516e2015-11-03 20:13:23 +000011; Check the loop-carried forward anti-dep between the load of A[i+1] and the
12; store of A[i];
13
Adam Nemet26da8e92015-04-14 01:12:55 +000014; CHECK: Memory dependences are safe{{$}}
Adam Nemeta2df7502015-11-03 21:39:52 +000015; CHECK-NEXT: Dependences:
Adam Nemetb45516e2015-11-03 20:13:23 +000016; CHECK-NEXT: Forward:
17; CHECK-NEXT: %loadA_plus_2 = load i16, i16* %arrayidxA_plus_2, align 2 ->
18; CHECK-NEXT: store i16 %mul1, i16* %arrayidxA, align 2
19
Adam Nemet26da8e92015-04-14 01:12:55 +000020
21define void @f(i16* noalias %a,
22 i16* noalias %b,
23 i16* noalias %c) {
24entry:
25 br label %for.body
26
27for.body: ; preds = %for.body, %entry
28 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
29
30 %add = add nuw nsw i64 %ind, 1
31
32 %arrayidxA_plus_2 = getelementptr inbounds i16, i16* %a, i64 %add
33 %loadA_plus_2 = load i16, i16* %arrayidxA_plus_2, align 2
34
35 %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %ind
36 %loadB = load i16, i16* %arrayidxB, align 2
37
38 %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %ind
39 %loadC = load i16, i16* %arrayidxC, align 2
40
41 %mul = mul i16 %loadB, %loadA_plus_2
42 %mul1 = mul i16 %mul, %loadC
43
44 %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %ind
45 store i16 %mul1, i16* %arrayidxA, align 2
46
47 %exitcond = icmp eq i64 %add, 20
48 br i1 %exitcond, label %for.end, label %for.body
49
50for.end: ; preds = %for.body
51 ret void
52}