Skip to content

Commit 1e0d3c6

Browse files
authored
LV: reuse getSmallBestKnownTC in a TC estimation (NFC) (#105834)
GeneratedRTChecks::getCost duplicates getSmallBestKnownTC partially, when attempting to get the best trip-count estimate. Since the intent of this code is to get the best trip-count estimate, and getSmallBestKnownTC is written for exactly this purpose, replace the partial code-duplication with a call to this function.
1 parent 1b7b3b8 commit 1e0d3c6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,11 @@ static bool hasIrregularType(Type *Ty, const DataLayout &DL) {
408408
/// the following procedure:
409409
/// 1) Returns exact trip count if it is known.
410410
/// 2) Returns expected trip count according to profile data if any.
411-
/// 3) Returns upper bound estimate if it is known.
411+
/// 3) Returns upper bound estimate if known, and if \p CanUseConstantMax.
412412
/// 4) Returns std::nullopt if all of the above failed.
413-
static std::optional<unsigned> getSmallBestKnownTC(ScalarEvolution &SE,
414-
Loop *L) {
413+
static std::optional<unsigned>
414+
getSmallBestKnownTC(ScalarEvolution &SE, Loop *L,
415+
bool CanUseConstantMax = true) {
415416
// Check if exact trip count is known.
416417
if (unsigned ExpectedTC = SE.getSmallConstantTripCount(L))
417418
return ExpectedTC;
@@ -421,6 +422,9 @@ static std::optional<unsigned> getSmallBestKnownTC(ScalarEvolution &SE,
421422
if (auto EstimatedTC = getLoopEstimatedTripCount(L))
422423
return *EstimatedTC;
423424

425+
if (!CanUseConstantMax)
426+
return std::nullopt;
427+
424428
// Check if upper bound estimate is known.
425429
if (unsigned ExpectedTC = SE.getSmallConstantMaxTripCount(L))
426430
return ExpectedTC;
@@ -1933,14 +1937,10 @@ class GeneratedRTChecks {
19331937
// count. Assume that the outer loop executes at least twice.
19341938
unsigned BestTripCount = 2;
19351939

1936-
// If exact trip count is known use that.
1937-
if (unsigned SmallTC = SE->getSmallConstantTripCount(OuterLoop))
1938-
BestTripCount = SmallTC;
1939-
else if (LoopVectorizeWithBlockFrequency) {
1940-
// Else use profile data if available.
1941-
if (auto EstimatedTC = getLoopEstimatedTripCount(OuterLoop))
1942-
BestTripCount = *EstimatedTC;
1943-
}
1940+
// Get the best known TC estimate.
1941+
if (auto EstimatedTC = getSmallBestKnownTC(
1942+
*SE, OuterLoop, /* CanUseConstantMax = */ false))
1943+
BestTripCount = *EstimatedTC;
19441944

19451945
BestTripCount = std::max(BestTripCount, 1U);
19461946
InstructionCost NewMemCheckCost = MemCheckCost / BestTripCount;

0 commit comments

Comments
 (0)