1 ; RUN: opt -basicaa -loop-distribute -enable-loop-distribute=0 -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=EXPLICIT --check-prefix=DEFAULT_OFF
2 ; RUN: opt -basicaa -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 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
9 target triple = "x86_64-apple-macosx10.10.0"
11 ; CHECK-LABEL: @explicit_on(
12 define void @explicit_on(i32* noalias %a,
20 ; EXPLICIT: for.body.ldist1:
22 for.body: ; preds = %for.body, %entry
23 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
25 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
26 %loadA = load i32, i32* %arrayidxA, align 4
28 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
29 %loadB = load i32, i32* %arrayidxB, align 4
31 %mulA = mul i32 %loadB, %loadA
33 %add = add nuw nsw i64 %ind, 1
34 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
35 store i32 %mulA, i32* %arrayidxA_plus_4, align 4
37 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
38 %loadD = load i32, i32* %arrayidxD, align 4
40 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
41 %loadE = load i32, i32* %arrayidxE, align 4
43 %mulC = mul i32 %loadD, %loadE
45 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
46 store i32 %mulC, i32* %arrayidxC, align 4
48 %exitcond = icmp eq i64 %add, 20
49 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
51 for.end: ; preds = %for.body
55 ; CHECK-LABEL: @explicit_off(
56 define void @explicit_off(i32* noalias %a,
64 ; EXPLICIT-NOT: for.body.ldist1:
66 for.body: ; preds = %for.body, %entry
67 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
69 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
70 %loadA = load i32, i32* %arrayidxA, align 4
72 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
73 %loadB = load i32, i32* %arrayidxB, align 4
75 %mulA = mul i32 %loadB, %loadA
77 %add = add nuw nsw i64 %ind, 1
78 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
79 store i32 %mulA, i32* %arrayidxA_plus_4, align 4
81 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
82 %loadD = load i32, i32* %arrayidxD, align 4
84 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
85 %loadE = load i32, i32* %arrayidxE, align 4
87 %mulC = mul i32 %loadD, %loadE
89 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
90 store i32 %mulC, i32* %arrayidxC, align 4
92 %exitcond = icmp eq i64 %add, 20
93 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !2
95 for.end: ; preds = %for.body
99 ; CHECK-LABEL: @default_distribute(
100 define void @default_distribute(i32* noalias %a,
108 ; Verify the two distributed loops.
110 ; DEFAULT_ON: for.body.ldist1:
111 ; DEFAULT_OFF-NOT: for.body.ldist1:
113 for.body: ; preds = %for.body, %entry
114 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
116 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
117 %loadA = load i32, i32* %arrayidxA, align 4
119 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
120 %loadB = load i32, i32* %arrayidxB, align 4
122 %mulA = mul i32 %loadB, %loadA
124 %add = add nuw nsw i64 %ind, 1
125 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
126 store i32 %mulA, i32* %arrayidxA_plus_4, align 4
128 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
129 %loadD = load i32, i32* %arrayidxD, align 4
131 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
132 %loadE = load i32, i32* %arrayidxE, align 4
134 %mulC = mul i32 %loadD, %loadE
136 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
137 store i32 %mulC, i32* %arrayidxC, align 4
139 %exitcond = icmp eq i64 %add, 20
140 br i1 %exitcond, label %for.end, label %for.body
142 for.end: ; preds = %for.body
146 !0 = distinct !{!0, !1}
147 !1 = !{!"llvm.loop.distribute.enable", i1 true}
148 !2 = distinct !{!2, !3}
149 !3 = !{!"llvm.loop.distribute.enable", i1 false}