[PATCH] D73712: [SCEV] SCEVExpander::isHighCostExpansionHelper(): bailout if no TTI is present

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 30 07:45:43 PST 2020


lebedev.ri created this revision.
lebedev.ri added reviewers: reames, mkazantsev, wmi, sanjoy.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri added a parent revision: D73706: [NFC][SCEV] SCEVExpander::isHighCostExpansionHelper(): check that we processed expression first.

This appears to be NFC presently, but given we don't *require* non-null TTI to be passed this isn't generally NFC.
Future patch will start making use of TTI, and it would seem good to
just always say that the cost is too high when unable to perform
cost-modelling rather than saying that is is never too high.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73712

Files:
  llvm/lib/Analysis/ScalarEvolutionExpander.cpp


Index: llvm/lib/Analysis/ScalarEvolutionExpander.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -2145,13 +2145,20 @@
   // If we can find an existing value for this scev available at the point "At"
   // then consider the expression cheap.
   if (At && getRelatedExistingExpansion(S, At, L))
-    return false;
+    return false; // Consider the expression to be free.
 
-  // Zero/One operand expressions
   switch (S->getSCEVType()) {
   case scUnknown:
   case scConstant:
-    return false;
+    return false; // Assume to be zero-cost.
+  }
+
+  // The rest of the logic is recursive!
+  if (!TTI)
+    return true; // No cost model - give up.
+
+  // Zero/One operand expressions
+  switch (S->getSCEVType()) {
   case scTruncate:
     return isHighCostExpansionHelper(cast<SCEVTruncateExpr>(S)->getOperand(), L,
                                      At, BudgetRemaining, TTI, Processed);
@@ -2163,7 +2170,6 @@
                                      L, At, BudgetRemaining, TTI, Processed);
   }
 
-
   if (auto *UDivExpr = dyn_cast<SCEVUDivExpr>(S)) {
     // If the divisor is a power of two and the SCEV type fits in a native
     // integer (and the LHS not expensive), consider the division cheap


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73712.241453.patch
Type: text/x-patch
Size: 1335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200130/035a3c15/attachment.bin>


More information about the llvm-commits mailing list