From 2d8275d72e1602a1869e6286b0ffbf9034ab102b Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 25 Feb 2020 21:51:12 +0300 Subject: [PATCH] [SCEV] SCEVExpander::isHighCostExpansion(): assert if TTI is not provided Summary: Currently, as per `check-llvm`, we never call `SCEVExpander::isHighCostExpansion()` with null TTI, so this appears to be a safe restriction. Reviewers: reames, mkazantsev, wmi, sanjoy Reviewed By: mkazantsev Subscribers: javed.absar, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73712 --- llvm/include/llvm/Analysis/ScalarEvolutionExpander.h | 7 +++++-- llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h index a1b2ed3666c7..65f4a29888c6 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -182,9 +182,12 @@ namespace llvm { bool isHighCostExpansion(const SCEV *Expr, Loop *L, unsigned Budget, const TargetTransformInfo *TTI, const Instruction *At = nullptr) { + assert(TTI && "This function requires TTI to be provided."); + if (!TTI) // In assert-less builds, avoid crashing + return true; // by always claiming to be high-cost. SmallPtrSet Processed; int BudgetRemaining = Budget * TargetTransformInfo::TCC_Basic; - return isHighCostExpansionHelper(Expr, L, At, BudgetRemaining, TTI, + return isHighCostExpansionHelper(Expr, L, At, BudgetRemaining, *TTI, Processed); } @@ -329,7 +332,7 @@ namespace llvm { /// Recursive helper function for isHighCostExpansion. bool isHighCostExpansionHelper(const SCEV *S, Loop *L, const Instruction *At, int &BudgetRemaining, - const TargetTransformInfo *TTI, + const TargetTransformInfo &TTI, SmallPtrSetImpl &Processed); /// Insert the specified binary operator, doing a small amount of work to diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index e8f267a39225..989e86485d62 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -2137,7 +2137,7 @@ 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 &Processed) { + const TargetTransformInfo &TTI, SmallPtrSetImpl &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. @@ -2145,13 +2145,16 @@ bool SCEVExpander::isHighCostExpansionHelper( // 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. + } + + // Zero/One operand expressions + switch (S->getSCEVType()) { case scTruncate: return isHighCostExpansionHelper(cast(S)->getOperand(), L, At, BudgetRemaining, TTI, Processed); -- 2.34.1