1 ; RUN: opt -mtriple=armv7 -mcpu=cortex-a57 -loop-unroll -S %s -o - | FileCheck %s --check-prefix=CHECK-NOUNROLL
2 ; RUN: opt -mtriple=thumbv7 -mcpu=cortex-a57 -loop-unroll -S %s -o - | FileCheck %s --check-prefix=CHECK-NOUNROLL
3 ; RUN: opt -mtriple=thumbv7 -mcpu=cortex-a72 -loop-unroll -S %s -o - | FileCheck %s --check-prefix=CHECK-NOUNROLL
4 ; RUN: opt -mtriple=thumbv8m -mcpu=cortex-m23 -loop-unroll -S %s -o - | FileCheck %s --check-prefix=CHECK-UNROLL
5 ; RUN: opt -mtriple=thumbv8m.main -mcpu=cortex-m33 -loop-unroll -S %s -o - | FileCheck %s --check-prefix=CHECK-UNROLL
6 ; RUN: opt -mtriple=thumbv7em -mcpu=cortex-m7 -loop-unroll -S %s -o - | FileCheck %s --check-prefix=CHECK-UNROLL
9 define arm_aapcs_vfpcc void @partial(i32* nocapture %C, i32* nocapture readonly %A, i32* nocapture readonly %B) local_unnamed_addr #0 {
13 ; CHECK-LABEL: for.body
16 ; CHECK-NOUNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, %entry ], [ [[IV2:%[a-z.0-9]+]], %for.body ]
17 ; CHECK-NOUNROLL: [[IV1:%[a-z.0-9]+]] = add nuw nsw i32 [[IV0]], 1
18 ; CHECK-NOUNROLL: [[IV2]] = add nuw nsw i32 [[IV1]], 1
19 ; CHECK-NOUNROLL: [[CMP:%[a-z.0-9]+]] = icmp eq i32 [[IV2]], 1024
20 ; CHECK-NOUNROLL: br i1 [[CMP]], label [[END:%[a-z.]+]], label %for.body
22 ; CHECK-UNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, %entry ], [ [[IV16:%[a-z.0-9]+]], %for.body ]
23 ; CHECK-UNROLL: [[IV1:%[a-z.0-9]+]] = add nuw nsw i32 [[IV0]], 1
24 ; CHECK-UNROLL: [[IV2:%[a-z.0-9]+]] = add nuw nsw i32 [[IV1]], 1
25 ; CHECK-UNROLL: [[IV3:%[a-z.0-9]+]] = add nuw nsw i32 [[IV2]], 1
26 ; CHECK-UNROLL: [[IV4:%[a-z.0-9]+]] = add nuw nsw i32 [[IV3]], 1
27 ; CHECK-UNROLL: [[IV5:%[a-z.0-9]+]] = add nuw nsw i32 [[IV4]], 1
28 ; CHECK-UNROLL: [[IV6:%[a-z.0-9]+]] = add nuw nsw i32 [[IV5]], 1
29 ; CHECK-UNROLL: [[IV7:%[a-z.0-9]+]] = add nuw nsw i32 [[IV6]], 1
30 ; CHECK-UNROLL: [[IV8:%[a-z.0-9]+]] = add nuw nsw i32 [[IV7]], 1
31 ; CHECK-UNROLL: [[IV9:%[a-z.0-9]+]] = add nuw nsw i32 [[IV8]], 1
32 ; CHECK-UNROLL: [[IV10:%[a-z.0-9]+]] = add nuw nsw i32 [[IV9]], 1
33 ; CHECK-UNROLL: [[IV11:%[a-z.0-9]+]] = add nuw nsw i32 [[IV10]], 1
34 ; CHECK-UNROLL: [[IV12:%[a-z.0-9]+]] = add nuw nsw i32 [[IV11]], 1
35 ; CHECK-UNROLL: [[IV13:%[a-z.0-9]+]] = add nuw nsw i32 [[IV12]], 1
36 ; CHECK-UNROLL: [[IV14:%[a-z.0-9]+]] = add nuw nsw i32 [[IV13]], 1
37 ; CHECK-UNROLL: [[IV15:%[a-z.0-9]+]] = add nuw nsw i32 [[IV14]], 1
38 ; CHECK-UNROLL: [[IV16]] = add nuw nsw i32 [[IV15]], 1
39 ; CHECK-UNROLL: [[CMP:%[a-z.0-9]+]] = icmp eq i32 [[IV16]], 1024
40 ; CHECK-UNROLL: br i1 [[CMP]], label [[END:%[a-z.]+]], label %for.body
42 %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
43 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.08
44 %0 = load i32, i32* %arrayidx, align 4
45 %arrayidx1 = getelementptr inbounds i32, i32* %B, i32 %i.08
46 %1 = load i32, i32* %arrayidx1, align 4
47 %mul = mul nsw i32 %1, %0
48 %arrayidx2 = getelementptr inbounds i32, i32* %C, i32 %i.08
49 store i32 %mul, i32* %arrayidx2, align 4
50 %inc = add nuw nsw i32 %i.08, 1
51 %exitcond = icmp eq i32 %inc, 1024
52 br i1 %exitcond, label %for.cond.cleanup, label %for.body
58 ; CHECK-LABEL: runtime
59 define arm_aapcs_vfpcc void @runtime(i32* nocapture %C, i32* nocapture readonly %A, i32* nocapture readonly %B, i32 %N) local_unnamed_addr #0 {
61 %cmp8 = icmp eq i32 %N, 0
62 br i1 %cmp8, label %for.cond.cleanup, label %for.body
64 ; CHECK-LABEL: for.body
66 ; CHECK-NOUNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, [[PRE:%[a-z.0-9]+]] ], [ [[IV2:%[a-z.0-9]+]], %for.body ]
67 ; CHECK-NOUNROLL: [[IV1:%[a-z.0-9]+]] = add nuw nsw i32 [[IV0]], 1
68 ; CHECK-NOUNROLL: [[IV2]] = add nuw i32 [[IV1]], 1
71 ; CHECK-UNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, [[PRE:%[a-z.0-9]+]] ], [ [[IV4:%[a-z.0-9]+]], %for.body ]
72 ; CHECK-UNROLL: [[IV1:%[a-z.0-9]+]] = add nuw nsw i32 [[IV0]], 1
73 ; CHECK-UNROLL: [[IV2:%[a-z.0-9]+]] = add nuw nsw i32 [[IV1]], 1
74 ; CHECK-UNROLL: [[IV3:%[a-z.0-9]+]] = add nuw nsw i32 [[IV2]], 1
75 ; CHECK-UNROLL: [[IV4]] = add nuw i32 [[IV3]], 1
78 ; CHECK-UNROLL: for.body.epil:
79 ; CHECK-UNROLL: for.body.epil.1:
80 ; CHECK-UNROLL: for.body.epil.2:
82 %i.09 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
83 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.09
84 %0 = load i32, i32* %arrayidx, align 4
85 %arrayidx1 = getelementptr inbounds i32, i32* %B, i32 %i.09
86 %1 = load i32, i32* %arrayidx1, align 4
87 %mul = mul nsw i32 %1, %0
88 %arrayidx2 = getelementptr inbounds i32, i32* %C, i32 %i.09
89 store i32 %mul, i32* %arrayidx2, align 4
90 %inc = add nuw i32 %i.09, 1
91 %exitcond = icmp eq i32 %inc, %N
92 br i1 %exitcond, label %for.cond.cleanup, label %for.body
98 ; CHECK-LABEL: nested_runtime
99 define arm_aapcs_vfpcc void @nested_runtime(i32* nocapture %C, i16* nocapture readonly %A, i16* nocapture readonly %B, i32 %N) local_unnamed_addr #0 {
101 %cmp25 = icmp eq i32 %N, 0
102 br i1 %cmp25, label %for.cond.cleanup, label %for.body4.lr.ph
105 %h.026 = phi i32 [ %inc11, %for.cond.cleanup3 ], [ 0, %entry ]
106 %mul = mul i32 %h.026, %N
113 %inc11 = add nuw i32 %h.026, 1
114 %exitcond27 = icmp eq i32 %inc11, %N
115 br i1 %exitcond27, label %for.cond.cleanup, label %for.body4.lr.ph
117 ; CHECK-LABEL: for.body4
119 ; CHECK-NOUNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, [[PRE:%[a-z0-9.]+]] ], [ [[IV1:%[a-z.0-9]+]], %for.body4 ]
120 ; CHECK-NOUNROLL: [[IV1]] = add nuw i32 [[IV0]], 1
123 ; CHECK-UNROLL: for.body4.epil:
124 ; CHECK-UNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, [[PRE:%[a-z0-9.]+]] ], [ [[IV4:%[a-z.0-9]+]], %for.body4 ]
125 ; CHECK-UNROLL: [[IV1:%[a-z.0-9]+]] = add nuw nsw i32 [[IV0]], 1
126 ; CHECK-UNROLL: [[IV2:%[a-z.0-9]+]] = add nuw nsw i32 [[IV1]], 1
127 ; CHECK-UNROLL: [[IV3:%[a-z.0-9]+]] = add nuw nsw i32 [[IV2]], 1
128 ; CHECK-UNROLL: [[IV4]] = add nuw i32 [[IV3]], 1
130 ; CHECK-UNROLL: for.body4.epil.1:
131 ; CHECK-UNROLL: for.body4.epil.2:
133 %w.024 = phi i32 [ 0, %for.body4.lr.ph ], [ %inc, %for.body4 ]
134 %add = add i32 %w.024, %mul
135 %arrayidx = getelementptr inbounds i16, i16* %A, i32 %add
136 %0 = load i16, i16* %arrayidx, align 2
137 %conv = sext i16 %0 to i32
138 %arrayidx5 = getelementptr inbounds i16, i16* %B, i32 %w.024
139 %1 = load i16, i16* %arrayidx5, align 2
140 %conv6 = sext i16 %1 to i32
141 %mul7 = mul nsw i32 %conv6, %conv
142 %arrayidx8 = getelementptr inbounds i32, i32* %C, i32 %w.024
143 %2 = load i32, i32* %arrayidx8, align 4
144 %add9 = add nsw i32 %mul7, %2
145 store i32 %add9, i32* %arrayidx8, align 4
146 %inc = add nuw i32 %w.024, 1
147 %exitcond = icmp eq i32 %inc, %N
148 br i1 %exitcond, label %for.cond.cleanup3, label %for.body4
151 ; CHECK-LABEL: loop_call
152 define arm_aapcs_vfpcc void @loop_call(i32* nocapture %C, i32* nocapture readonly %A, i32* nocapture readonly %B) local_unnamed_addr #1 {
159 ; CHECK-LABEL: for.body
161 ; CHECK-NOUNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, %entry ], [ [[IV1:%[a-z.0-9]+]], %for.body ]
162 ; CHECK-NOUNROLL: [[IV1]] = add nuw nsw i32 [[IV0]], 1
163 ; CHECK-NOUNROLL: icmp eq i32 [[IV1]], 1024
166 ; CHECK-UNROLL: [[IV0:%[a-z.0-9]+]] = phi i32 [ 0, %entry ], [ [[IV1:%[a-z.0-9]+]], %for.body ]
167 ; CHECK-UNROLL: [[IV1]] = add nuw nsw i32 [[IV0]], 1
168 ; CHECK-UNROLL: icmp eq i32 [[IV1]], 1024
171 %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
172 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.08
173 %0 = load i32, i32* %arrayidx, align 4
174 %arrayidx1 = getelementptr inbounds i32, i32* %B, i32 %i.08
175 %1 = load i32, i32* %arrayidx1, align 4
176 %call = tail call arm_aapcs_vfpcc i32 @some_func(i32 %0, i32 %1) #3
177 %arrayidx2 = getelementptr inbounds i32, i32* %C, i32 %i.08
178 store i32 %call, i32* %arrayidx2, align 4
179 %inc = add nuw nsw i32 %i.08, 1
180 %exitcond = icmp eq i32 %inc, 1024
181 br i1 %exitcond, label %for.cond.cleanup, label %for.body
184 ; CHECK-LABEL: iterate_inc
185 ; CHECK-NOUNROLL: %n.addr.04 = phi %struct.Node* [ %1, %while.body ], [ %n, %while.body.preheader ]
186 ; CHECK-NOUNROLL: %tobool = icmp eq %struct.Node* %1, null
187 ; CHECK-NOUNROLL: br i1 %tobool
188 ; CHECK-NOUNROLL-NOT: load
190 ; CHECK-UNROLL: [[CMP0:%[a-z.0-9]+]] = icmp eq %struct.Node* [[VAR0:%[a-z.0-9]+]], null
191 ; CHECK-UNROLL: br i1 [[CMP0]], label [[END:%[a-z.0-9]+]]
192 ; CHECK-UNROLL: [[CMP1:%[a-z.0-9]+]] = icmp eq %struct.Node* [[VAR1:%[a-z.0-9]+]], null
193 ; CHECK-UNROLL: br i1 [[CMP1]], label [[END]]
194 ; CHECK-UNROLL: [[CMP2:%[a-z.0-9]+]] = icmp eq %struct.Node* [[VAR2:%[a-z.0-9]+]], null
195 ; CHECK-UNROLL: br i1 [[CMP2]], label [[END]]
196 ; CHECK-UNROLL: [[CMP3:%[a-z.0-9]+]] = icmp eq %struct.Node* [[VAR3:%[a-z.0-9]+]], null
197 ; CHECK-UNROLL: br i1 [[CMP3]], label [[END]]
198 ; CHECK-UNROLL: [[CMP4:%[a-z.0-9]+]] = icmp eq %struct.Node* [[VAR4:%[a-z.0-9]+]], null
199 ; CHECK-UNROLL: br i1 [[CMP4]], label [[END]]
200 ; CHECK-UNROLL-NOT: load
202 %struct.Node = type { %struct.Node*, i32 }
204 define arm_aapcscc void @iterate_inc(%struct.Node* %n) local_unnamed_addr #0 {
206 %tobool3 = icmp eq %struct.Node* %n, null
207 br i1 %tobool3, label %while.end, label %while.body.preheader
209 while.body.preheader:
213 %n.addr.04 = phi %struct.Node* [ %1, %while.body ], [ %n, %while.body.preheader ]
214 %val = getelementptr inbounds %struct.Node, %struct.Node* %n.addr.04, i32 0, i32 1
215 %0 = load i32, i32* %val, align 4
216 %add = add nsw i32 %0, 1
217 store i32 %add, i32* %val, align 4
218 %next = getelementptr inbounds %struct.Node, %struct.Node* %n.addr.04, i32 0, i32 0
219 %1 = load %struct.Node*, %struct.Node** %next, align 4
220 %tobool = icmp eq %struct.Node* %1, null
221 br i1 %tobool, label %while.end, label %while.body
227 declare arm_aapcs_vfpcc i32 @some_func(i32, i32) local_unnamed_addr #2