[PATCH] D105113: [LV] Do cost comparison on InstructionCost directly.

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 29 06:19:36 PDT 2021


sdesmalen created this revision.
Herald added subscribers: dexonsmith, hiraditya.
sdesmalen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Instead of performing the isMoreProfitable() operation on
InstructionCost::CostTy the operation is performed on InstructionCost
directly, so that it can handle the case where one of the costs is
Invalid.

This patch also changes the CostTy to be int64_t, so that the type is
wide enough to deal with multiplications with e.g. `unsigned MaxTripCount`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105113

Files:
  llvm/include/llvm/Support/InstructionCost.h
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp


Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6020,8 +6020,8 @@
 
 bool LoopVectorizationCostModel::isMoreProfitable(
     const VectorizationFactor &A, const VectorizationFactor &B) const {
-  InstructionCost::CostType CostA = *A.Cost.getValue();
-  InstructionCost::CostType CostB = *B.Cost.getValue();
+  InstructionCost CostA = A.Cost;
+  InstructionCost CostB = B.Cost;
 
   unsigned MaxTripCount = PSE.getSE()->getSmallConstantMaxTripCount(TheLoop);
 
@@ -6034,8 +6034,8 @@
     // be PerIterationCost*floor(TC/VF) + Scalar remainder cost, and so is
     // approximated with the per-lane cost below instead of using the tripcount
     // as here.
-    int64_t RTCostA = CostA * divideCeil(MaxTripCount, A.Width.getFixedValue());
-    int64_t RTCostB = CostB * divideCeil(MaxTripCount, B.Width.getFixedValue());
+    auto RTCostA = CostA * divideCeil(MaxTripCount, A.Width.getFixedValue());
+    auto RTCostB = CostB * divideCeil(MaxTripCount, B.Width.getFixedValue());
     return RTCostA < RTCostB;
   }
 
@@ -6595,7 +6595,7 @@
 
   // A lambda that gets the register usage for the given type and VF.
   const auto &TTICapture = TTI;
-  auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) {
+  auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) -> int64_t {
     if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty))
       return 0;
     return *TTICapture.getRegUsageForType(VectorType::get(Ty, VF)).getValue();
Index: llvm/include/llvm/Support/InstructionCost.h
===================================================================
--- llvm/include/llvm/Support/InstructionCost.h
+++ llvm/include/llvm/Support/InstructionCost.h
@@ -27,7 +27,7 @@
 
 class InstructionCost {
 public:
-  using CostType = int;
+  using CostType = int64_t;
 
   /// These states can currently be used to indicate whether a cost is valid or
   /// invalid. Examples of an invalid cost might be where the cost is


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105113.355207.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210629/5ba15bf0/attachment.bin>


More information about the llvm-commits mailing list