1260679b0SDávid Bolvanský; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 248c6b272SRoman Lebedev; RUN: opt -passes=loop-idiom < %s -S | FileCheck %s 3cee313d2SEric Christophertarget 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" 4cee313d2SEric Christopher 5cee313d2SEric Christopher%struct.foo = type { i32, i32 } 6cee313d2SEric Christopher%struct.foo1 = type { i32, i32, i32 } 7cee313d2SEric Christopher%struct.foo2 = type { i32, i16, i16 } 8cee313d2SEric Christopher 9cee313d2SEric Christopher;void bar1(foo_t *f, unsigned n) { 10cee313d2SEric Christopher; for (unsigned i = 0; i < n; ++i) { 11cee313d2SEric Christopher; f[i].a = 0; 12cee313d2SEric Christopher; f[i].b = 0; 13cee313d2SEric Christopher; } 14cee313d2SEric Christopher;} 15*7a752e81SNikita Popovdefine void @bar1(ptr %f, i32 %n) nounwind ssp { 16260679b0SDávid Bolvanský; CHECK-LABEL: @bar1( 17260679b0SDávid Bolvanský; CHECK-NEXT: entry: 18260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 19260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]] 20260679b0SDávid Bolvanský; CHECK: for.body.preheader: 21260679b0SDávid Bolvanský; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i32 [[N]], 3 22*7a752e81SNikita Popov; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 4 [[F:%.*]], i8 0, i32 [[TMP0]], i1 false) 23260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_BODY:%.*]] 24260679b0SDávid Bolvanský; CHECK: for.body: 25260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 26*7a752e81SNikita Popov; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], ptr [[F]], i32 [[INDVARS_IV]], i32 0 27*7a752e81SNikita Popov; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO]], ptr [[F]], i32 [[INDVARS_IV]], i32 1 28260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1 29260679b0SDávid Bolvanský; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], [[N]] 30260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] 31260679b0SDávid Bolvanský; CHECK: for.end.loopexit: 32260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_END]] 33260679b0SDávid Bolvanský; CHECK: for.end: 34260679b0SDávid Bolvanský; CHECK-NEXT: ret void 35260679b0SDávid Bolvanský; 36cee313d2SEric Christopherentry: 37cee313d2SEric Christopher %cmp1 = icmp eq i32 %n, 0 38cee313d2SEric Christopher br i1 %cmp1, label %for.end, label %for.body.preheader 39cee313d2SEric Christopher 40cee313d2SEric Christopherfor.body.preheader: ; preds = %entry 41cee313d2SEric Christopher br label %for.body 42cee313d2SEric Christopher 43cee313d2SEric Christopherfor.body: ; preds = %for.body.preheader, %for.body 44cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 45*7a752e81SNikita Popov %a = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 0 46*7a752e81SNikita Popov store i32 0, ptr %a, align 4 47*7a752e81SNikita Popov %b = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 1 48*7a752e81SNikita Popov store i32 0, ptr %b, align 4 49cee313d2SEric Christopher %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 50cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, %n 51cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.end.loopexit 52cee313d2SEric Christopher 53cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.body 54cee313d2SEric Christopher br label %for.end 55cee313d2SEric Christopher 56cee313d2SEric Christopherfor.end: ; preds = %for.end.loopexit, %entry 57cee313d2SEric Christopher ret void 58cee313d2SEric Christopher} 59cee313d2SEric Christopher 60cee313d2SEric Christopher;void bar2(foo_t *f, unsigned n) { 61cee313d2SEric Christopher; for (unsigned i = 0; i < n; ++i) { 62cee313d2SEric Christopher; f[i].b = 0; 63cee313d2SEric Christopher; f[i].a = 0; 64cee313d2SEric Christopher; } 65cee313d2SEric Christopher;} 66*7a752e81SNikita Popovdefine void @bar2(ptr %f, i32 %n) nounwind ssp { 67260679b0SDávid Bolvanský; CHECK-LABEL: @bar2( 68260679b0SDávid Bolvanský; CHECK-NEXT: entry: 69260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 70260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]] 71260679b0SDávid Bolvanský; CHECK: for.body.preheader: 72260679b0SDávid Bolvanský; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i32 [[N]], 3 73*7a752e81SNikita Popov; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 4 [[F:%.*]], i8 0, i32 [[TMP0]], i1 false) 74260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_BODY:%.*]] 75260679b0SDávid Bolvanský; CHECK: for.body: 76260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 77*7a752e81SNikita Popov; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], ptr [[F]], i32 [[INDVARS_IV]], i32 1 78*7a752e81SNikita Popov; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO]], ptr [[F]], i32 [[INDVARS_IV]], i32 0 79260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1 80260679b0SDávid Bolvanský; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], [[N]] 81260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] 82260679b0SDávid Bolvanský; CHECK: for.end.loopexit: 83260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_END]] 84260679b0SDávid Bolvanský; CHECK: for.end: 85260679b0SDávid Bolvanský; CHECK-NEXT: ret void 86260679b0SDávid Bolvanský; 87cee313d2SEric Christopherentry: 88cee313d2SEric Christopher %cmp1 = icmp eq i32 %n, 0 89cee313d2SEric Christopher br i1 %cmp1, label %for.end, label %for.body.preheader 90cee313d2SEric Christopher 91cee313d2SEric Christopherfor.body.preheader: ; preds = %entry 92cee313d2SEric Christopher br label %for.body 93cee313d2SEric Christopher 94cee313d2SEric Christopherfor.body: ; preds = %for.body.preheader, %for.body 95cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 96*7a752e81SNikita Popov %b = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 1 97*7a752e81SNikita Popov store i32 0, ptr %b, align 4 98*7a752e81SNikita Popov %a = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 0 99*7a752e81SNikita Popov store i32 0, ptr %a, align 4 100cee313d2SEric Christopher %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 101cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, %n 102cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.end.loopexit 103cee313d2SEric Christopher 104cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.body 105cee313d2SEric Christopher br label %for.end 106cee313d2SEric Christopher 107cee313d2SEric Christopherfor.end: ; preds = %for.end.loopexit, %entry 108cee313d2SEric Christopher ret void 109cee313d2SEric Christopher} 110cee313d2SEric Christopher 111cee313d2SEric Christopher;void bar3(foo_t *f, unsigned n) { 112cee313d2SEric Christopher; for (unsigned i = n; i > 0; --i) { 113cee313d2SEric Christopher; f[i].a = 0; 114cee313d2SEric Christopher; f[i].b = 0; 115cee313d2SEric Christopher; } 116cee313d2SEric Christopher;} 117*7a752e81SNikita Popovdefine void @bar3(ptr nocapture %f, i32 %n) nounwind ssp { 118260679b0SDávid Bolvanský; CHECK-LABEL: @bar3( 119260679b0SDávid Bolvanský; CHECK-NEXT: entry: 120260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 121260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]] 122260679b0SDávid Bolvanský; CHECK: for.body.preheader: 123*7a752e81SNikita Popov; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr [[F:%.*]], i32 8 124260679b0SDávid Bolvanský; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i32 [[N]], 3 125*7a752e81SNikita Popov; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 4 [[UGLYGEP]], i8 0, i32 [[TMP0]], i1 false) 126260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_BODY:%.*]] 127260679b0SDávid Bolvanský; CHECK: for.body: 128260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[N]], [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 129*7a752e81SNikita Popov; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], ptr [[F]], i32 [[INDVARS_IV]], i32 0 130*7a752e81SNikita Popov; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO]], ptr [[F]], i32 [[INDVARS_IV]], i32 1 131260679b0SDávid Bolvanský; CHECK-NEXT: [[DEC:%.*]] = add i32 [[INDVARS_IV]], -1 132260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[DEC]], 0 133260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i32 [[INDVARS_IV]], -1 134260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]] 135260679b0SDávid Bolvanský; CHECK: for.end.loopexit: 136260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_END]] 137260679b0SDávid Bolvanský; CHECK: for.end: 138260679b0SDávid Bolvanský; CHECK-NEXT: ret void 139260679b0SDávid Bolvanský; 140cee313d2SEric Christopherentry: 141cee313d2SEric Christopher %cmp1 = icmp eq i32 %n, 0 142cee313d2SEric Christopher br i1 %cmp1, label %for.end, label %for.body.preheader 143cee313d2SEric Christopher 144cee313d2SEric Christopherfor.body.preheader: ; preds = %entry 145cee313d2SEric Christopher br label %for.body 146cee313d2SEric Christopher 147cee313d2SEric Christopherfor.body: ; preds = %for.body.preheader, %for.body 148cee313d2SEric Christopher %indvars.iv = phi i32 [ %n, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 149*7a752e81SNikita Popov %a = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 0 150*7a752e81SNikita Popov store i32 0, ptr %a, align 4 151*7a752e81SNikita Popov %b = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 1 152*7a752e81SNikita Popov store i32 0, ptr %b, align 4 153cee313d2SEric Christopher %dec = add i32 %indvars.iv, -1 154cee313d2SEric Christopher %cmp = icmp eq i32 %dec, 0 155cee313d2SEric Christopher %indvars.iv.next = add nsw i32 %indvars.iv, -1 156cee313d2SEric Christopher br i1 %cmp, label %for.end.loopexit, label %for.body 157cee313d2SEric Christopher 158cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.body 159cee313d2SEric Christopher br label %for.end 160cee313d2SEric Christopher 161cee313d2SEric Christopherfor.end: ; preds = %for.end.loopexit, %entry 162cee313d2SEric Christopher ret void 163cee313d2SEric Christopher} 164cee313d2SEric Christopher 165cee313d2SEric Christopher;void bar4(foo_t *f, unsigned n) { 166cee313d2SEric Christopher; for (unsigned i = 0; i < n; ++i) { 167cee313d2SEric Christopher; f[i].a = 0; 168cee313d2SEric Christopher; f[i].b = 1; 169cee313d2SEric Christopher; } 170cee313d2SEric Christopher;} 171*7a752e81SNikita Popovdefine void @bar4(ptr nocapture %f, i32 %n) nounwind ssp { 172260679b0SDávid Bolvanský; CHECK-LABEL: @bar4( 173260679b0SDávid Bolvanský; CHECK-NEXT: entry: 174260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 175260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]] 176260679b0SDávid Bolvanský; CHECK: for.body.preheader: 177260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_BODY:%.*]] 178260679b0SDávid Bolvanský; CHECK: for.body: 179260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 180*7a752e81SNikita Popov; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], ptr [[F:%.*]], i32 [[INDVARS_IV]], i32 0 181*7a752e81SNikita Popov; CHECK-NEXT: store i32 0, ptr [[A]], align 4 182*7a752e81SNikita Popov; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO]], ptr [[F]], i32 [[INDVARS_IV]], i32 1 183*7a752e81SNikita Popov; CHECK-NEXT: store i32 1, ptr [[B]], align 4 184260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1 185260679b0SDávid Bolvanský; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], [[N]] 186260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] 187260679b0SDávid Bolvanský; CHECK: for.end.loopexit: 188260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_END]] 189260679b0SDávid Bolvanský; CHECK: for.end: 190260679b0SDávid Bolvanský; CHECK-NEXT: ret void 191260679b0SDávid Bolvanský; 192cee313d2SEric Christopherentry: 193cee313d2SEric Christopher %cmp1 = icmp eq i32 %n, 0 194cee313d2SEric Christopher br i1 %cmp1, label %for.end, label %for.body.preheader 195cee313d2SEric Christopher 196cee313d2SEric Christopherfor.body.preheader: ; preds = %entry 197cee313d2SEric Christopher br label %for.body 198cee313d2SEric Christopher 199cee313d2SEric Christopherfor.body: ; preds = %for.body.preheader, %for.body 200cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 201*7a752e81SNikita Popov %a = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 0 202*7a752e81SNikita Popov store i32 0, ptr %a, align 4 203*7a752e81SNikita Popov %b = getelementptr inbounds %struct.foo, ptr %f, i32 %indvars.iv, i32 1 204*7a752e81SNikita Popov store i32 1, ptr %b, align 4 205cee313d2SEric Christopher %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 206cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, %n 207cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.end.loopexit 208cee313d2SEric Christopher 209cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.body 210cee313d2SEric Christopher br label %for.end 211cee313d2SEric Christopher 212cee313d2SEric Christopherfor.end: ; preds = %for.end.loopexit, %entry 213cee313d2SEric Christopher ret void 214cee313d2SEric Christopher} 215cee313d2SEric Christopher 216cee313d2SEric Christopher;void bar5(foo1_t *f, unsigned n) { 217cee313d2SEric Christopher; for (unsigned i = 0; i < n; ++i) { 218cee313d2SEric Christopher; f[i].a = 0; 219cee313d2SEric Christopher; f[i].b = 0; 220cee313d2SEric Christopher; } 221cee313d2SEric Christopher;} 222*7a752e81SNikita Popovdefine void @bar5(ptr nocapture %f, i32 %n) nounwind ssp { 223260679b0SDávid Bolvanský; CHECK-LABEL: @bar5( 224260679b0SDávid Bolvanský; CHECK-NEXT: entry: 225260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 226260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]] 227260679b0SDávid Bolvanský; CHECK: for.body.preheader: 228260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_BODY:%.*]] 229260679b0SDávid Bolvanský; CHECK: for.body: 230260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 231*7a752e81SNikita Popov; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO1:%.*]], ptr [[F:%.*]], i32 [[INDVARS_IV]], i32 0 232*7a752e81SNikita Popov; CHECK-NEXT: store i32 0, ptr [[A]], align 4 233*7a752e81SNikita Popov; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO1]], ptr [[F]], i32 [[INDVARS_IV]], i32 1 234*7a752e81SNikita Popov; CHECK-NEXT: store i32 0, ptr [[B]], align 4 235260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1 236260679b0SDávid Bolvanský; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], [[N]] 237260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] 238260679b0SDávid Bolvanský; CHECK: for.end.loopexit: 239260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_END]] 240260679b0SDávid Bolvanský; CHECK: for.end: 241260679b0SDávid Bolvanský; CHECK-NEXT: ret void 242260679b0SDávid Bolvanský; 243cee313d2SEric Christopherentry: 244cee313d2SEric Christopher %cmp1 = icmp eq i32 %n, 0 245cee313d2SEric Christopher br i1 %cmp1, label %for.end, label %for.body.preheader 246cee313d2SEric Christopher 247cee313d2SEric Christopherfor.body.preheader: ; preds = %entry 248cee313d2SEric Christopher br label %for.body 249cee313d2SEric Christopher 250cee313d2SEric Christopherfor.body: ; preds = %for.body.preheader, %for.body 251cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 252*7a752e81SNikita Popov %a = getelementptr inbounds %struct.foo1, ptr %f, i32 %indvars.iv, i32 0 253*7a752e81SNikita Popov store i32 0, ptr %a, align 4 254*7a752e81SNikita Popov %b = getelementptr inbounds %struct.foo1, ptr %f, i32 %indvars.iv, i32 1 255*7a752e81SNikita Popov store i32 0, ptr %b, align 4 256cee313d2SEric Christopher %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 257cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, %n 258cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.end.loopexit 259cee313d2SEric Christopher 260cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.body 261cee313d2SEric Christopher br label %for.end 262cee313d2SEric Christopher 263cee313d2SEric Christopherfor.end: ; preds = %for.end.loopexit, %entry 264cee313d2SEric Christopher ret void 265cee313d2SEric Christopher} 266cee313d2SEric Christopher 267cee313d2SEric Christopher;void bar6(foo2_t *f, unsigned n) { 268cee313d2SEric Christopher; for (unsigned i = 0; i < n; ++i) { 269cee313d2SEric Christopher; f[i].a = 0; 270cee313d2SEric Christopher; f[i].b = 0; 271cee313d2SEric Christopher; f[i].c = 0; 272cee313d2SEric Christopher; } 273cee313d2SEric Christopher;} 274*7a752e81SNikita Popovdefine void @bar6(ptr nocapture %f, i32 %n) nounwind ssp { 275260679b0SDávid Bolvanský; CHECK-LABEL: @bar6( 276260679b0SDávid Bolvanský; CHECK-NEXT: entry: 277260679b0SDávid Bolvanský; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 278260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]] 279260679b0SDávid Bolvanský; CHECK: for.body.preheader: 280260679b0SDávid Bolvanský; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i32 [[N]], 3 281*7a752e81SNikita Popov; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 4 [[F:%.*]], i8 0, i32 [[TMP0]], i1 false) 282260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_BODY:%.*]] 283260679b0SDávid Bolvanský; CHECK: for.body: 284260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] 285*7a752e81SNikita Popov; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[STRUCT_FOO2:%.*]], ptr [[F]], i32 [[INDVARS_IV]], i32 0 286*7a752e81SNikita Popov; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [[STRUCT_FOO2]], ptr [[F]], i32 [[INDVARS_IV]], i32 1 287*7a752e81SNikita Popov; CHECK-NEXT: [[C:%.*]] = getelementptr inbounds [[STRUCT_FOO2]], ptr [[F]], i32 [[INDVARS_IV]], i32 2 288260679b0SDávid Bolvanský; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1 289260679b0SDávid Bolvanský; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], [[N]] 290260679b0SDávid Bolvanský; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] 291260679b0SDávid Bolvanský; CHECK: for.end.loopexit: 292260679b0SDávid Bolvanský; CHECK-NEXT: br label [[FOR_END]] 293260679b0SDávid Bolvanský; CHECK: for.end: 294260679b0SDávid Bolvanský; CHECK-NEXT: ret void 295260679b0SDávid Bolvanský; 296cee313d2SEric Christopherentry: 297cee313d2SEric Christopher %cmp1 = icmp eq i32 %n, 0 298cee313d2SEric Christopher br i1 %cmp1, label %for.end, label %for.body.preheader 299cee313d2SEric Christopher 300cee313d2SEric Christopherfor.body.preheader: ; preds = %entry 301cee313d2SEric Christopher br label %for.body 302cee313d2SEric Christopher 303cee313d2SEric Christopherfor.body: ; preds = %for.body.preheader, %for.body 304cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 305*7a752e81SNikita Popov %a = getelementptr inbounds %struct.foo2, ptr %f, i32 %indvars.iv, i32 0 306*7a752e81SNikita Popov store i32 0, ptr %a, align 4 307*7a752e81SNikita Popov %b = getelementptr inbounds %struct.foo2, ptr %f, i32 %indvars.iv, i32 1 308*7a752e81SNikita Popov store i16 0, ptr %b, align 4 309*7a752e81SNikita Popov %c = getelementptr inbounds %struct.foo2, ptr %f, i32 %indvars.iv, i32 2 310*7a752e81SNikita Popov store i16 0, ptr %c, align 2 311cee313d2SEric Christopher %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 312cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, %n 313cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.end.loopexit 314cee313d2SEric Christopher 315cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.body 316cee313d2SEric Christopher br label %for.end 317cee313d2SEric Christopher 318cee313d2SEric Christopherfor.end: ; preds = %for.end.loopexit, %entry 319cee313d2SEric Christopher ret void 320cee313d2SEric Christopher} 321