diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index a2e6c22236f98e..3094beeb5005c1 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -66,6 +66,7 @@ #include "llvm/Transforms/Utils/UnrollLoop.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include +#include #include #include @@ -440,6 +441,224 @@ static bool canHaveUnrollRemainder(const Loop *L) { return true; } +// If LoopUnroll has proven OriginalLoopProb is incorrect for some iterations +// of the original loop, adjust latch probabilities in the unrolled loop to +// maintain the original total frequency of the original loop body. +// +// OriginalLoopProb is practical but imprecise +// ------------------------------------------- +// +// The latch branch weights that LLVM originally adds to a loop encode one latch +// probability, OriginalLoopProb, applied uniformly across the loop's infinite +// set of theoretically possible iterations. While this uniform latch +// probability serves as a practical statistic summarizing the trip counts +// observed during profiling, it is imprecise. Specifically, unless it is zero, +// it is impossible for it to be the actual probability observed at every +// individual iteration. To see why, consider that the only way to actually +// observe at run time that the latch probability remains non-zero is to profile +// at least one loop execution that has an infinite number of iterations. I do +// not know how to profile an infinite number of loop iterations, and most loops +// I work with are always finite. +// +// LoopUnroll proves OriginalLoopProb is incorrect +// ------------------------------------------------ +// +// LoopUnroll reorganizes the original loop so that loop iterations are no +// longer all implemented by the same code, and then it analyzes some of those +// loop iteration implementations independently of others. In particular, it +// converts some of their conditional latches to unconditional. That is, by +// examining code structure without any profile data, LoopUnroll proves that the +// actual latch probability at the end of such an iteration is either 1 or 0. +// When an individual iteration's actual latch probability is 1 or 0, that means +// it always behaves the same, so it is impossible to observe it as having any +// other probability. The original uniform latch probability is rarely 1 or 0 +// because, when applied to all possible iterations, that would yield an +// estimated trip count of infinity or 1, respectively. +// +// Thus, the new probabilities of 1 or 0 are proven corrections to +// OriginalLoopProb for individual iterations in the original loop. However, +// LoopUnroll often is able to perform these corrections for only some +// iterations, leaving other iterations with OriginalLoopProb, and thus +// corrupting the aggregate effect on the total frequency of the original loop +// body. +// +// Adjusting latch probabilities +// ----------------------------- +// +// This function ensures that the total frequency of the original loop body, +// summed across all its occurrences in the unrolled loop after the +// aforementioned latch conversions, is the same as in the original loop. To do +// so, it adjusts probabilities on the remaining conditional latches. However, +// it cannot derive the new probabilities directly from the original uniform +// latch probability because the latter has been proven incorrect for some +// original loop iterations. +// +// There are often many sets of latch probabilities that can produce the +// original total loop body frequency. For now, this function computes uniform +// probabilities when the number of remaining conditional latches is <= 2 and +// does not handle other cases. +static void fixProbContradiction(UnrollLoopOptions ULO, + BranchProbability OriginalLoopProb, + bool CompletelyUnroll, + std::vector &IterCounts, + const std::vector &CondLatches, + std::vector &CondLatchNexts) { + // Runtime unrolling is handled later in LoopUnroll not here. + // + // There are two scenarios in which LoopUnroll sets ProbUpdateRequired to true + // because it needs to update probabilities that were originally + // OriginalLoopProb, but only in one scenario has LoopUnroll proven + // OriginalLoopProb incorrect for iterations within the original loop: + // - If ULO.Runtime, LoopUnroll adds new guards that enforce new reaching + // conditions for new loop iteration implementations (e.g., one unrolled + // loop iteration executes only if at least ULO.Count original loop + // iterations remain). Those reaching conditions dictate how conditional + // latches can be converted to unconditional (e.g., within an unrolled loop + // iteration, there is no need to recheck the number of remaining original + // loop iterations). None of this reorganization alters the set of possible + // original loop iteration counts or proves OriginalLoopProb incorrect for + // any of the original loop iterations. Thus, LoopUnroll derives + // probabilities for the new guards and latches directly from + // OriginalLoopProb based on the probabilities that their reaching + // conditions would occur in the original loop. Doing so maintains the + // total frequency of the original loop body. + // - If !ULO.Runtime, LoopUnroll initially adds new loop iteration + // implementations, which have the same latch probabilities as in the + // original loop because there are no new guards that change their reaching + // conditions. Sometimes, LoopUnroll is then done, and so does not set + // ProbUpdateRequired to true. Other times, LoopUnroll then proves that + // some latches are unconditional, directly contradicting OriginalLoopProb + // for the corresponding original loop iterations. That reduces the set of + // possible original loop iteration counts, possibly producing a finite set + // if it manages to eliminate the backedge. LoopUnroll has to choose a new + // set of latch probabilities that produce the same total loop body + // frequency. + // + // This function addresses the second scenario only. + if (ULO.Runtime) + return; + + // If CondLatches.empty(), there are no latch branches with probabilities we + // can adjust. That should mean that the actual trip count is always exactly + // the number of remaining unrolled iterations, and so OriginalLoopProb should + // have yielded that trip count as the original loop body frequency. Of + // course, OriginalLoopProb could be based on inaccurate profile data, but + // there is nothing we can do about that here. + if (CondLatches.empty()) + return; + + // If the original latch probability is 1, the original frequency is infinity. + // Leaving all remaining probabilities set to 1 might or might not get us + // there (e.g., a completely unrolled loop cannot be infinite), but it is the + // closest we can come. + assert(!OriginalLoopProb.isUnknown() && + "Expected to have loop probability to fix"); + if (OriginalLoopProb.isOne()) + return; + + // FreqDesired is the frequency implied by the original loop probability. + double FreqDesired = 1 / (1 - OriginalLoopProb.toDouble()); + + // Set the probability at CondLatches[I] to Prob. + auto SetProb = [&](unsigned I, double Prob) { + CondBrInst *B = cast(CondLatches[I]->getTerminator()); + bool FirstTargetIsNext = B->getSuccessor(0) == CondLatchNexts[I]; + setBranchProbability(B, BranchProbability::getBranchProbability(Prob), + FirstTargetIsNext); + }; + + // Set all probabilities in CondLatches to Prob. + auto SetAllProbs = [&](double Prob) { + for (unsigned I = 0, E = CondLatches.size(); I < E; ++I) + SetProb(I, Prob); + }; + + // If n <= 2, we choose the simplest probability model we can think of: every + // remaining conditional branch instruction has the same probability, Prob, + // of continuing to the next iteration. This model has several helpful + // properties: + // - We have no reason to think one latch branch's probability should be + // higher or lower than another, and so this model makes them all the same. + // In the worst cases, we thus avoid setting just some probabilities to 0 or + // 1, which can unrealistically make some code appear unreachable. There + // are cases where they *all* must become 0 or 1 to achieve the total + // frequency of original loop body, and our model does permit that. + // - The frequency, FreqOne, of the original loop body in a single iteration + // of the unrolled loop is computed by a simple polynomial, where p=Prob, + // n=CondLatches.size(), and c_i=IterCounts[i]: + // + // FreqOne = Sum(i=0..n)(c_i * p^i) + // + // - If the backedge has been eliminated, FreqOne is the total frequency of + // the original loop body in the unrolled loop. + // - If the backedge remains, Sum(i=0..inf)(FreqOne * p^(n*i)) = + // FreqOne / (1 - p^n) is the total frequency of the original loop body in + // the unrolled loop, regardless of whether the backedge is conditional or + // unconditional. + // - For n <= 2, we can use simple formulas to solve the above polynomial + // equations exactly for p without performing a search. + + // Compute the probability that, used at CondLaches[0] where + // CondLatches.size() == 1, gets as close as possible to FreqDesired. + auto ComputeProbForLinear = [&]() { + // The polynomial is linear (0 = A*p + B), so just solve it. + double A = IterCounts[1] + (CompletelyUnroll ? 0 : FreqDesired); + double B = IterCounts[0] - FreqDesired; + assert(A > 0 && "Expected iterations after last conditional latch"); + double Prob = -B / A; + Prob = std::max(Prob, 0.); + Prob = std::min(Prob, 1.); + return Prob; + }; + + // Compute the probability that, used throughout CondLatches where + // CondLatches.size() == 2, gets as close as possible to FreqDesired. + auto ComputeProbForQuadratic = [&]() { + // The polynomial is quadratic (0 = A*p^2 + B*p + C), so just solve it. + double A = IterCounts[2] + (CompletelyUnroll ? 0 : FreqDesired); + double B = IterCounts[1]; + double C = IterCounts[0] - FreqDesired; + assert(A > 0 && "Expected iterations after last conditional latch"); + double Prob = (-B + sqrt(B * B - 4 * A * C)) / (2 * A); + Prob = std::max(Prob, 0.); + Prob = std::min(Prob, 1.); + return Prob; + }; + + // Determine and set branch weights. + if (CondLatches.size() == 1) { + SetAllProbs(ComputeProbForLinear()); + } else if (CondLatches.size() == 2) { + SetAllProbs(ComputeProbForQuadratic()); + } else { + // FIXME: Handle CondLatches.size() > 2. + } + + // FIXME: We have not considered non-latch loop exits: + // - Their original probabilities are not considered in our calculation of + // FreqDesired. + // - Their probabilities are not considered in our probability model used to + // determine new probabilities for remaining conditional branches. + // - If they are conditional and LoopUnroll converts them to unconditional, + // LoopUnroll has proven their original probabilities are incorrect for some + // original loop iterations, but that does not cause ProbUpdateRequired to + // be set to true. + // + // To adjust FreqDesired and our probability model correctly for a non-latch + // loop exit, we would need to compute the original probability that the exit + // is reached from the loop header (in contrast, we currently assume that + // probability is 1 in the case of a latch exit) and the probability that the + // exit is taken if it is conditional (use the branch's old or new weights for + // FreqDesired or the probability model, respectively). Does computing the + // reaching probability require a CFG traversal, or is there some existing + // library that can do it? Prior discussions suggest some such libraries are + // difficult to use within LoopUnroll: + // . + // For now, we just let our corrected probabilities be less accurate in that + // scenario. Alternatively, we could refuse to correct probabilities at all + // in that scenario, but that seems worse. +} + /// Unroll the given loop by Count. The loop must be in LCSSA form. Unrolling /// can only fail when the loop's latch block is not terminated by a conditional /// branch instruction. However, if the trip count (and multiple) are not known, @@ -1121,6 +1340,12 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, } } + // Fix probabilities we contradicted above. + if (ProbUpdateRequired) { + fixProbContradiction(ULO, OriginalLoopProb, CompletelyUnroll, IterCounts, + CondLatches, CondLatchNexts); + } + // If there are partial reductions, create code in the exit block to compute // the final result and update users of the final result. if (!PartialReductions.empty()) { @@ -1187,8 +1412,7 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, // unrolled loop guard it creates. The branch weights for the unrolled // loop latch are adjusted below. FIXME: Handle prologue loops. // - Otherwise, if unrolled loop iteration latches become unconditional, - // branch weights are adjusted above. FIXME: Actually handle such - // unconditional latches. + // branch weights are adjusted by the fixProbContradiction call above. // - Otherwise, the original loop's branch weights are correct for the // unrolled loop, so do not adjust them. // - In all cases, the unrolled loop's estimated trip count is set below. diff --git a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-complete.ll b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-complete.ll index fd7df00515e25b..3d87ee185b554a 100644 --- a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-complete.ll +++ b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-complete.ll @@ -106,16 +106,14 @@ ; impossibly high. ; ORIG2310: - do.body: float = 3.0, ; UR2310: - do.body: float = 1.0, -; FIXME: Should be 1.0: -; UR2310: - do.body.1: float = 0.66667 +; UR2310: - do.body.1: float = 1.0, ; ; The sole probability is maximized to try to reach the original frequency. ; UR2310: call void @f ; UR2310: br i1 %{{.*}}, label %do.end, label %do.body.1, !prof !0 ; UR2310: call void @f ; UR2310: br label %do.end -; FIXME: Should be (0, non-zero): -; UR2310: !0 = !{!"branch_weights", i32 1, i32 2} +; UR2310: !0 = !{!"branch_weights", i32 0, i32 -2147483648} ; ; Now use a constant iteration count so that the sole non-final unrolled ; iteration's latch unconditionally continues. @@ -148,15 +146,13 @@ ; The sum of the new do.body* is the old do.body. ; ORIG2210: - do.body: float = 2.0, ; UR2210: - do.body: float = 1.0, -; FIXME: Should be 1.0: -; UR2210: - do.body.1: float = 0.5, +; UR2210: - do.body.1: float = 1.0, ; ; UR2210: call void @f ; UR2210: br i1 %{{.*}}, label %do.end, label %do.body.1, !prof !0 ; UR2210: call void @f ; UR2210: br label %do.end -; FIXME: Should be (0, non-zero): -; UR2210: !0 = !{!"branch_weights", i32 1, i32 1} +; UR2210: !0 = !{!"branch_weights", i32 0, i32 -2147483648} ; ; Now use a constant iteration count so that the sole non-final unrolled ; iteration's latch unconditionally continues. @@ -235,10 +231,8 @@ ; impossibly high. ; ORIG3410: - do.body: float = 4.0, ; UR3410: - do.body: float = 1.0, -; FIXME: Should be 1.0: -; UR3410: - do.body.1: float = 0.75, -; FIXME: Should be 1.0: -; UR3410: - do.body.2: float = 0.5625, +; UR3410: - do.body.1: float = 1.0, +; UR3410: - do.body.2: float = 1.0, ; ; The probabilities are maximized to try to reach the original frequency. ; UR3410: call void @f @@ -247,8 +241,7 @@ ; UR3410: br i1 %{{.*}}, label %do.end, label %do.body.2, !prof !0 ; UR3410: call void @f ; UR3410: br label %do.end -; FIXME: Should be (0, non-zero): -; UR3410: !0 = !{!"branch_weights", i32 1, i32 3} +; UR3410: !0 = !{!"branch_weights", i32 0, i32 -2147483648} ; ; Now use a constant iteration count so that all non-final unrolled ; iterations' latches unconditionally continue. @@ -284,8 +277,7 @@ ; old do.body, which is impossibly high. ; ORIG343x: - do.body: float = 4.0, ; UR343x: - do.body: float = 1.0, -; FIXME: Should be 1.0: -; UR343x: - do.body.1: float = 0.75, +; UR343x: - do.body.1: float = 1.0, ; ; The sole probability is maximized to try to reach the original frequency. ; UR343x: call void @f @@ -294,8 +286,7 @@ ; UR343x-NOT: br ; UR343x: call void @f ; UR343x: ret void -; FIXME: Should be (0, non-zero): -; UR343x: !0 = !{!"branch_weights", i32 1, i32 3} +; UR343x: !0 = !{!"branch_weights", i32 0, i32 -2147483648} ; ; Original loop body frequency is 3 (loop weight 2). ; @@ -310,10 +301,8 @@ ; The sum of the new do.body* is the old do.body. ; ORIG3310: - do.body: float = 3.0, ; UR3310: - do.body: float = 1.0, -; FIXME: Should be 1.0: -; UR3310: - do.body.1: float = 0.66667, -; FIXME: Should be 1.0: -; UR3310: - do.body.2: float = 0.44444, +; UR3310: - do.body.1: float = 1.0, +; UR3310: - do.body.2: float = 1.0, ; ; UR3310: call void @f ; UR3310: br i1 %{{.*}}, label %do.end, label %do.body.1, !prof !0 @@ -321,8 +310,7 @@ ; UR3310: br i1 %{{.*}}, label %do.end, label %do.body.2, !prof !0 ; UR3310: call void @f ; UR3310: br label %do.end -; FIXME: Should be (very small, very large): -; UR3310: !0 = !{!"branch_weights", i32 1, i32 2} +; UR3310: !0 = !{!"branch_weights", i32 1, i32 2147483647} ; ; Now use a constant iteration count so that all non-final unrolled ; iterations' latches unconditionally continue. @@ -357,8 +345,7 @@ ; multiply it by 2, and add the new do.body to get the old do.body. ; ORIG333x: - do.body: float = 3.0, ; UR333x: - do.body: float = 1.0, -; FIXME: Should be 1.0: -; UR333x: - do.body.1: float = 0.66667, +; UR333x: - do.body.1: float = 1.0, ; ; UR333x: call void @f ; UR333x: br i1 %{{.*}}, label %do.end, label %do.body.1, !prof !0 @@ -366,8 +353,7 @@ ; UR333x-NOT: br ; UR333x: call void @f ; UR333x: br label %do.end -; FIXME: Should be (very small, very large): -; UR333x: !0 = !{!"branch_weights", i32 1, i32 2} +; UR333x: !0 = !{!"branch_weights", i32 1, i32 2147483647} ; ; Original loop body frequency is 2 (loop weight 1). This is our first case ; where new frequencies and probabilities are not all approximately 1 or 0. @@ -383,9 +369,8 @@ ; The sum of the new do.body* is the old do.body. ; ORIG3210: - do.body: float = 2.0, ; UR3210: - do.body: float = 1.0, -; FIXME: Should sum to 1.0: -; UR3210: - do.body.1: float = 0.5, -; UR3210: - do.body.2: float = 0.25, +; UR3210: - do.body.1: float = 0.61803, +; UR3210: - do.body.2: float = 0.38197, ; ; UR3210: call void @f ; UR3210: br i1 %{{.*}}, label %do.end, label %do.body.1, !prof !0 @@ -393,7 +378,7 @@ ; UR3210: br i1 %{{.*}}, label %do.end, label %do.body.2, !prof !0 ; UR3210: call void @f ; UR3210: br label %do.end -; UR3210: !0 = !{!"branch_weights", i32 1, i32 1} +; UR3210: !0 = !{!"branch_weights", i32 820265763, i32 1327217885} ; ; Now use a constant iteration count so that all non-final unrolled ; iterations' latches unconditionally continue. @@ -436,7 +421,7 @@ ; UR323x-NOT: br ; UR323x: call void @f ; UR323x: br label %do.end -; UR323x: !0 = !{!"branch_weights", i32 1, i32 1} +; UR323x: !0 = !{!"branch_weights", i32 1073741824, i32 1073741824} ; ; Original loop body frequency is 1 (loop weight 0). ; @@ -504,7 +489,7 @@ ; UR313x-NOT: br ; UR313x: call void @f ; UR313x: br label %do.end -; UR313x: !0 = !{!"branch_weights", i32 1, i32 0} +; UR313x: !0 = !{!"branch_weights", i32 -2147483648, i32 0} declare void @f(i32) diff --git a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-epilog.ll b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-epilog.ll index 8b5a88bd6e8cda..09ecaebcf1f459 100644 --- a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-epilog.ll +++ b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-epilog.ll @@ -95,10 +95,9 @@ ; original loop body frequency, 11. ; UR4: - do.body: float = 2.3702, ; UR4-ELP: - do.body.epil: float = 1.5193, -; FIXME: Should sum to 1.5193: ; UR4-EUR: - do.body.epil: float = 0.78453, -; UR4-EUR: - do.body.epil.1: float = 0.37941, -; UR4-EUR: - do.body.epil.2: float = 0.18349, +; UR4-EUR: - do.body.epil.1: float = 0.46232, +; UR4-EUR: - do.body.epil.2: float = 0.27244, ; ; Unrolled loop guard, body, and latch. ; UR4: br i1 %{{.*}}, label %do.body.epil.preheader, label %entry.new, !prof !0 @@ -137,7 +136,7 @@ ; to the non-unrolled case. There are only two, so the implementation can ; compute uniform branch weights using the quadratic formula. ; - It has no llvm.loop.estimated_trip_count. -; UR4-EUR: !6 = !{!"branch_weights", i32 1038564635, i32 1108919013} +; UR4-EUR: !6 = !{!"branch_weights", i32 1265493781, i32 881989867} ; ------------------------------------------------------------------------------ ; Check -unroll-count=10. diff --git a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-partial-unconditional-latch.ll b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-partial-unconditional-latch.ll index dafb2a3ca4ed96..09b2097d13582e 100644 --- a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-partial-unconditional-latch.ll +++ b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-partial-unconditional-latch.ll @@ -95,8 +95,7 @@ ; RUN: %{ur-bf} -unroll-count=2 | %{fc} MULT2 ; ; Multiply by 2 to get the original loop body frequency, 10. -; FIXME: Should sum to 5.0: -; MULT2: - do.body: float = 10.0, +; MULT2: - do.body: float = 5.0, ; ; MULT2: call void @f ; MULT2-NOT: br @@ -105,8 +104,7 @@ ; ; The branch weights imply the estimated trip count is ; (1717986918+429496730)/429496730 = approximately (8+2)/2 = 5. -; FIXME: Or at least they should. -; MULT2: !0 = !{!"branch_weights", i32 9, i32 1} +; MULT2: !0 = !{!"branch_weights", i32 1717986918, i32 429496730} ; MULT2: !1 = distinct !{!1, !2, !3} ; MULT2: !2 = !{!"llvm.loop.estimated_trip_count", i32 5} ; MULT2: !3 = !{!"llvm.loop.unroll.disable"} @@ -117,9 +115,8 @@ ; RUN: %{ur-bf} -unroll-count=4 | %{fc} MULT4 ; ; Multiply by 2 and sum to get the original loop body frequency, 10. -; FIXME: Should sum to 5.0: -; MULT4: - do.body: float = 5.2632, -; MULT4: - do.body.2: float = 4.7368, +; MULT4: - do.body: float = 2.7778, +; MULT4: - do.body.2: float = 2.2222, ; ; MULT4: call void @f ; MULT4-NOT: br @@ -132,7 +129,7 @@ ; ; MULT4 is like applying -unroll-count=2 to MULT2 without converting any ; more conditional latches to unconditional, so MULT2's branch weights work. -; MULT4: !0 = !{!"branch_weights", i32 9, i32 1} +; MULT4: !0 = !{!"branch_weights", i32 1717986918, i32 429496730} ; MULT4: !1 = distinct !{!1, !2, !3} ; MULT4: !2 = !{!"llvm.loop.estimated_trip_count", i32 3} ; MULT4: !3 = !{!"llvm.loop.unroll.disable"} @@ -167,7 +164,7 @@ ; LOW2: call void @f ; LOW2: br i1 %{{.*}}, label %do.body, label %do.end, !prof !0, !llvm.loop !1{{$}} ; -; LOW2: !0 = !{!"branch_weights", i32 0, i32 1} +; LOW2: !0 = !{!"branch_weights", i32 0, i32 -2147483648} ; LOW2: !1 = distinct !{!1, !2, !3} ; LOW2: !2 = !{!"llvm.loop.estimated_trip_count", i32 1} ; LOW2: !3 = !{!"llvm.loop.unroll.disable"} @@ -192,7 +189,7 @@ ; LOW4: call void @f ; LOW4: br i1 %{{.*}}, label %do.body, label %do.end, !prof !0, !llvm.loop !1 ; -; LOW4: !0 = !{!"branch_weights", i32 0, i32 1} +; LOW4: !0 = !{!"branch_weights", i32 0, i32 -2147483648} ; LOW4: !1 = distinct !{!1, !2, !3} ; LOW4: !2 = !{!"llvm.loop.estimated_trip_count", i32 1} ; LOW4: !3 = !{!"llvm.loop.unroll.disable"} @@ -218,8 +215,7 @@ ; RUN: %{ur-bf} -unroll-count=2 | %{fc} CONST2 ; ; Multiply by 2 to get the original loop body frequency, 10. -; FIXME: Should be 5.0: -; CONST2: - do.body: float = 10.0, +; CONST2: - do.body: float = 5.0, ; ; CONST2: call void @f ; CONST2-NOT: br: @@ -227,7 +223,7 @@ ; CONST2: br i1 %{{.*}}, label %do.body, label %do.end, !prof !0, !llvm.loop !1 ; ; Like MULT2. -; CONST2: !0 = !{!"branch_weights", i32 9, i32 1} +; CONST2: !0 = !{!"branch_weights", i32 1717986918, i32 429496730} ; CONST2: !1 = distinct !{!1, !2, !3} ; CONST2: !2 = !{!"llvm.loop.estimated_trip_count", i32 5} ; CONST2: !3 = !{!"llvm.loop.unroll.disable"} @@ -237,9 +233,8 @@ ; RUN: %{ur-bf} -unroll-count=4 | %{fc} CONST4 ; ; Multiply by 2 and sum to get the original loop body frequency, 10. -; FIXME: Should sum to 5.0: -; CONST4: - do.body: float = 10.0, -; CONST4: - do.body.2: float = 9.0, +; CONST4: - do.body: float = 3.0, +; CONST4: - do.body.2: float = 2.0, ; ; CONST4: call void @f ; CONST4-NOT: br @@ -254,7 +249,7 @@ ; in do.body.2 unconditionally continues. The branch weights on do.body's ; branch imply do.body continues twice and then exits once, thus executing the ; original loop body 10 times. -; CONST4: !0 = !{!"branch_weights", i32 9, i32 1} +; CONST4: !0 = !{!"branch_weights", i32 1431655765, i32 715827883} ; CONST4: !1 = distinct !{!1, !2} ; CONST4: !2 = !{!"llvm.loop.unroll.disable"}