diff options
author | Evgeniy Brevnov <evgueni.brevnov@gmail.com> | 2019-12-31 13:33:44 +0700 |
---|---|---|
committer | Evgeniy Brevnov <evgueni.brevnov@gmail.com> | 2020-01-09 16:49:15 +0700 |
commit | f0abe820eebf47a3e9b9d0daf9f995d65db186bc (patch) | |
tree | da9b403008b316c19f0ccfb9d009ec55d9aa28b8 /llvm/lib/Transforms/Utils | |
parent | 459ad8e97e07c823181cd457f2c2ac08f3896e37 (diff) | |
download | bcm5719-llvm-f0abe820eebf47a3e9b9d0daf9f995d65db186bc.tar.gz bcm5719-llvm-f0abe820eebf47a3e9b9d0daf9f995d65db186bc.zip |
[LoopUtils][NFC] Minor refactoring in getLoopEstimatedTripCount.
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index b7dd3d75e45..c4c40189fda 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -714,19 +714,19 @@ Optional<unsigned> llvm::getLoopEstimatedTripCount(Loop *L) { // 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 // we exited the loop. - uint64_t TrueVal, FalseVal; - if (!LatchBR->extractProfMetadata(TrueVal, FalseVal)) + uint64_t BackedgeTakenWeight, LatchExitWeight; + if (!LatchBR->extractProfMetadata(BackedgeTakenWeight, LatchExitWeight)) return None; - if (!TrueVal || !FalseVal) + if (LatchBR->getSuccessor(0) != L->getHeader()) + std::swap(BackedgeTakenWeight, LatchExitWeight); + + if (!BackedgeTakenWeight || !LatchExitWeight) return 0; // Divide the count of the backedge by the count of the edge exiting the loop, // rounding to nearest. - if (LatchBR->getSuccessor(0) == L->getHeader()) - return (TrueVal + (FalseVal / 2)) / FalseVal; - else - return (FalseVal + (TrueVal / 2)) / TrueVal; + return llvm::divideNearest(BackedgeTakenWeight, LatchExitWeight); } bool llvm::hasIterationCountInvariantInParent(Loop *InnerLoop, |