[llvm] b27f14d - [SCEV][NFC-mostly] Remove constant handling in TripMultiple computation
Joshua Cao via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 20:56:31 PDT 2023
Author: Joshua Cao
Date: 2023-05-16T20:24:31-07:00
New Revision: b27f14d920e17d0216bba1dd1d051137627ab356
URL: https://github.com/llvm/llvm-project/commit/b27f14d920e17d0216bba1dd1d051137627ab356
DIFF: https://github.com/llvm/llvm-project/commit/b27f14d920e17d0216bba1dd1d051137627ab356.diff
LOG: [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
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 81f075825ee7..5f9b506ae398 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
More information about the llvm-commits
mailing list