Index: lib/Transforms/Utils/LoopUtils.cpp =================================================================== --- lib/Transforms/Utils/LoopUtils.cpp +++ lib/Transforms/Utils/LoopUtils.cpp @@ -1094,9 +1094,9 @@ return 0; // Divide the count of the backedge by the count of the edge exiting the loop, - // rounding to nearest. + // rounding to nearest. Trip count == backedge-taken count + 1. if (LatchBR->getSuccessor(0) == L->getHeader()) - return (TrueVal + (FalseVal / 2)) / FalseVal; + return (TrueVal + (FalseVal / 2)) / FalseVal + 1; else - return (FalseVal + (TrueVal / 2)) / TrueVal; + return (FalseVal + (TrueVal / 2)) / TrueVal + 1; }