diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/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(S)->getOperand(), L, At, BudgetRemaining, TTI, Processed); @@ -2163,7 +2170,6 @@ L, At, BudgetRemaining, TTI, Processed); } - if (auto *UDivExpr = dyn_cast(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