1 ; RUN: opt -passes=loop-distribute -enable-loop-distribute=0 -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=EXPLICIT --check-prefix=DEFAULT_OFF
2 ; RUN: opt -passes=loop-distribute -enable-loop-distribute=1 -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=EXPLICIT --check-prefix=DEFAULT_ON
4 ; Same loop as in basic.ll. Check that distribution is enabled/disabled
5 ; properly according to -enable-loop-distribute=0/1 and the
6 ; llvm.loop.distribute.enable metadata.
8 define void @explicit_on(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e) {
9 ; CHECK-LABEL: @explicit_on(
13 ; EXPLICIT: for.body.ldist1:
14 for.body: ; preds = %for.body, %entry
15 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
17 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
18 %loadA = load i32, ptr %arrayidxA, align 4
20 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
21 %loadB = load i32, ptr %arrayidxB, align 4
23 %mulA = mul i32 %loadB, %loadA
25 %add = add nuw nsw i64 %ind, 1
26 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
27 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
29 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
30 %loadD = load i32, ptr %arrayidxD, align 4
32 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
33 %loadE = load i32, ptr %arrayidxE, align 4
35 %mulC = mul i32 %loadD, %loadE
37 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
38 store i32 %mulC, ptr %arrayidxC, align 4
40 %exitcond = icmp eq i64 %add, 20
41 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
43 for.end: ; preds = %for.body
47 ; CHECK-LABEL: @explicit_off(
48 define void @explicit_off(ptr noalias %a,
56 ; EXPLICIT-NOT: for.body.ldist1:
57 for.body: ; preds = %for.body, %entry
58 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
60 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
61 %loadA = load i32, ptr %arrayidxA, align 4
63 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
64 %loadB = load i32, ptr %arrayidxB, align 4
66 %mulA = mul i32 %loadB, %loadA
68 %add = add nuw nsw i64 %ind, 1
69 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
70 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
72 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
73 %loadD = load i32, ptr %arrayidxD, align 4
75 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
76 %loadE = load i32, ptr %arrayidxE, align 4
78 %mulC = mul i32 %loadD, %loadE
80 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
81 store i32 %mulC, ptr %arrayidxC, align 4
83 %exitcond = icmp eq i64 %add, 20
84 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !2
86 for.end: ; preds = %for.body
90 define void @default_distribute(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d,
92 ; CHECK-LABEL: @default_distribute(
96 ; Verify the two distributed loops.
98 ; DEFAULT_ON: for.body.ldist1:
99 ; DEFAULT_OFF-NOT: for.body.ldist1:
100 for.body: ; preds = %for.body, %entry
101 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
103 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
104 %loadA = load i32, ptr %arrayidxA, align 4
106 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
107 %loadB = load i32, ptr %arrayidxB, align 4
109 %mulA = mul i32 %loadB, %loadA
111 %add = add nuw nsw i64 %ind, 1
112 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
113 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
115 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
116 %loadD = load i32, ptr %arrayidxD, align 4
118 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
119 %loadE = load i32, ptr %arrayidxE, align 4
121 %mulC = mul i32 %loadD, %loadE
123 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
124 store i32 %mulC, ptr %arrayidxC, align 4
126 %exitcond = icmp eq i64 %add, 20
127 br i1 %exitcond, label %for.end, label %for.body
129 for.end: ; preds = %for.body
133 !0 = distinct !{!0, !1}
134 !1 = !{!"llvm.loop.distribute.enable", i1 true}
135 !2 = distinct !{!2, !3}
136 !3 = !{!"llvm.loop.distribute.enable", i1 false}