blob: c53dc858c5cef0fca9b2293339e375d1c2d4eaa4 [file] [log] [blame]
Adam Nemet32e6a342016-12-21 04:07:40 +00001; RUN: opt -basicaa -loop-distribute -enable-loop-distribute -loop-simplify -scoped-noalias \
Florian Hahn2e032132016-12-19 17:13:37 +00002; RUN: -loop-versioning -S < %s | FileCheck %s
Adam Nemet5eccf072016-03-17 20:32:32 +00003
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
8; within each.
9;
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:
13;
14; for (i = 0; i < n; i++) {
15; A[i + 1] = A[i] * B[i];
16; -------------------------------
17; C[i] = D[i] * E[i];
18; }
19
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).
23
24target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
25
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
31
32define void @f() {
33entry:
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
39 br label %for.body
40
41for.body: ; preds = %for.body, %entry
42 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
43
44 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
45
46; CHECK: %loadA.ldist1 = {{.*}} !noalias !25
47; A noalias C: !25 -> { 17(15), 18(15), 19(15), 26(24) }
48; ^^^^^^
49 %loadA = load i32, i32* %arrayidxA, align 4
50
51 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
52 %loadB = load i32, i32* %arrayidxB, align 4
53
54 %mulA = mul i32 %loadB, %loadA
55
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
59
60; CHECK: for.body:
61
62 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
63
64; CHECK: %loadD = {{.*}} !alias.scope !31
65; D's scope: !31 -> { 18(15), 32(33) }
66; ^^^^^^
67 %loadD = load i32, i32* %arrayidxD, align 4
68
69 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
70
71; CHECK: %loadE = {{.*}} !alias.scope !34
72; E's scope: !34 -> { 19(15), 35(33) }
73; ^^^^^^
74 %loadE = load i32, i32* %arrayidxE, align 4
75
76 %mulC = mul i32 %loadD, %loadE
77
78 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
79
80; CHECK: store i32 %mulC, {{.*}} !alias.scope !36, !noalias !38
81; C's scope: !36 -> { 17(15), 37(33) }
82; ^^^^^^
83; C noalias D and E: !38 -> { 21(15), 32(33), 35(33) }
84; ^^^^^^ ^^^^^^
85 store i32 %mulC, i32* %arrayidxC, align 4
86
87 %exitcond = icmp eq i64 %add, 20
88 br i1 %exitcond, label %for.end, label %for.body
89
90for.end: ; preds = %for.body
91 ret void
92}
93
94; Domain for the second loop versioning for the top loop after
95; distribution.
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
102; distribution.
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}