[PATCH] D33914: LSR: Calculate instruction cost only if InsnsCost is set to true (NFC)

Evgeny Stupachenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 5 14:52:47 PDT 2017


evstupac created this revision.
Herald added a subscriber: mzolotukhin.

The patch supports https://reviews.llvm.org/D30561 and https://reviews.llvm.org/D30562.
The patch guard all instruction cost calculations with InsnCosts (-lsr-insns-cost) option.
Currently even if the option set to false we calculate and print (in debug mode) instruction costs.

The patch is NFC and I'm going to commit it today.


Repository:
  rL LLVM

https://reviews.llvm.org/D33914

Files:
  lib/Transforms/Scalar/LoopStrengthReduce.cpp


Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1251,18 +1251,6 @@
       return;
   }
 
-  // Treat every new register that exceeds TTI.getNumberOfRegisters() - 1 as
-  // additional instruction (at least fill).
-  unsigned TTIRegNum = TTI.getNumberOfRegisters(false) - 1;
-  if (NumRegs > TTIRegNum) {
-    // Cost already exceeded TTIRegNum, then only newly added register can add
-    // new instructions.
-    if (PrevNumRegs > TTIRegNum)
-      Insns += (NumRegs - PrevNumRegs);
-    else
-      Insns += (NumRegs - TTIRegNum);
-  }
-
   // Determine how many (unfolded) adds we'll need inside the loop.
   size_t NumBaseParts = F.getNumRegs();
   if (NumBaseParts > 1)
@@ -1292,6 +1280,24 @@
       NumBaseAdds++;
   }
 
+  // If we don't count instruction cost exit here.
+  if (!InsnsCost) {
+    assert(isValid() && "invalid cost");
+    return;
+  }
+
+  // Treat every new register that exceeds TTI.getNumberOfRegisters() - 1 as
+  // additional instruction (at least fill).
+  unsigned TTIRegNum = TTI.getNumberOfRegisters(false) - 1;
+  if (NumRegs > TTIRegNum) {
+    // Cost already exceeded TTIRegNum, then only newly added register can add
+    // new instructions.
+    if (PrevNumRegs > TTIRegNum)
+      Insns += (NumRegs - PrevNumRegs);
+    else
+      Insns += (NumRegs - TTIRegNum);
+  }
+
   // If ICmpZero formula ends with not 0, it could not be replaced by
   // just add or sub. We'll need to compare final result of AddRec.
   // That means we'll need an additional instruction.
@@ -1326,7 +1332,7 @@
 
 /// Choose the lower cost.
 bool Cost::operator<(const Cost &Other) const {
-  if (InsnsCost && Insns != Other.Insns)
+  if (InsnsCost.getNumOccurrences() > 0 && InsnsCost && Insns != Other.Insns)
     return Insns < Other.Insns;
   return std::tie(NumRegs, AddRecCost, NumIVMuls, NumBaseAdds, ScaleCost,
                   ImmCost, SetupCost) <
@@ -1336,7 +1342,8 @@
 }
 
 void Cost::print(raw_ostream &OS) const {
-  OS << Insns << " instruction" << (Insns == 1 ? " " : "s ");
+  if (InsnsCost)
+    OS << Insns << " instruction" << (Insns == 1 ? " " : "s ");
   OS << NumRegs << " reg" << (NumRegs == 1 ? "" : "s");
   if (AddRecCost != 0)
     OS << ", with addrec cost " << AddRecCost;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33914.101460.patch
Type: text/x-patch
Size: 2400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170605/f1fbb1af/attachment.bin>


More information about the llvm-commits mailing list