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" 3 4 %struct.foo = type { i32, i32 } 5 %struct.foo1 = type { i32, i32, i32 } 6 %struct.foo2 = type { i32, i16, i16 } 7 8 ;void bar1(foo_t *f, unsigned n) { 9 ; for (unsigned i = 0; i < n; ++i) { 10 ; f[i].a = 0; 11 ; f[i].b = 0; 12 ; } 13 ;} 14 define void @bar1(%struct.foo* %f, i32 %n) nounwind ssp { 15 entry: 16 %cmp1 = icmp eq i32 %n, 0 17 br i1 %cmp1, label %for.end, label %for.body.preheader 18 19 for.body.preheader: ; preds = %entry 20 br label %for.body 21 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 31 32 for.end.loopexit: ; preds = %for.body 33 br label %for.end 34 35 for.end: ; preds = %for.end.loopexit, %entry 36 ret void 37 ; CHECK-LABEL: @bar1( 38 ; CHECK: call void @llvm.memset 39 ; CHECK-NOT: store 40 } 41 42 ;void bar2(foo_t *f, unsigned n) { 43 ; for (unsigned i = 0; i < n; ++i) { 44 ; f[i].b = 0; 45 ; f[i].a = 0; 46 ; } 47 ;} 48 define void @bar2(%struct.foo* %f, i32 %n) nounwind ssp { 49 entry: 50 %cmp1 = icmp eq i32 %n, 0 51 br i1 %cmp1, label %for.end, label %for.body.preheader 52 53 for.body.preheader: ; preds = %entry 54 br label %for.body 55 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 65 66 for.end.loopexit: ; preds = %for.body 67 br label %for.end 68 69 for.end: ; preds = %for.end.loopexit, %entry 70 ret void 71 ; CHECK-LABEL: @bar2( 72 ; CHECK: call void @llvm.memset 73 ; CHECK-NOT: store 74 } 75 76 ;void bar3(foo_t *f, unsigned n) { 77 ; for (unsigned i = n; i > 0; --i) { 78 ; f[i].a = 0; 79 ; f[i].b = 0; 80 ; } 81 ;} 82 define void @bar3(%struct.foo* nocapture %f, i32 %n) nounwind ssp { 83 entry: 84 %cmp1 = icmp eq i32 %n, 0 85 br i1 %cmp1, label %for.end, label %for.body.preheader 86 87 for.body.preheader: ; preds = %entry 88 br label %for.body 89 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 100 101 for.end.loopexit: ; preds = %for.body 102 br label %for.end 103 104 for.end: ; preds = %for.end.loopexit, %entry 105 ret void 106 ; CHECK-LABEL: @bar3( 107 ; CHECK: call void @llvm.memset 108 ; CHECK-NOT: store 109 } 110 111 ;void bar4(foo_t *f, unsigned n) { 112 ; for (unsigned i = 0; i < n; ++i) { 113 ; f[i].a = 0; 114 ; f[i].b = 1; 115 ; } 116 ;} 117 define void @bar4(%struct.foo* nocapture %f, i32 %n) nounwind ssp { 118 entry: 119 %cmp1 = icmp eq i32 %n, 0 120 br i1 %cmp1, label %for.end, label %for.body.preheader 121 122 for.body.preheader: ; preds = %entry 123 br label %for.body 124 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 134 135 for.end.loopexit: ; preds = %for.body 136 br label %for.end 137 138 for.end: ; preds = %for.end.loopexit, %entry 139 ret void 140 ; CHECK-LABEL: @bar4( 141 ; CHECK-NOT: call void @llvm.memset 142 } 143 144 ;void bar5(foo1_t *f, unsigned n) { 145 ; for (unsigned i = 0; i < n; ++i) { 146 ; f[i].a = 0; 147 ; f[i].b = 0; 148 ; } 149 ;} 150 define void @bar5(%struct.foo1* nocapture %f, i32 %n) nounwind ssp { 151 entry: 152 %cmp1 = icmp eq i32 %n, 0 153 br i1 %cmp1, label %for.end, label %for.body.preheader 154 155 for.body.preheader: ; preds = %entry 156 br label %for.body 157 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 167 168 for.end.loopexit: ; preds = %for.body 169 br label %for.end 170 171 for.end: ; preds = %for.end.loopexit, %entry 172 ret void 173 ; CHECK-LABEL: @bar5( 174 ; CHECK-NOT: call void @llvm.memset 175 } 176 177 ;void bar6(foo2_t *f, unsigned n) { 178 ; for (unsigned i = 0; i < n; ++i) { 179 ; f[i].a = 0; 180 ; f[i].b = 0; 181 ; f[i].c = 0; 182 ; } 183 ;} 184 define void @bar6(%struct.foo2* nocapture %f, i32 %n) nounwind ssp { 185 entry: 186 %cmp1 = icmp eq i32 %n, 0 187 br i1 %cmp1, label %for.end, label %for.body.preheader 188 189 for.body.preheader: ; preds = %entry 190 br label %for.body 191 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 203 204 for.end.loopexit: ; preds = %for.body 205 br label %for.end 206 207 for.end: ; preds = %for.end.loopexit, %entry 208 ret void 209 ; CHECK-LABEL: @bar6( 210 ; CHECK: call void @llvm.memset 211 ; CHECK-NOT: store 212 } 213