[llvm] fb14577 - [SCEV] Extract out a helper for computing trip multiples

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed May 26 10:15:18 PDT 2021


Author: Philip Reames
Date: 2021-05-26T10:15:03-07:00
New Revision: fb14577d0c4828f0e793072fc3e6bb3c57ec596e

URL: https://github.com/llvm/llvm-project/commit/fb14577d0c4828f0e793072fc3e6bb3c57ec596e
DIFF: https://github.com/llvm/llvm-project/commit/fb14577d0c4828f0e793072fc3e6bb3c57ec596e.diff

LOG: [SCEV] Extract out a helper for computing trip multiples

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ScalarEvolution.h
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index b423b01b8033..7aa540a5e402 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -727,6 +727,15 @@ class ScalarEvolution {
   /// Returns 0 if the trip count is unknown or not constant.
   unsigned getSmallConstantMaxTripCount(const Loop *L);
 
+  /// Returns the largest constant divisor of the trip count as a normal
+  /// unsigned value, if possible. This means that the actual trip count is
+  /// always a multiple of the returned value. Returns 1 if the trip count is
+  /// unknown or not guaranteed to be the multiple of a constant., Will also
+  /// return 1 if the trip count is very large (>= 2^32).
+  /// Note that the argument is an exit count for loop L, NOT a trip count.
+  unsigned getSmallConstantTripMultiple(const Loop *L,
+                                        const SCEV *ExitCount);
+
   /// Returns the largest constant divisor of the trip count of the
   /// loop if it is a single-exit loop and we can compute a small maximum for
   /// that loop.

diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index cf68317be425..5a2a4b8ddfe2 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6974,25 +6974,8 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L) {
   return 0;
 }
 
-/// Returns the largest constant divisor of the trip count of this loop as a
-/// normal unsigned value, if possible. This means that the actual trip count is
-/// always a multiple of the returned value (don't forget the trip count could
-/// very well be zero as well!).
-///
-/// Returns 1 if the trip count is unknown or not guaranteed to be the
-/// multiple of a constant (which is also the case if the trip count is simply
-/// constant, use getSmallConstantTripCount for that case), Will also return 1
-/// if the trip count is very large (>= 2^32).
-///
-/// As explained in the comments for getSmallConstantTripCount, this assumes
-/// that control exits the loop via ExitingBlock.
-unsigned
-ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
-                                              const BasicBlock *ExitingBlock) {
-  assert(ExitingBlock && "Must pass a non-null exiting block!");
-  assert(L->isLoopExiting(ExitingBlock) &&
-         "Exiting block must actually branch out of the loop!");
-  const SCEV *ExitCount = getExitCount(L, ExitingBlock);
+unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
+                                                       const SCEV *ExitCount) {
   if (ExitCount == getCouldNotCompute())
     return 1;
 
@@ -7019,6 +7002,28 @@ ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
   return (unsigned)Result->getZExtValue();
 }
 
+/// Returns the largest constant divisor of the trip count of this loop as a
+/// normal unsigned value, if possible. This means that the actual trip count is
+/// always a multiple of the returned value (don't forget the trip count could
+/// very well be zero as well!).
+///
+/// Returns 1 if the trip count is unknown or not guaranteed to be the
+/// multiple of a constant (which is also the case if the trip count is simply
+/// constant, use getSmallConstantTripCount for that case), Will also return 1
+/// if the trip count is very large (>= 2^32).
+///
+/// As explained in the comments for getSmallConstantTripCount, this assumes
+/// that control exits the loop via ExitingBlock.
+unsigned
+ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
+                                              const BasicBlock *ExitingBlock) {
+  assert(ExitingBlock && "Must pass a non-null exiting block!");
+  assert(L->isLoopExiting(ExitingBlock) &&
+         "Exiting block must actually branch out of the loop!");
+  const SCEV *ExitCount = getExitCount(L, ExitingBlock);
+  return getSmallConstantTripMultiple(L, ExitCount);
+}
+
 const SCEV *ScalarEvolution::getExitCount(const Loop *L,
                                           const BasicBlock *ExitingBlock,
                                           ExitCountKind Kind) {


        


More information about the llvm-commits mailing list