1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[LoopUtils][NFC] Minor refactoring in getLoopEstimatedTripCount.

This commit is contained in:
Evgeniy Brevnov 2019-12-31 13:33:44 +07:00
parent ea4efaf94d
commit a8c4082764
2 changed files with 12 additions and 7 deletions

View File

@ -732,6 +732,11 @@ inline uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) {
return alignTo(Numerator, Denominator) / Denominator; return alignTo(Numerator, Denominator) / Denominator;
} }
/// Returns the integer nearest(Numerator / Denominator).
inline uint64_t divideNearest(uint64_t Numerator, uint64_t Denominator) {
return (Numerator + (Denominator / 2)) / Denominator;
}
/// Returns the largest uint64_t less than or equal to \p Value and is /// Returns the largest uint64_t less than or equal to \p Value and is
/// \p Skew mod \p Align. \p Align must be non-zero /// \p Skew mod \p Align. \p Align must be non-zero
inline uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { inline uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew = 0) {

View File

@ -714,19 +714,19 @@ Optional<unsigned> llvm::getLoopEstimatedTripCount(Loop *L) {
// To estimate the number of times the loop body was executed, we want to // To estimate the number of times the loop body was executed, we want to
// know the number of times the backedge was taken, vs. the number of times // know the number of times the backedge was taken, vs. the number of times
// we exited the loop. // we exited the loop.
uint64_t TrueVal, FalseVal; uint64_t BackedgeTakenWeight, LatchExitWeight;
if (!LatchBR->extractProfMetadata(TrueVal, FalseVal)) if (!LatchBR->extractProfMetadata(BackedgeTakenWeight, LatchExitWeight))
return None; return None;
if (!TrueVal || !FalseVal) if (LatchBR->getSuccessor(0) != L->getHeader())
std::swap(BackedgeTakenWeight, LatchExitWeight);
if (!BackedgeTakenWeight || !LatchExitWeight)
return 0; return 0;
// Divide the count of the backedge by the count of the edge exiting the loop, // Divide the count of the backedge by the count of the edge exiting the loop,
// rounding to nearest. // rounding to nearest.
if (LatchBR->getSuccessor(0) == L->getHeader()) return llvm::divideNearest(BackedgeTakenWeight, LatchExitWeight);
return (TrueVal + (FalseVal / 2)) / FalseVal;
else
return (FalseVal + (TrueVal / 2)) / TrueVal;
} }
bool llvm::hasIterationCountInvariantInParent(Loop *InnerLoop, bool llvm::hasIterationCountInvariantInParent(Loop *InnerLoop,