1; RUN: opt -basic-aa -loop-versioning -S < %s | FileCheck %s
2
3; A very simple case.  After versioning the %loadA and %loadB can't alias with
4; the store.
5;
6; To see it easier what's going on, I expanded every noalias/scope metadata
7; reference below in a comment.  For a scope I use the format scope(domain),
8; e.g. scope 17 in domain 15 is written as 17(15).
9
10; CHECK-LABEL: @f(
11
12target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
13
14define void @f(i32* %a, i32* %b, i32* %c) {
15entry:
16  br label %for.body
17
18; CHECK: for.body.lver.orig:
19; CHECK: for.body:
20for.body:                                         ; preds = %for.body, %entry
21  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
22
23  %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
24; CHECK: %loadA = {{.*}} !alias.scope !0
25; A's scope: !0 -> { 1(2) }
26  %loadA = load i32, i32* %arrayidxA, align 4
27
28  %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
29; CHECK: %loadB = {{.*}} !alias.scope !3
30; B's scope: !3 -> { 4(2) }
31  %loadB = load i32, i32* %arrayidxB, align 4
32
33  %mulC = mul i32 %loadA, %loadB
34
35  %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
36; CHECK: store {{.*}} !alias.scope !5, !noalias !7
37; C noalias A and B: !7 -> { 1(2), 4(2) }
38  store i32 %mulC, i32* %arrayidxC, align 4
39
40  %add = add nuw nsw i64 %ind, 1
41  %exitcond = icmp eq i64 %add, 20
42  br i1 %exitcond, label %for.end, label %for.body
43
44for.end:                                          ; preds = %for.body
45  ret void
46}
47; CHECK: !0 = !{!1}
48; CHECK: !1 = distinct !{!1, !2}
49; CHECK: !2 = distinct !{!2, !"LVerDomain"}
50; CHECK: !3 = !{!4}
51; CHECK: !4 = distinct !{!4, !2}
52; CHECK: !5 = !{!6}
53; CHECK: !6 = distinct !{!6, !2}
54; CHECK: !7 = !{!1, !4}
55