summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authorEvgeniy Brevnov <evgueni.brevnov@gmail.com>2019-12-31 13:33:44 +0700
committerEvgeniy Brevnov <evgueni.brevnov@gmail.com>2020-01-09 16:49:15 +0700
commitf0abe820eebf47a3e9b9d0daf9f995d65db186bc (patch)
treeda9b403008b316c19f0ccfb9d009ec55d9aa28b8 /llvm/lib/Transforms/Utils
parent459ad8e97e07c823181cd457f2c2ac08f3896e37 (diff)
downloadbcm5719-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.cpp14
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,
OpenPOWER on IntegriCloud