1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -basic-aa -loop-idiom < %s -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5 ; CHECK: @.memset_pattern = private unnamed_addr constant [4 x i32] [i32 2, i32 2, i32 2, i32 2], align 16
6 ; CHECK: @.memset_pattern.1 = private unnamed_addr constant [4 x i32] [i32 2, i32 2, i32 2, i32 2], align 16
7 ; CHECK: @.memset_pattern.2 = private unnamed_addr constant [4 x i32] [i32 2, i32 2, i32 2, i32 2], align 16
9 target triple = "x86_64-apple-darwin10.0.0"
11 %struct.foo = type { i32, i32 }
12 %struct.foo1 = type { i32, i32, i32 }
14 ;void bar1(foo_t *f, unsigned n) {
15 ; for (unsigned i = 0; i < n; ++i) {
20 define void @bar1(%struct.foo* %f, i32 %n) nounwind ssp {
23 ; CHECK-NEXT: [[F1:%.*]] = bitcast %struct.foo* [[F:%.*]] to i8*
24 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0
25 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
26 ; CHECK: for.body.preheader:
27 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64
28 ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i64 [[TMP0]], 3
29 ; CHECK-NEXT: call void @memset_pattern16(i8* [[F1]], i8* bitcast ([4 x i32]* @.memset_pattern to i8*), i64 [[TMP1]])
30 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
32 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
33 ; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 0
34 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 1
35 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
36 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
37 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]
38 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
39 ; CHECK: for.end.loopexit:
40 ; CHECK-NEXT: br label [[FOR_END]]
42 ; CHECK-NEXT: ret void
45 %cmp1 = icmp eq i32 %n, 0
46 br i1 %cmp1, label %for.end, label %for.body.preheader
48 for.body.preheader: ; preds = %entry
51 for.body: ; preds = %for.body.preheader, %for.body
52 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
53 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 0
54 store i32 2, i32* %a, align 4
55 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 1
56 store i32 2, i32* %b, align 4
57 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
58 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
59 %exitcond = icmp ne i32 %lftr.wideiv, %n
60 br i1 %exitcond, label %for.body, label %for.end.loopexit
62 for.end.loopexit: ; preds = %for.body
65 for.end: ; preds = %for.end.loopexit, %entry
69 ;void bar2(foo_t *f, unsigned n) {
70 ; for (unsigned i = 0; i < n; ++i) {
75 define void @bar2(%struct.foo* %f, i32 %n) nounwind ssp {
78 ; CHECK-NEXT: [[F1:%.*]] = bitcast %struct.foo* [[F:%.*]] to i8*
79 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0
80 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
81 ; CHECK: for.body.preheader:
82 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64
83 ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i64 [[TMP0]], 3
84 ; CHECK-NEXT: call void @memset_pattern16(i8* [[F1]], i8* bitcast ([4 x i32]* @.memset_pattern.1 to i8*), i64 [[TMP1]])
85 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
87 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
88 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 1
89 ; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 0
90 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
91 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
92 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]
93 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
94 ; CHECK: for.end.loopexit:
95 ; CHECK-NEXT: br label [[FOR_END]]
97 ; CHECK-NEXT: ret void
100 %cmp1 = icmp eq i32 %n, 0
101 br i1 %cmp1, label %for.end, label %for.body.preheader
103 for.body.preheader: ; preds = %entry
106 for.body: ; preds = %for.body.preheader, %for.body
107 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
108 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 1
109 store i32 2, i32* %b, align 4
110 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 0
111 store i32 2, i32* %a, align 4
112 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
113 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
114 %exitcond = icmp ne i32 %lftr.wideiv, %n
115 br i1 %exitcond, label %for.body, label %for.end.loopexit
117 for.end.loopexit: ; preds = %for.body
120 for.end: ; preds = %for.end.loopexit, %entry
124 ;void bar3(foo_t *f, unsigned n) {
125 ; for (unsigned i = n; i > 0; --i) {
130 define void @bar3(%struct.foo* nocapture %f, i32 %n) nounwind ssp {
131 ; CHECK-LABEL: @bar3(
133 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0
134 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
135 ; CHECK: for.body.preheader:
136 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64
137 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[N]], -1
138 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64
139 ; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP0]], [[TMP2]]
140 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr [[STRUCT_FOO:%.*]], %struct.foo* [[F:%.*]], i64 [[TMP3]]
141 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = bitcast %struct.foo* [[SCEVGEP]] to i8*
142 ; CHECK-NEXT: [[TMP4:%.*]] = shl nuw nsw i64 [[TMP0]], 3
143 ; CHECK-NEXT: call void @memset_pattern16(i8* [[SCEVGEP1]], i8* bitcast ([4 x i32]* @.memset_pattern.2 to i8*), i64 [[TMP4]])
144 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
146 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[TMP0]], [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
147 ; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 0
148 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 1
149 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i64 [[INDVARS_IV]] to i32
150 ; CHECK-NEXT: [[DEC:%.*]] = add i32 [[TMP5]], -1
151 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[DEC]], 0
152 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], -1
153 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]]
154 ; CHECK: for.end.loopexit:
155 ; CHECK-NEXT: br label [[FOR_END]]
157 ; CHECK-NEXT: ret void
160 %cmp1 = icmp eq i32 %n, 0
161 br i1 %cmp1, label %for.end, label %for.body.preheader
163 for.body.preheader: ; preds = %entry
164 %0 = zext i32 %n to i64
167 for.body: ; preds = %for.body.preheader, %for.body
168 %indvars.iv = phi i64 [ %0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
169 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 0
170 store i32 2, i32* %a, align 4
171 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 1
172 store i32 2, i32* %b, align 4
173 %1 = trunc i64 %indvars.iv to i32
174 %dec = add i32 %1, -1
175 %cmp = icmp eq i32 %dec, 0
176 %indvars.iv.next = add nsw i64 %indvars.iv, -1
177 br i1 %cmp, label %for.end.loopexit, label %for.body
179 for.end.loopexit: ; preds = %for.body
182 for.end: ; preds = %for.end.loopexit, %entry
186 ;void bar4(foo_t *f, unsigned n) {
187 ; for (unsigned i = 0; i < n; ++i) {
192 define void @bar4(%struct.foo* nocapture %f, i32 %n) nounwind ssp {
193 ; CHECK-LABEL: @bar4(
195 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0
196 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
197 ; CHECK: for.body.preheader:
198 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
200 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
201 ; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.foo* [[F:%.*]], i64 [[INDVARS_IV]], i32 0
202 ; CHECK-NEXT: store i32 0, i32* [[A]], align 4
203 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO]], %struct.foo* [[F]], i64 [[INDVARS_IV]], i32 1
204 ; CHECK-NEXT: store i32 1, i32* [[B]], align 4
205 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
206 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
207 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]
208 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
209 ; CHECK: for.end.loopexit:
210 ; CHECK-NEXT: br label [[FOR_END]]
212 ; CHECK-NEXT: ret void
215 %cmp1 = icmp eq i32 %n, 0
216 br i1 %cmp1, label %for.end, label %for.body.preheader
218 for.body.preheader: ; preds = %entry
221 for.body: ; preds = %for.body.preheader, %for.body
222 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
223 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 0
224 store i32 0, i32* %a, align 4
225 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 %indvars.iv, i32 1
226 store i32 1, i32* %b, align 4
227 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
228 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
229 %exitcond = icmp ne i32 %lftr.wideiv, %n
230 br i1 %exitcond, label %for.body, label %for.end.loopexit
232 for.end.loopexit: ; preds = %for.body
235 for.end: ; preds = %for.end.loopexit, %entry
239 ;void bar5(foo1_t *f, unsigned n) {
240 ; for (unsigned i = 0; i < n; ++i) {
245 define void @bar5(%struct.foo1* nocapture %f, i32 %n) nounwind ssp {
246 ; CHECK-LABEL: @bar5(
248 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0
249 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
250 ; CHECK: for.body.preheader:
251 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
253 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
254 ; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO1:%.*]], %struct.foo1* [[F:%.*]], i64 [[INDVARS_IV]], i32 0
255 ; CHECK-NEXT: store i32 1, i32* [[A]], align 4
256 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO1]], %struct.foo1* [[F]], i64 [[INDVARS_IV]], i32 1
257 ; CHECK-NEXT: store i32 1, i32* [[B]], align 4
258 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
259 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
260 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]
261 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
262 ; CHECK: for.end.loopexit:
263 ; CHECK-NEXT: br label [[FOR_END]]
265 ; CHECK-NEXT: ret void
268 %cmp1 = icmp eq i32 %n, 0
269 br i1 %cmp1, label %for.end, label %for.body.preheader
271 for.body.preheader: ; preds = %entry
274 for.body: ; preds = %for.body.preheader, %for.body
275 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
276 %a = getelementptr inbounds %struct.foo1, %struct.foo1* %f, i64 %indvars.iv, i32 0
277 store i32 1, i32* %a, align 4
278 %b = getelementptr inbounds %struct.foo1, %struct.foo1* %f, i64 %indvars.iv, i32 1
279 store i32 1, i32* %b, align 4
280 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
281 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
282 %exitcond = icmp ne i32 %lftr.wideiv, %n
283 br i1 %exitcond, label %for.body, label %for.end.loopexit
285 for.end.loopexit: ; preds = %for.body
288 for.end: ; preds = %for.end.loopexit, %entry