1 ; RUN: opt -basicaa -loop-distribute -enable-loop-distribute -loop-simplify -scoped-noalias \
2 ; RUN: -loop-versioning -S < %s | FileCheck %s
4 ; Test the metadata generated when versioning an already versioned loop. Here
5 ; we invoke loop distribution to perform the first round of versioning. It
6 ; adds memchecks for accesses that can alias across the distribution boundary.
7 ; Then we further version the distributed loops to fully disambiguate accesses
10 ; So as an example, we add noalias between C and A during the versioning
11 ; within loop distribution and then add noalias between C and D during the
12 ; second explicit versioning step:
14 ; for (i = 0; i < n; i++) {
15 ; A[i + 1] = A[i] * B[i];
16 ; -------------------------------
20 ; To see it easier what's going on, I expanded every noalias/scope metadata
21 ; reference below in a comment. For a scope I use the format scope(domain),
22 ; e.g. scope 17 in domain 15 is written as 17(15).
24 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
26 @B = common global i32* null, align 8
27 @A = common global i32* null, align 8
28 @C = common global i32* null, align 8
29 @D = common global i32* null, align 8
30 @E = common global i32* null, align 8
34 %a = load i32*, i32** @A, align 8
35 %b = load i32*, i32** @B, align 8
36 %c = load i32*, i32** @C, align 8
37 %d = load i32*, i32** @D, align 8
38 %e = load i32*, i32** @E, align 8
41 for.body: ; preds = %for.body, %entry
42 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
44 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
46 ; CHECK: %loadA.ldist1 = {{.*}} !noalias !25
47 ; A noalias C: !25 -> { 17(15), 18(15), 19(15), 26(24) }
49 %loadA = load i32, i32* %arrayidxA, align 4
51 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
52 %loadB = load i32, i32* %arrayidxB, align 4
54 %mulA = mul i32 %loadB, %loadA
56 %add = add nuw nsw i64 %ind, 1
57 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
58 store i32 %mulA, i32* %arrayidxA_plus_4, align 4
62 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
64 ; CHECK: %loadD = {{.*}} !alias.scope !31
65 ; D's scope: !31 -> { 18(15), 32(33) }
67 %loadD = load i32, i32* %arrayidxD, align 4
69 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
71 ; CHECK: %loadE = {{.*}} !alias.scope !34
72 ; E's scope: !34 -> { 19(15), 35(33) }
74 %loadE = load i32, i32* %arrayidxE, align 4
76 %mulC = mul i32 %loadD, %loadE
78 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
80 ; CHECK: store i32 %mulC, {{.*}} !alias.scope !36, !noalias !38
81 ; C's scope: !36 -> { 17(15), 37(33) }
83 ; C noalias D and E: !38 -> { 21(15), 32(33), 35(33) }
85 store i32 %mulC, i32* %arrayidxC, align 4
87 %exitcond = icmp eq i64 %add, 20
88 br i1 %exitcond, label %for.end, label %for.body
90 for.end: ; preds = %for.body
94 ; Domain for the second loop versioning for the top loop after
96 ; CHECK: !15 = distinct !{!15, !"LVerDomain"}
97 ; CHECK: !17 = distinct !{!17, !15}
98 ; CHECK: !25 = !{!17, !18, !19, !26}
99 ; CHECK: !31 = !{!18, !32}
100 ; CHECK: !32 = distinct !{!32, !33}
101 ; Domain for the second loop versioning for the bottom loop after
103 ; CHECK: !33 = distinct !{!33, !"LVerDomain"}
104 ; CHECK: !34 = !{!19, !35}
105 ; CHECK: !35 = distinct !{!35, !33}
106 ; CHECK: !36 = !{!17, !37}
107 ; CHECK: !38 = !{!21, !32, !35}