1; RUN: opt < %s -S -loop-unroll -unroll-runtime=true | FileCheck %s -check-prefix=EPILOG 2; RUN: opt < %s -S -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=false | FileCheck %s -check-prefix=PROLOG 3 4target 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-S128" 5 6; Tests for unrolling loops with run-time trip counts 7 8; EPILOG: %xtraiter = and i32 %n 9; EPILOG: %lcmp.mod = icmp ne i32 %xtraiter, 0 10; EPILOG: br i1 %lcmp.mod, label %for.body.epil.preheader, label %for.end.loopexit 11 12; PROLOG: %xtraiter = and i32 %n 13; PROLOG: %lcmp.mod = icmp ne i32 %xtraiter, 0 14; PROLOG: br i1 %lcmp.mod, label %for.body.prol.preheader, label %for.body.prol.loopexit 15 16; EPILOG: for.body.epil: 17; EPILOG: %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %for.body.epil ], [ %indvars.iv.unr, %for.body.epil.preheader ] 18; EPILOG: %epil.iter.sub = sub i32 %epil.iter, 1 19; EPILOG: %epil.iter.cmp = icmp ne i32 %epil.iter.sub, 0 20; EPILOG: br i1 %epil.iter.cmp, label %for.body.epil, label %for.end.loopexit.epilog-lcssa, !llvm.loop !0 21 22; PROLOG: for.body.prol: 23; PROLOG: %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %for.body.prol ], [ 0, %for.body.prol.preheader ] 24; PROLOG: %prol.iter.sub = sub i32 %prol.iter, 1 25; PROLOG: %prol.iter.cmp = icmp ne i32 %prol.iter.sub, 0 26; PROLOG: br i1 %prol.iter.cmp, label %for.body.prol, label %for.body.prol.loopexit, !llvm.loop !0 27 28 29define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly { 30entry: 31 %cmp1 = icmp eq i32 %n, 0 32 br i1 %cmp1, label %for.end, label %for.body 33 34for.body: ; preds = %for.body, %entry 35 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] 36 %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] 37 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 38 %0 = load i32, i32* %arrayidx, align 4 39 %add = add nsw i32 %0, %sum.02 40 %indvars.iv.next = add i64 %indvars.iv, 1 41 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 42 %exitcond = icmp eq i32 %lftr.wideiv, %n 43 br i1 %exitcond, label %for.end, label %for.body 44 45for.end: ; preds = %for.body, %entry 46 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ] 47 ret i32 %sum.0.lcssa 48} 49 50 51; Still try to completely unroll loops with compile-time trip counts 52; even if the -unroll-runtime is specified 53 54; EPILOG: for.body: 55; EPILOG-NOT: for.body.epil: 56 57; PROLOG: for.body: 58; PROLOG-NOT: for.body.prol: 59 60define i32 @test1(i32* nocapture %a) nounwind uwtable readonly { 61entry: 62 br label %for.body 63 64for.body: ; preds = %for.body, %entry 65 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 66 %sum.01 = phi i32 [ 0, %entry ], [ %add, %for.body ] 67 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 68 %0 = load i32, i32* %arrayidx, align 4 69 %add = add nsw i32 %0, %sum.01 70 %indvars.iv.next = add i64 %indvars.iv, 1 71 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 72 %exitcond = icmp eq i32 %lftr.wideiv, 5 73 br i1 %exitcond, label %for.end, label %for.body 74 75for.end: ; preds = %for.body 76 ret i32 %add 77} 78 79; This is test 2007-05-09-UnknownTripCount.ll which can be unrolled now 80; if the -unroll-runtime option is turned on 81 82; EPILOG: bb72.2: 83; PROLOG: bb72.2: 84 85define void @foo(i32 %trips) { 86entry: 87 br label %cond_true.outer 88 89cond_true.outer: 90 %indvar1.ph = phi i32 [ 0, %entry ], [ %indvar.next2, %bb72 ] 91 br label %bb72 92 93bb72: 94 %indvar.next2 = add i32 %indvar1.ph, 1 95 %exitcond3 = icmp eq i32 %indvar.next2, %trips 96 br i1 %exitcond3, label %cond_true138, label %cond_true.outer 97 98cond_true138: 99 ret void 100} 101 102 103; Test run-time unrolling for a loop that counts down by -2. 104 105; EPILOG: for.body.epil: 106; EPILOG: br i1 %epil.iter.cmp, label %for.body.epil, label %for.cond.for.end_crit_edge.epilog-lcssa 107 108; PROLOG: for.body.prol: 109; PROLOG: br i1 %prol.iter.cmp, label %for.body.prol, label %for.body.prol.loopexit 110 111define zeroext i16 @down(i16* nocapture %p, i32 %len) nounwind uwtable readonly { 112entry: 113 %cmp2 = icmp eq i32 %len, 0 114 br i1 %cmp2, label %for.end, label %for.body 115 116for.body: ; preds = %for.body, %entry 117 %p.addr.05 = phi i16* [ %incdec.ptr, %for.body ], [ %p, %entry ] 118 %len.addr.04 = phi i32 [ %sub, %for.body ], [ %len, %entry ] 119 %res.03 = phi i32 [ %add, %for.body ], [ 0, %entry ] 120 %incdec.ptr = getelementptr inbounds i16, i16* %p.addr.05, i64 1 121 %0 = load i16, i16* %p.addr.05, align 2 122 %conv = zext i16 %0 to i32 123 %add = add i32 %conv, %res.03 124 %sub = add nsw i32 %len.addr.04, -2 125 %cmp = icmp eq i32 %sub, 0 126 br i1 %cmp, label %for.cond.for.end_crit_edge, label %for.body 127 128for.cond.for.end_crit_edge: ; preds = %for.body 129 %phitmp = trunc i32 %add to i16 130 br label %for.end 131 132for.end: ; preds = %for.cond.for.end_crit_edge, %entry 133 %res.0.lcssa = phi i16 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ] 134 ret i16 %res.0.lcssa 135} 136 137; Test run-time unrolling disable metadata. 138; EPILOG: for.body: 139; EPILOG-NOT: for.body.epil: 140 141; PROLOG: for.body: 142; PROLOG-NOT: for.body.prol: 143 144define zeroext i16 @test2(i16* nocapture %p, i32 %len) nounwind uwtable readonly { 145entry: 146 %cmp2 = icmp eq i32 %len, 0 147 br i1 %cmp2, label %for.end, label %for.body 148 149for.body: ; preds = %for.body, %entry 150 %p.addr.05 = phi i16* [ %incdec.ptr, %for.body ], [ %p, %entry ] 151 %len.addr.04 = phi i32 [ %sub, %for.body ], [ %len, %entry ] 152 %res.03 = phi i32 [ %add, %for.body ], [ 0, %entry ] 153 %incdec.ptr = getelementptr inbounds i16, i16* %p.addr.05, i64 1 154 %0 = load i16, i16* %p.addr.05, align 2 155 %conv = zext i16 %0 to i32 156 %add = add i32 %conv, %res.03 157 %sub = add nsw i32 %len.addr.04, -2 158 %cmp = icmp eq i32 %sub, 0 159 br i1 %cmp, label %for.cond.for.end_crit_edge, label %for.body, !llvm.loop !0 160 161for.cond.for.end_crit_edge: ; preds = %for.body 162 %phitmp = trunc i32 %add to i16 163 br label %for.end 164 165for.end: ; preds = %for.cond.for.end_crit_edge, %entry 166 %res.0.lcssa = phi i16 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ] 167 ret i16 %res.0.lcssa 168} 169 170!0 = distinct !{!0, !1} 171!1 = !{!"llvm.loop.unroll.runtime.disable"} 172 173; EPILOG: !0 = distinct !{!0, !1} 174; EPILOG: !1 = !{!"llvm.loop.unroll.disable"} 175 176; PROLOG: !0 = distinct !{!0, !1} 177; PROLOG: !1 = !{!"llvm.loop.unroll.disable"} 178