117 lines · plain
1; Check that a loop probability of one (indicating an always infinite loop) does2; not crash or otherwise break LoopUnroll behavior when it tries to compute new3; probabilities from it.4;5; That case indicates an always infinite loop. A remainder loop cannot be6; calculated at run time when the original loop is infinite as infinity %7; UnrollCount is undefined, so consistent remainder loop probabilities are8; difficult or impossible to reason about. The implementation chooses9; probabilities indicating that all remainder loop iterations will always10; execute.11 12; DEFINE: %{unroll} = opt < %s -unroll-count=3 -passes=loop-unroll -S13; DEFINE: %{rt} = %{unroll} -unroll-runtime14 15; RUN: %{unroll} | FileCheck %s -check-prefix UNROLL16; RUN: %{rt} -unroll-runtime-epilog=true | FileCheck %s -check-prefix EPILOG17; RUN: %{rt} -unroll-runtime-epilog=false | FileCheck %s -check-prefix PROLOG18 19define void @test(i32 %n) {20entry:21 br label %loop22 23loop:24 %i = phi i32 [ 0, %entry ], [ %inc, %loop ]25 %inc = add i32 %i, 126 %c = icmp slt i32 %inc, %n27 br i1 %c, label %loop, label %end, !prof !028 29end:30 ret void31}32 33 34!0 = !{!"branch_weights", i32 1, i32 0}35 36; UNROLL: define void @test(i32 %n) {37; UNROLL: entry:38; UNROLL: br label %loop39; UNROLL: loop:40; UNROLL: br i1 %c, label %loop.1, label %end, !prof !041; UNROLL: loop.1:42; UNROLL: br i1 %c.1, label %loop.2, label %end, !prof !043; UNROLL: loop.2:44; UNROLL: br i1 %c.2, label %loop, label %end, !prof !0, !llvm.loop !145; UNROLL-NOT: loop.346; UNROLL: end:47; UNROLL: ret void48; UNROLL: }49;50; Infinite unrolled loop.51; UNROLL: !0 = !{!"branch_weights", i32 1, i32 0}52 53; EPILOG: define void @test(i32 %n) {54; EPILOG: entry:55; EPILOG: br i1 %{{.*}}, label %loop.epil.preheader, label %entry.new, !prof !056; EPILOG: entry.new:57; EPILOG: br label %loop58; EPILOG: loop:59; EPILOG: br i1 %{{.*}}, label %loop, label %end.unr-lcssa, !prof !160; EPILOG: end.unr-lcssa:61; EPILOG: br i1 %{{.*}}, label %loop.epil.preheader, label %end, !prof !162; EPILOG: loop.epil.preheader:63; EPILOG: br label %loop.epil64; EPILOG: loop.epil:65; EPILOG: br i1 %{{.*}}, label %loop.epil, label %end.epilog-lcssa, !prof !466; EPILOG: end.epilog-lcssa:67; EPILOG: br label %end68; EPILOG: end:69; EPILOG: ret void70; EPILOG: }71;72; Unrolled loop guard: Unrolled loop is always entered.73; EPILOG: !0 = !{!"branch_weights", i32 0, i32 -2147483648}74;75; Unrolled loop latch: Unrolled loop is infinite.76; Epilogue loop guard: Epilogue loop is always entered if unrolled loop exits.77; EPILOG: !1 = !{!"branch_weights", i32 -2147483648, i32 0}78;79; Epilogue loop latch: Epilogue loop executes both of its 2 iterations.80; EPILOG: !4 = !{!"branch_weights", i32 1073741824, i32 1073741824}81 82; PROLOG: define void @test(i32 %n) {83; PROLOG: entry:84; PROLOG: br i1 %{{.*}}, label %loop.prol.preheader, label %loop.prol.loopexit, !prof !085; PROLOG: loop.prol.preheader:86; PROLOG: br label %loop.prol87; PROLOG: loop.prol:88; PROLOG: br i1 %{{.*}}, label %loop.prol, label %loop.prol.loopexit.unr-lcssa, !prof !189; PROLOG: loop.prol.loopexit.unr-lcssa:90; PROLOG: br label %loop.prol.loopexit91; PROLOG: loop.prol.loopexit:92; PROLOG: br i1 %{{.*}}, label %end, label %entry.new, !prof !093; PROLOG: entry.new:94; PROLOG: br label %loop95; PROLOG: loop:96; PROLOG: br i1 %{{.*}}, label %loop, label %end.unr-lcssa, !prof !497; PROLOG: end.unr-lcssa:98; PROLOG: br label %end99; PROLOG: end:100; PROLOG: ret void101; PROLOG: }102;103; FIXME: Branch weights still need to be fixed in the case of prologues (issue104; #135812), so !0 and !1 do not yet match their comments below. When we do105; fix it, this test will hopefully catch any bug like issue #165998, which106; impacted the case of epilogues.107;108; Prologue loop guard: Prologue loop is always entered.109; Unrolled loop guard: Unrolled loop is always entered.110; PROLOG: !0 = !{!"branch_weights", i32 1, i32 127}111;112; Prologue loop latch: Prologue loop executes both of its 2 iterations.113; PROLOG: !1 = !{!"branch_weights", i32 0, i32 1}114;115; Unrolled loop latch: Unrolled loop is infinite.116; PROLOG: !4 = !{!"branch_weights", i32 1, i32 0}117