/// Return true for expressions that can't be evaluated at runtime
/// within given \b Budget.
///
- /// At is a parameter which specifies point in code where user is going to
- /// expand this expression. Sometimes this knowledge can lead to
+ /// \p At is a parameter which specifies point in code where user is going to
+ /// expand these expressions. Sometimes this knowledge can lead to
/// a less pessimistic cost estimation.
- bool isHighCostExpansion(const SCEV *Expr, Loop *L, unsigned Budget,
- const TargetTransformInfo *TTI,
+ bool isHighCostExpansion(ArrayRef<const SCEV *> Exprs, Loop *L,
+ unsigned Budget, const TargetTransformInfo *TTI,
const Instruction *At) {
assert(TTI && "This function requires TTI to be provided.");
assert(At && "This function requires At instruction to be provided.");
SmallPtrSet<const SCEV *, 8> Processed;
InstructionCost Cost = 0;
unsigned ScaledBudget = Budget * TargetTransformInfo::TCC_Basic;
- Worklist.emplace_back(-1, -1, Expr);
+ for (auto *Expr : Exprs)
+ Worklist.emplace_back(-1, -1, Expr);
while (!Worklist.empty()) {
const SCEVOperand WorkItem = Worklist.pop_back_val();
if (isHighCostExpansionHelper(WorkItem, L, *At, Cost, ScaledBudget, *TTI,
// Do not generate something ridiculous.
auto *PHTerm = Preheader->getTerminator();
- if (Rewriter.isHighCostExpansion(InvariantLHS, L, SCEVCheapExpansionBudget,
- TTI, PHTerm))
- return false;
- if (Rewriter.isHighCostExpansion(InvariantRHS, L, SCEVCheapExpansionBudget,
- TTI, PHTerm))
+ if (Rewriter.isHighCostExpansion({ InvariantLHS, InvariantRHS }, L,
+ 2 * SCEVCheapExpansionBudget, TTI, PHTerm))
return false;
auto *NewLHS =
Rewriter.expandCodeFor(InvariantLHS, IVOperand->getType(), PHTerm);