1 ; RUN: opt -basicaa -loop-idiom < %s -S | FileCheck %s
2 target datalayout = "e-p:40:64:64:32-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"
4 %struct.foo = type { i32, i32 }
5 %struct.foo1 = type { i32, i32, i32 }
6 %struct.foo2 = type { i32, i16, i16 }
8 ;void bar1(foo_t *f, unsigned n) {
9 ; for (unsigned i = 0; i < n; ++i) {
14 define void @bar1(%struct.foo* %f, i32 %n) nounwind ssp {
16 %cmp1 = icmp eq i32 %n, 0
17 br i1 %cmp1, label %for.end, label %for.body.preheader
19 for.body.preheader: ; preds = %entry
22 for.body: ; preds = %for.body.preheader, %for.body
23 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
24 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 0
25 store i32 0, i32* %a, align 4
26 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 1
27 store i32 0, i32* %b, align 4
28 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
29 %exitcond = icmp ne i32 %indvars.iv.next, %n
30 br i1 %exitcond, label %for.body, label %for.end.loopexit
32 for.end.loopexit: ; preds = %for.body
35 for.end: ; preds = %for.end.loopexit, %entry
38 ; CHECK: call void @llvm.memset
42 ;void bar2(foo_t *f, unsigned n) {
43 ; for (unsigned i = 0; i < n; ++i) {
48 define void @bar2(%struct.foo* %f, i32 %n) nounwind ssp {
50 %cmp1 = icmp eq i32 %n, 0
51 br i1 %cmp1, label %for.end, label %for.body.preheader
53 for.body.preheader: ; preds = %entry
56 for.body: ; preds = %for.body.preheader, %for.body
57 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
58 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 1
59 store i32 0, i32* %b, align 4
60 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 0
61 store i32 0, i32* %a, align 4
62 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
63 %exitcond = icmp ne i32 %indvars.iv.next, %n
64 br i1 %exitcond, label %for.body, label %for.end.loopexit
66 for.end.loopexit: ; preds = %for.body
69 for.end: ; preds = %for.end.loopexit, %entry
72 ; CHECK: call void @llvm.memset
76 ;void bar3(foo_t *f, unsigned n) {
77 ; for (unsigned i = n; i > 0; --i) {
82 define void @bar3(%struct.foo* nocapture %f, i32 %n) nounwind ssp {
84 %cmp1 = icmp eq i32 %n, 0
85 br i1 %cmp1, label %for.end, label %for.body.preheader
87 for.body.preheader: ; preds = %entry
90 for.body: ; preds = %for.body.preheader, %for.body
91 %indvars.iv = phi i32 [ %n, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
92 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 0
93 store i32 0, i32* %a, align 4
94 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 1
95 store i32 0, i32* %b, align 4
96 %dec = add i32 %indvars.iv, -1
97 %cmp = icmp eq i32 %dec, 0
98 %indvars.iv.next = add nsw i32 %indvars.iv, -1
99 br i1 %cmp, label %for.end.loopexit, label %for.body
101 for.end.loopexit: ; preds = %for.body
104 for.end: ; preds = %for.end.loopexit, %entry
106 ; CHECK-LABEL: @bar3(
107 ; CHECK: call void @llvm.memset
111 ;void bar4(foo_t *f, unsigned n) {
112 ; for (unsigned i = 0; i < n; ++i) {
117 define void @bar4(%struct.foo* nocapture %f, i32 %n) nounwind ssp {
119 %cmp1 = icmp eq i32 %n, 0
120 br i1 %cmp1, label %for.end, label %for.body.preheader
122 for.body.preheader: ; preds = %entry
125 for.body: ; preds = %for.body.preheader, %for.body
126 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
127 %a = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 0
128 store i32 0, i32* %a, align 4
129 %b = getelementptr inbounds %struct.foo, %struct.foo* %f, i32 %indvars.iv, i32 1
130 store i32 1, i32* %b, align 4
131 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
132 %exitcond = icmp ne i32 %indvars.iv.next, %n
133 br i1 %exitcond, label %for.body, label %for.end.loopexit
135 for.end.loopexit: ; preds = %for.body
138 for.end: ; preds = %for.end.loopexit, %entry
140 ; CHECK-LABEL: @bar4(
141 ; CHECK-NOT: call void @llvm.memset
144 ;void bar5(foo1_t *f, unsigned n) {
145 ; for (unsigned i = 0; i < n; ++i) {
150 define void @bar5(%struct.foo1* nocapture %f, i32 %n) nounwind ssp {
152 %cmp1 = icmp eq i32 %n, 0
153 br i1 %cmp1, label %for.end, label %for.body.preheader
155 for.body.preheader: ; preds = %entry
158 for.body: ; preds = %for.body.preheader, %for.body
159 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
160 %a = getelementptr inbounds %struct.foo1, %struct.foo1* %f, i32 %indvars.iv, i32 0
161 store i32 0, i32* %a, align 4
162 %b = getelementptr inbounds %struct.foo1, %struct.foo1* %f, i32 %indvars.iv, i32 1
163 store i32 0, i32* %b, align 4
164 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
165 %exitcond = icmp ne i32 %indvars.iv.next, %n
166 br i1 %exitcond, label %for.body, label %for.end.loopexit
168 for.end.loopexit: ; preds = %for.body
171 for.end: ; preds = %for.end.loopexit, %entry
173 ; CHECK-LABEL: @bar5(
174 ; CHECK-NOT: call void @llvm.memset
177 ;void bar6(foo2_t *f, unsigned n) {
178 ; for (unsigned i = 0; i < n; ++i) {
184 define void @bar6(%struct.foo2* nocapture %f, i32 %n) nounwind ssp {
186 %cmp1 = icmp eq i32 %n, 0
187 br i1 %cmp1, label %for.end, label %for.body.preheader
189 for.body.preheader: ; preds = %entry
192 for.body: ; preds = %for.body.preheader, %for.body
193 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
194 %a = getelementptr inbounds %struct.foo2, %struct.foo2* %f, i32 %indvars.iv, i32 0
195 store i32 0, i32* %a, align 4
196 %b = getelementptr inbounds %struct.foo2, %struct.foo2* %f, i32 %indvars.iv, i32 1
197 store i16 0, i16* %b, align 4
198 %c = getelementptr inbounds %struct.foo2, %struct.foo2* %f, i32 %indvars.iv, i32 2
199 store i16 0, i16* %c, align 2
200 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
201 %exitcond = icmp ne i32 %indvars.iv.next, %n
202 br i1 %exitcond, label %for.body, label %for.end.loopexit
204 for.end.loopexit: ; preds = %for.body
207 for.end: ; preds = %for.end.loopexit, %entry
209 ; CHECK-LABEL: @bar6(
210 ; CHECK: call void @llvm.memset