[llvm] [SCEV] Improve code around constant TC (NFC) (PR #133261)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 7 09:44:47 PDT 2025
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/133261
>From 9e7975150e1882c4a54761265596a0fca046a75f Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Thu, 27 Mar 2025 14:46:37 +0000
Subject: [PATCH 1/2] [SCEV] Improve code around constant TC (NFC)
---
llvm/lib/Analysis/ScalarEvolution.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 314baa7c7aee1..fc12128f73146 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8225,7 +8225,7 @@ static unsigned getConstantTripCount(const SCEVConstant *ExitCount) {
ConstantInt *ExitConst = ExitCount->getValue();
// Guard against huge trip counts.
- if (ExitConst->getValue().getActiveBits() > 32)
+ if (ExitConst->getValue().getActiveBits() > CHAR_BIT * sizeof(unsigned))
return 0;
// In case of integer overflow, this returns 0, which is correct.
@@ -8266,14 +8266,14 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L) {
unsigned Multiple = getSmallConstantTripMultiple(L, ExitingBB);
if (!Res)
Res = Multiple;
- Res = (unsigned)std::gcd(*Res, Multiple);
+ Res = std::gcd(*Res, Multiple);
}
return Res.value_or(1);
}
unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
const SCEV *ExitCount) {
- if (ExitCount == getCouldNotCompute())
+ if (isa<SCEVCouldNotCompute>(ExitCount))
return 1;
// Get the trip count
@@ -8283,8 +8283,8 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
// 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.
return Multiple.getActiveBits() > 32
- ? 1U << std::min((unsigned)31, Multiple.countTrailingZeros())
- : (unsigned)Multiple.zextOrTrunc(32).getZExtValue();
+ ? 1U << std::min(31U, Multiple.countTrailingZeros())
+ : (unsigned)Multiple.getZExtValue();
}
/// Returns the largest constant divisor of the trip count of this loop as a
>From 7ddee6165969cb73c8e8885b4e19a03c28c828fa Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Mon, 7 Apr 2025 17:43:47 +0100
Subject: [PATCH 2/2] [SCEV] Keep 32 (NFC)
---
llvm/lib/Analysis/ScalarEvolution.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index fc12128f73146..e028c663be526 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8225,7 +8225,7 @@ static unsigned getConstantTripCount(const SCEVConstant *ExitCount) {
ConstantInt *ExitConst = ExitCount->getValue();
// Guard against huge trip counts.
- if (ExitConst->getValue().getActiveBits() > CHAR_BIT * sizeof(unsigned))
+ if (ExitConst->getValue().getActiveBits() > 32)
return 0;
// In case of integer overflow, this returns 0, which is correct.
More information about the llvm-commits
mailing list