1 ; RUN: opt -passes=loop-distribute,loop-simplify,loop-versioning -enable-loop-distribute -S < %s | FileCheck %s
3 ; Test the metadata generated when versioning an already versioned loop. Here
4 ; we invoke loop distribution to perform the first round of versioning. It
5 ; adds memchecks for accesses that can alias across the distribution boundary.
6 ; Then we further version the distributed loops to fully disambiguate accesses
9 ; So as an example, we add noalias between C and A during the versioning
10 ; within loop distribution and then add noalias between C and D during the
11 ; second explicit versioning step:
13 ; for (i = 0; i < n; i++) {
14 ; A[i + 1] = A[i] * B[i];
15 ; -------------------------------
19 ; To see it easier what's going on, I expanded every noalias/scope metadata
20 ; reference below in a comment. For a scope I use the format scope(domain),
21 ; e.g. scope 17 in domain 15 is written as 17(15).
23 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
25 @B = common global ptr null, align 8
26 @A = common global ptr null, align 8
27 @C = common global ptr null, align 8
28 @D = common global ptr null, align 8
29 @E = common global ptr null, align 8
33 %a = load ptr, ptr @A, align 8
34 %b = load ptr, ptr @B, align 8
35 %c = load ptr, ptr @C, align 8
36 %d = load ptr, ptr @D, align 8
37 %e = load ptr, ptr @E, align 8
40 for.body: ; preds = %for.body, %entry
41 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
43 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
45 ; CHECK: %loadA.ldist1 = {{.*}} !noalias !25
46 ; A noalias C: !25 -> { 17(15), 18(15), 19(15), 26(24) }
48 %loadA = load i32, ptr %arrayidxA, align 4
50 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
51 %loadB = load i32, ptr %arrayidxB, align 4
53 %mulA = mul i32 %loadB, %loadA
55 %add = add nuw nsw i64 %ind, 1
56 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
57 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
61 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
63 ; CHECK: %loadD = {{.*}} !alias.scope !31
64 ; D's scope: !31 -> { 18(15), 32(33) }
66 %loadD = load i32, ptr %arrayidxD, align 4
68 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
70 ; CHECK: %loadE = {{.*}} !alias.scope !34
71 ; E's scope: !34 -> { 19(15), 35(33) }
73 %loadE = load i32, ptr %arrayidxE, align 4
75 %mulC = mul i32 %loadD, %loadE
77 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
79 ; CHECK: store i32 %mulC, {{.*}} !alias.scope !36, !noalias !38
80 ; C's scope: !36 -> { 17(15), 37(33) }
82 ; C noalias D and E: !38 -> { 21(15), 32(33), 35(33) }
84 store i32 %mulC, ptr %arrayidxC, align 4
86 %exitcond = icmp eq i64 %add, 20
87 br i1 %exitcond, label %for.end, label %for.body
89 for.end: ; preds = %for.body
93 ; Domain for the second loop versioning for the top loop after
95 ; CHECK: !15 = distinct !{!15, !"LVerDomain"}
96 ; CHECK: !17 = distinct !{!17, !15}
97 ; CHECK: !25 = !{!17, !18, !19, !26}
98 ; CHECK: !31 = !{!18, !32}
99 ; CHECK: !32 = distinct !{!32, !33}
100 ; Domain for the second loop versioning for the bottom loop after
102 ; CHECK: !33 = distinct !{!33, !"LVerDomain"}
103 ; CHECK: !34 = !{!19, !35}
104 ; CHECK: !35 = distinct !{!35, !33}
105 ; CHECK: !36 = !{!17, !37}
106 ; CHECK: !38 = !{!21, !32, !35}