diff options
author | Joshua Cao <cao.joshua@yahoo.com> | 2023-05-14 23:53:45 -0700 |
---|---|---|
committer | Joshua Cao <cao.joshua@yahoo.com> | 2023-05-16 20:24:31 -0700 |
commit | b27f14d920e17d0216bba1dd1d051137627ab356 (patch) | |
tree | 993ab9704f27f9ba9fdc410ef740e4a70e51ac19 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | cae7ef260458f66b4c6b2b8075db7cb6afe6bf9e (diff) | |
download | llvm-b27f14d920e17d0216bba1dd1d051137627ab356.zip llvm-b27f14d920e17d0216bba1dd1d051137627ab356.tar.gz llvm-b27f14d920e17d0216bba1dd1d051137627ab356.tar.bz2 |
[SCEV][NFC-mostly] Remove constant handling in TripMultiple computation
After landing more precise trip multiples in
https://reviews.llvm.org/D149529, the SCEV multiple computation handles
constants, so there is no longer any need for special constant handling
in getSmallConstantTripMultiple.
This patch can improve the multiple of a non-constant SCEV that is huge
(>=2**32). This is very rare in practice.
Differential Revision: https://reviews.llvm.org/D150541
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 81f0758..5f9b506 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8335,29 +8335,12 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L, // Get the trip count const SCEV *TCExpr = getTripCountFromExitCount(applyLoopGuards(ExitCount, L)); + APInt Multiple = getNonZeroConstantMultiple(TCExpr); // If a trip multiple is huge (>=2^32), the trip count is still divisible by // the greatest power of 2 divisor less than 2^32. - auto GetSmallMultiple = [](unsigned TrailingZeros) { - return 1U << std::min((uint32_t)31, TrailingZeros); - }; - - const SCEVConstant *TC = dyn_cast<SCEVConstant>(TCExpr); - if (!TC) { - APInt Multiple = getNonZeroConstantMultiple(TCExpr); - return Multiple.getActiveBits() > 32 - ? 1 - : Multiple.zextOrTrunc(32).getZExtValue(); - } - - ConstantInt *Result = TC->getValue(); - assert(Result && "SCEVConstant expected to have non-null ConstantInt"); - assert(Result->getValue() != 0 && "trip count should never be zero"); - - // Guard against huge trip multiples. - if (Result->getValue().getActiveBits() > 32) - return GetSmallMultiple(Result->getValue().countTrailingZeros()); - - return (unsigned)Result->getZExtValue(); + return Multiple.getActiveBits() > 32 + ? 1U << std::min((uint32_t)31, Multiple.countTrailingZeros()) + : Multiple.zextOrTrunc(32).getZExtValue(); } /// Returns the largest constant divisor of the trip count of this loop as a |