[NFC][SCEV] SCEVExpander::isHighCostExpansionHelper(): check that we processed expres...
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 25 Feb 2020 18:51:06 +0000 (21:51 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 25 Feb 2020 20:05:57 +0000 (23:05 +0300)
Summary:
As far as i can tell this is still NFC.
Initially in rL146438 it was added at the top of the function,
later rL238507 dethroned it, and rL244474 did it again.

I'm not sure if we have already checked the cost of this expansion, we should be doing that again.

Reviewers: reames, mkazantsev, wmi, sanjoy, atrick, igor-laevsky

Reviewed By: mkazantsev

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73706

llvm/lib/Analysis/ScalarEvolutionExpander.cpp

index 146db09..e8f267a 100644 (file)
@@ -2138,6 +2138,10 @@ SCEVExpander::getRelatedExistingExpansion(const SCEV *S, const Instruction *At,
 bool SCEVExpander::isHighCostExpansionHelper(
     const SCEV *S, Loop *L, const Instruction *At, int &BudgetRemaining,
     const TargetTransformInfo *TTI, SmallPtrSetImpl<const SCEV *> &Processed) {
+  // Was the cost of expansion of this expression already accounted for?
+  if (!Processed.insert(S).second)
+    return false; // We have already accounted for this expression.
+
   // 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))
@@ -2159,8 +2163,6 @@ bool SCEVExpander::isHighCostExpansionHelper(
                                      L, At, BudgetRemaining, TTI, Processed);
   }
 
-  if (!Processed.insert(S).second)
-    return false;
 
   if (auto *UDivExpr = dyn_cast<SCEVUDivExpr>(S)) {
     // If the divisor is a power of two and the SCEV type fits in a native