[PATCH] D150541: [SCEV][NFC-mostly] Remove constant handling in TripMultiple computation

Joshua Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 00:05:34 PDT 2023


caojoshua created this revision.
Herald added subscribers: javed.absar, hiraditya.
Herald added a project: All.
caojoshua added reviewers: nikic, mkazantsev.
Herald added a subscriber: StephenFan.
caojoshua added a reviewer: fhahn.
caojoshua updated this revision to Diff 522063.
caojoshua edited the summary of this revision.
caojoshua added a comment.
caojoshua published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

update commit message


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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150541

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp


Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8335,29 +8335,12 @@
   // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150541.522063.patch
Type: text/x-patch
Size: 1554 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/189c3875/attachment.bin>


More information about the llvm-commits mailing list