LLVM  9.0.0svn
Macros | Functions | Variables
ScalarEvolution.cpp File Reference
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/EquivalenceClasses.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <map>
#include <memory>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "scalar-evolution"
 

Functions

 STATISTIC (NumArrayLenItCounts, "Number of trip counts computed with array length")
 
 STATISTIC (NumTripCountsComputed, "Number of loops with predictable loop counts")
 
 STATISTIC (NumTripCountsNotComputed, "Number of loops without predictable loop counts")
 
 STATISTIC (NumBruteForceTripCountsComputed, "Number of loops with trip counts computed by force")
 
static int CompareValueComplexity (EquivalenceClasses< const Value *> &EqCacheValue, const LoopInfo *const LI, Value *LV, Value *RV, unsigned Depth)
 Compare the two values LV and RV in terms of their "complexity" where "complexity" is a partial (and somewhat ad-hoc) relation used to order operands in SCEV expressions. More...
 
static int CompareSCEVComplexity (EquivalenceClasses< const SCEV *> &EqCacheSCEV, EquivalenceClasses< const Value *> &EqCacheValue, const LoopInfo *const LI, const SCEV *LHS, const SCEV *RHS, DominatorTree &DT, unsigned Depth=0)
 
static void GroupByComplexity (SmallVectorImpl< const SCEV *> &Ops, LoopInfo *LI, DominatorTree &DT)
 Given a list of SCEV objects, order them by their complexity, and group objects of the same complexity together by value. More...
 
static int sizeOfSCEV (const SCEV *S)
 
static bool isHugeExpression (const SCEV *S)
 Returns true if the subtree of S contains at least HugeExprThreshold nodes. More...
 
static bool hasHugeExpression (ArrayRef< const SCEV *> Ops)
 Returns true of Ops contains a huge SCEV (see definition above). More...
 
static const SCEVBinomialCoefficient (const SCEV *It, unsigned K, ScalarEvolution &SE, Type *ResultTy)
 Compute BC(It, K). The result has width W. Assume, K > 0. More...
 
static const SCEVgetSignedOverflowLimitForStep (const SCEV *Step, ICmpInst::Predicate *Pred, ScalarEvolution *SE)
 
static const SCEVgetUnsignedOverflowLimitForStep (const SCEV *Step, ICmpInst::Predicate *Pred, ScalarEvolution *SE)
 
template<typename ExtendOpTy >
static const SCEVgetPreStartForExtend (const SCEVAddRecExpr *AR, Type *Ty, ScalarEvolution *SE, unsigned Depth)
 
template<typename ExtendOpTy >
static const SCEVgetExtendAddRecStart (const SCEVAddRecExpr *AR, Type *Ty, ScalarEvolution *SE, unsigned Depth)
 
static APInt extractConstantWithoutWrapping (ScalarEvolution &SE, const SCEVConstant *ConstantTerm, const SCEVAddExpr *WholeAddExpr)
 
static APInt extractConstantWithoutWrapping (ScalarEvolution &SE, const APInt &ConstantStart, const SCEV *Step)
 
static bool CollectAddOperandsWithScales (DenseMap< const SCEV *, APInt > &M, SmallVectorImpl< const SCEV *> &NewOps, APInt &AccumulatedConstant, const SCEV *const *Ops, size_t NumOperands, const APInt &Scale, ScalarEvolution &SE)
 Process the given Ops list, which is a list of operands to be added under the given scale, update the given map. More...
 
static SCEV::NoWrapFlags StrengthenNoWrapFlags (ScalarEvolution *SE, SCEVTypes Type, const ArrayRef< const SCEV *> Ops, SCEV::NoWrapFlags Flags)
 
static uint64_t umul_ov (uint64_t i, uint64_t j, bool &Overflow)
 
static uint64_t Choose (uint64_t n, uint64_t k, bool &Overflow)
 Compute the result of "n choose k", the binomial coefficient. More...
 
static bool containsConstantInAddMulChain (const SCEV *StartExpr)
 Determine if any of the operands in this SCEV are a constant or if any of the add or multiply expressions in this SCEV contain a constant. More...
 
static const APInt gcd (const SCEVConstant *C1, const SCEVConstant *C2)
 
static std::pair< const SCEV *, ConstantInt * > splitAddExpr (const SCEV *S)
 Try to split a SCEVAddExpr into a pair of {SCEV, ConstantInt}. More...
 
static bool SCEVLostPoisonFlags (const SCEV *S, const Value *V)
 Check whether value has nuw/nsw/exact set but SCEV does not. More...
 
static void PushDefUseChildren (Instruction *I, SmallVectorImpl< Instruction *> &Worklist)
 Push users of the given Instruction onto the given Worklist. More...
 
static Optional< BinaryOp > MatchBinaryOp (Value *V, DominatorTree &DT)
 Try to map V into a BinaryOp, and return None on failure. More...
 
static TypeisSimpleCastedPHI (const SCEV *Op, const SCEVUnknown *SymbolicPHI, bool &Signed, ScalarEvolution &SE)
 Helper function to createAddRecFromPHIWithCasts. More...
 
static const LoopisIntegerLoopHeaderPHI (const PHINode *PN, LoopInfo &LI)
 
static bool IsAvailableOnEntry (const Loop *L, DominatorTree &DT, const SCEV *S, BasicBlock *BB)
 
static bool BrPHIToSelect (DominatorTree &DT, BranchInst *BI, PHINode *Merge, Value *&C, Value *&LHS, Value *&RHS)
 
static Optional< ConstantRangeGetRangeFromMetadata (Value *V)
 Helper method to assign a range to V from metadata present in the IR. More...
 
static ConstantRange getRangeForAffineARHelper (APInt Step, const ConstantRange &StartRange, const APInt &MaxBECount, unsigned BitWidth, bool Signed)
 
static unsigned getConstantTripCount (const SCEVConstant *ExitCount)
 
static void PushLoopPHIs (const Loop *L, SmallVectorImpl< Instruction *> &Worklist)
 Push PHI nodes in the header of the given loop onto the given Worklist. More...
 
static ConstantIntEvaluateConstantChrecAtConstant (const SCEVAddRecExpr *AddRec, ConstantInt *C, ScalarEvolution &SE)
 
static bool CanConstantFold (const Instruction *I)
 Return true if we can constant fold an instruction of the specified type, assuming that all operands were constants. More...
 
static bool canConstantEvolve (Instruction *I, const Loop *L)
 Determine whether this instruction can constant evolve within this loop assuming its operands can all constant evolve. More...
 
static PHINodegetConstantEvolvingPHIOperands (Instruction *UseInst, const Loop *L, DenseMap< Instruction *, PHINode *> &PHIMap, unsigned Depth)
 getConstantEvolvingPHIOperands - Implement getConstantEvolvingPHI by recursing through each instruction operand until reaching a loop header phi. More...
 
static PHINodegetConstantEvolvingPHI (Value *V, const Loop *L)
 getConstantEvolvingPHI - Given an LLVM value and a loop, return a PHI node in the loop that V is derived from. More...
 
static ConstantEvaluateExpression (Value *V, const Loop *L, DenseMap< Instruction *, Constant *> &Vals, const DataLayout &DL, const TargetLibraryInfo *TLI)
 EvaluateExpression - Given an expression that passes the getConstantEvolvingPHI predicate, evaluate its value assuming the PHI node in the loop has the value PHIVal. More...
 
static ConstantgetOtherIncomingValue (PHINode *PN, BasicBlock *BB)
 
static ConstantBuildConstantFromSCEV (const SCEV *V)
 This builds up a Constant using the ConstantExpr interface. More...
 
static const SCEVSolveLinEquationWithOverflow (const APInt &A, const SCEV *B, ScalarEvolution &SE)
 Finds the minimum unsigned root of the following equation: More...
 
static Optional< std::tuple< APInt, APInt, APInt, APInt, unsigned > > GetQuadraticEquation (const SCEVAddRecExpr *AddRec)
 For a given quadratic addrec, generate coefficients of the corresponding quadratic equation, multiplied by a common value to ensure that they are integers. More...
 
static Optional< APIntMinOptional (Optional< APInt > X, Optional< APInt > Y)
 Helper function to compare optional APInts: (a) if X and Y both exist, return min(X, Y), (b) if neither X nor Y exist, return None, (c) if exactly one of X and Y exists, return that value. More...
 
static Optional< APIntTruncIfPossible (Optional< APInt > X, unsigned BitWidth)
 Helper function to truncate an optional APInt to a given BitWidth. More...
 
static Optional< APIntSolveQuadraticAddRecExact (const SCEVAddRecExpr *AddRec, ScalarEvolution &SE)
 Let c(n) be the value of the quadratic chrec {L,+,M,+,N} after n iterations. More...
 
static Optional< APIntSolveQuadraticAddRecRange (const SCEVAddRecExpr *AddRec, const ConstantRange &Range, ScalarEvolution &SE)
 Let c(n) be the value of the quadratic chrec {0,+,M,+,N} after n iterations. More...
 
static bool HasSameValue (const SCEV *A, const SCEV *B)
 SCEV structural equivalence is usually sufficient for testing whether two expressions are equal, however for the purposes of looking for a condition guarding a loop, it can be useful to be a little more general, since a front-end may have replicated the controlling expression. More...
 
static const SCEVMatchNotExpr (const SCEV *Expr)
 If Expr computes ~A, return A else return nullptr. More...
 
template<typename MaxExprType >
static bool IsMaxConsistingOf (const SCEV *MaybeMaxExpr, const SCEV *Candidate)
 Is MaybeMaxExpr an SMax or UMax of Candidate and some other values? More...
 
template<typename MaxExprType >
static bool IsMinConsistingOf (ScalarEvolution &SE, const SCEV *MaybeMinExpr, const SCEV *Candidate)
 Is MaybeMinExpr an SMin or UMin of Candidate and some other values? More...
 
static bool IsKnownPredicateViaAddRecStart (ScalarEvolution &SE, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
 
static bool IsKnownPredicateViaMinOrMax (ScalarEvolution &SE, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
 Is LHS Pred RHS true on the virtue of LHS or RHS being a Min or Max expression? More...
 
static bool containsUndefs (const SCEV *S)
 
static bool findArrayDimensionsRec (ScalarEvolution &SE, SmallVectorImpl< const SCEV *> &Terms, SmallVectorImpl< const SCEV *> &Sizes)
 
static bool containsParameters (SmallVectorImpl< const SCEV *> &Terms)
 
static int numberOfTerms (const SCEV *S)
 
static const SCEVremoveConstantFactors (ScalarEvolution &SE, const SCEV *T)
 
static void PrintLoopInfo (raw_ostream &OS, ScalarEvolution *SE, const Loop *L)
 
static StringRef loopDispositionToStr (ScalarEvolution::LoopDisposition LD)
 
 INITIALIZE_PASS_BEGIN (ScalarEvolutionWrapperPass, "scalar-evolution", "Scalar Evolution Analysis", false, true) INITIALIZE_PASS_END(ScalarEvolutionWrapperPass
 

Variables

static cl::opt< unsignedMaxBruteForceIterations ("scalar-evolution-max-iterations", cl::ReallyHidden, cl::desc("Maximum number of iterations SCEV will " "symbolically execute a constant " "derived loop"), cl::init(100))
 
static cl::opt< boolVerifySCEV ("verify-scev", cl::Hidden, cl::desc("Verify ScalarEvolution's backedge taken counts (slow)"))
 
static cl::opt< boolVerifySCEVMap ("verify-scev-maps", cl::Hidden, cl::desc("Verify no dangling value in ScalarEvolution's " "ExprValueMap (slow)"))
 
static cl::opt< boolVerifyIR ("scev-verify-ir", cl::Hidden, cl::desc("Verify IR correctness when making sensitive SCEV queries (slow)"), cl::init(false))
 
static cl::opt< unsignedMulOpsInlineThreshold ("scev-mulops-inline-threshold", cl::Hidden, cl::desc("Threshold for inlining multiplication operands into a SCEV"), cl::init(32))
 
static cl::opt< unsignedAddOpsInlineThreshold ("scev-addops-inline-threshold", cl::Hidden, cl::desc("Threshold for inlining addition operands into a SCEV"), cl::init(500))
 
static cl::opt< unsignedMaxSCEVCompareDepth ("scalar-evolution-max-scev-compare-depth", cl::Hidden, cl::desc("Maximum depth of recursive SCEV complexity comparisons"), cl::init(32))
 
static cl::opt< unsignedMaxSCEVOperationsImplicationDepth ("scalar-evolution-max-scev-operations-implication-depth", cl::Hidden, cl::desc("Maximum depth of recursive SCEV operations implication analysis"), cl::init(2))
 
static cl::opt< unsignedMaxValueCompareDepth ("scalar-evolution-max-value-compare-depth", cl::Hidden, cl::desc("Maximum depth of recursive value complexity comparisons"), cl::init(2))
 
static cl::opt< unsignedMaxArithDepth ("scalar-evolution-max-arith-depth", cl::Hidden, cl::desc("Maximum depth of recursive arithmetics"), cl::init(32))
 
static cl::opt< unsignedMaxConstantEvolvingDepth ("scalar-evolution-max-constant-evolving-depth", cl::Hidden, cl::desc("Maximum depth of recursive constant evolving"), cl::init(32))
 
static cl::opt< unsignedMaxExtDepth ("scalar-evolution-max-ext-depth", cl::Hidden, cl::desc("Maximum depth of recursive SExt/ZExt"), cl::init(8))
 
static cl::opt< unsignedMaxAddRecSize ("scalar-evolution-max-add-rec-size", cl::Hidden, cl::desc("Max coefficients in AddRec during evolving"), cl::init(8))
 
static cl::opt< unsignedHugeExprThreshold ("scalar-evolution-huge-expr-threshold", cl::Hidden, cl::desc("Size of the expression which is considered huge"), cl::init(4096))
 
scalar evolution
 
scalar Scalar Evolution Analysis
 
scalar Scalar Evolution false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "scalar-evolution"

Definition at line 138 of file ScalarEvolution.cpp.

Function Documentation

◆ BinomialCoefficient()

static const SCEV* BinomialCoefficient ( const SCEV It,
unsigned  K,
ScalarEvolution SE,
Type ResultTy 
)
static

◆ BrPHIToSelect()

static bool BrPHIToSelect ( DominatorTree DT,
BranchInst BI,
PHINode Merge,
Value *&  C,
Value *&  LHS,
Value *&  RHS 
)
static

◆ BuildConstantFromSCEV()

static Constant* BuildConstantFromSCEV ( const SCEV V)
static

This builds up a Constant using the ConstantExpr interface.

That way, we will return Constants for objects which aren't represented by a SCEVConstant, because SCEVConstant is restricted to ConstantInt. Returns NULL if the SCEV isn't representable as a Constant.

Definition at line 8004 of file ScalarEvolution.cpp.

References C, CanConstantFold(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldInstOperands(), llvm::ConstantFoldLoadFromConstPtr(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::dyn_cast(), llvm::SCEV::FlagNW, llvm::ConstantExpr::getAdd(), llvm::ConstantExpr::getBitCast(), llvm::ConstantExpr::getCast(), llvm::CastInst::getCastOpcode(), llvm::Value::getContext(), llvm::ConstantExpr::getGetElementPtr(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::Type::getInt32Ty(), llvm::Type::getInt8PtrTy(), llvm::ConstantExpr::getIntegerCast(), llvm::SCEVUDivExpr::getLHS(), llvm::ConstantExpr::getMul(), llvm::PHINode::getNumIncomingValues(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVCastExpr::getOperand(), llvm::SCEVNAryExpr::getOperand(), llvm::Instruction::getParent(), llvm::LoopBase< BlockT, LoopT >::getParentLoop(), llvm::Type::getPointerAddressSpace(), llvm::SCEVUDivExpr::getRHS(), llvm::SCEV::getSCEVType(), llvm::ConstantExpr::getSExt(), llvm::ConstantExpr::getTrunc(), llvm::SCEVCastExpr::getType(), llvm::SCEV::getType(), llvm::Value::getType(), llvm::ConstantExpr::getUDiv(), llvm::ConstantExpr::getZExt(), llvm::Type::isPointerTy(), llvm::LoadInst::isVolatile(), llvm_unreachable, llvm::SCEVCastExpr::Op, llvm::User::operands(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::scAddExpr, llvm::scAddRecExpr, llvm::scConstant, llvm::scCouldNotCompute, llvm::scMulExpr, llvm::scSignExtend, llvm::scSMaxExpr, llvm::scTruncate, llvm::scUDivExpr, llvm::scUMaxExpr, llvm::scUnknown, llvm::scZeroExtend, llvm::ARM_MB::ST, and std::swap().

◆ canConstantEvolve()

static bool canConstantEvolve ( Instruction I,
const Loop L 
)
static

Determine whether this instruction can constant evolve within this loop assuming its operands can all constant evolve.

Definition at line 7681 of file ScalarEvolution.cpp.

References CanConstantFold(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::LoopBase< BlockT, LoopT >::getHeader(), and llvm::Instruction::getParent().

Referenced by EvaluateExpression(), getConstantEvolvingPHI(), and getConstantEvolvingPHIOperands().

◆ CanConstantFold()

static bool CanConstantFold ( const Instruction I)
static

Return true if we can constant fold an instruction of the specified type, assuming that all operands were constants.

Definition at line 7667 of file ScalarEvolution.cpp.

References llvm::canConstantFoldCallTo(), and F().

Referenced by BuildConstantFromSCEV(), and canConstantEvolve().

◆ Choose()

static uint64_t Choose ( uint64_t  n,
uint64_t  k,
bool Overflow 
)
static

Compute the result of "n choose k", the binomial coefficient.

If an intermediate computation overflows, Overflow will be set and the return will be garbage. Overflow is not cleared on absence of overflow.

Definition at line 2836 of file ScalarEvolution.cpp.

References umul_ov().

Referenced by llvm::ScalarEvolution::getMulExpr().

◆ CollectAddOperandsWithScales()

static bool CollectAddOperandsWithScales ( DenseMap< const SCEV *, APInt > &  M,
SmallVectorImpl< const SCEV *> &  NewOps,
APInt AccumulatedConstant,
const SCEV *const Ops,
size_t  NumOperands,
const APInt Scale,
ScalarEvolution SE 
)
static

Process the given Ops list, which is a list of operands to be added under the given scale, update the given map.

This is a helper function for getAddRecExpr. As an example of what it does, given a sequence of operands that would form an add expression like this:

m + n + 13 + (A * (o + p + (B * (q + m + 29)))) + r + (-1 * r)

where A and B are constants, update the map with these values:

(m, 1+A*B), (n, 1), (o, A), (p, A), (q, A*B), (r, 0)

and add 13 + A*B*29 to AccumulatedConstant. This will allow getAddRecExpr to produce this:

13+A*B*29 + n + (m * (1+A*B)) + ((o + p) * A) + (q * A*B)

This form often exposes folding opportunities that are hidden in the original operand list.

Return true iff it appears that any interesting folding opportunities may be exposed. This helps getAddRecExpr short-circuit extra work in the common case where no interesting opportunities are present, and is also used as a check to avoid infinite recursion.

Definition at line 2243 of file ScalarEvolution.cpp.

References llvm::MCID::Add, C, llvm::dyn_cast(), llvm::ScalarEvolution::getMulExpr(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::SCEVNAryExpr::op_begin(), llvm::SCEVNAryExpr::op_end(), and llvm::SmallVectorTemplateBase< T >::push_back().

Referenced by llvm::ScalarEvolution::getAddExpr().

◆ CompareSCEVComplexity()

static int CompareSCEVComplexity ( EquivalenceClasses< const SCEV *> &  EqCacheSCEV,
EquivalenceClasses< const Value *> &  EqCacheValue,
const LoopInfo *const  LI,
const SCEV LHS,
const SCEV RHS,
DominatorTree DT,
unsigned  Depth = 0 
)
static

◆ CompareValueComplexity()

static int CompareValueComplexity ( EquivalenceClasses< const Value *> &  EqCacheValue,
const LoopInfo *const  LI,
Value LV,
Value RV,
unsigned  Depth 
)
static

Compare the two values LV and RV in terms of their "complexity" where "complexity" is a partial (and somewhat ad-hoc) relation used to order operands in SCEV expressions.

EqCache is a set of pairs of values that have been previously deemed to be "equally complex" by this routine. It is intended to avoid exponential time complexity in cases like:

a = f(x, y) b = f(a, a) c = f(b, b)

d = f(x, y) e = f(d, d) f = f(e, e)

CompareValueComplexity(f, c)

Since we do not continue running this routine on expression trees once we have seen unequal values, there is no need to track them in the cache.

Definition at line 560 of file ScalarEvolution.cpp.

References llvm::LoopInfoBase< BlockT, LoopT >::getLoopDepth(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::Value::getValueID(), llvm::EquivalenceClasses< ElemTy >::isEquivalent(), llvm::GlobalValue::isInternalLinkage(), llvm::Type::isPointerTy(), llvm::GlobalValue::isPrivateLinkage(), llvm::AArch64CC::LT, MaxValueCompareDepth, RA, llvm::seq(), and llvm::EquivalenceClasses< ElemTy >::unionSets().

Referenced by CompareSCEVComplexity().

◆ containsConstantInAddMulChain()

static bool containsConstantInAddMulChain ( const SCEV StartExpr)
static

Determine if any of the operands in this SCEV are a constant or if any of the add or multiply expressions in this SCEV contain a constant.

Definition at line 2861 of file ScalarEvolution.cpp.

References F(), llvm::ARM_MB::ST, and llvm::SCEVTraversal< SV >::visitAll().

Referenced by llvm::ScalarEvolution::getMulExpr().

◆ containsParameters()

static bool containsParameters ( SmallVectorImpl< const SCEV *> &  Terms)
inlinestatic

◆ containsUndefs()

static bool containsUndefs ( const SCEV S)
inlinestatic

◆ EvaluateConstantChrecAtConstant()

static ConstantInt* EvaluateConstantChrecAtConstant ( const SCEVAddRecExpr AddRec,
ConstantInt C,
ScalarEvolution SE 
)
static

◆ EvaluateExpression()

static Constant* EvaluateExpression ( Value V,
const Loop L,
DenseMap< Instruction *, Constant *> &  Vals,
const DataLayout DL,
const TargetLibraryInfo TLI 
)
static

EvaluateExpression - Given an expression that passes the getConstantEvolvingPHI predicate, evaluate its value assuming the PHI node in the loop has the value PHIVal.

If we can't fold this expression for some reason, return null.

Definition at line 7757 of file ScalarEvolution.cpp.

References C, canConstantEvolve(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldInstOperands(), llvm::ConstantFoldLoadFromConstPtr(), llvm::dyn_cast(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Value::getType(), llvm::LoadInst::isVolatile(), and llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::lookup().

Referenced by llvm::FileCheckPattern::getCount(), and getOtherIncomingValue().

◆ extractConstantWithoutWrapping() [1/2]

static APInt extractConstantWithoutWrapping ( ScalarEvolution SE,
const SCEVConstant ConstantTerm,
const SCEVAddExpr WholeAddExpr 
)
static

◆ extractConstantWithoutWrapping() [2/2]

static APInt extractConstantWithoutWrapping ( ScalarEvolution SE,
const APInt ConstantStart,
const SCEV Step 
)
static

◆ findArrayDimensionsRec()

static bool findArrayDimensionsRec ( ScalarEvolution SE,
SmallVectorImpl< const SCEV *> &  Terms,
SmallVectorImpl< const SCEV *> &  Sizes 
)
static

◆ gcd()

static const APInt gcd ( const SCEVConstant C1,
const SCEVConstant C2 
)
static

◆ getConstantEvolvingPHI()

static PHINode* getConstantEvolvingPHI ( Value V,
const Loop L 
)
static

getConstantEvolvingPHI - Given an LLVM value and a loop, return a PHI node in the loop that V is derived from.

We allow arbitrary operations along the way, but the operands of an operation must either be constants or a value derived from a constant PHI. If this expression does not fit with these constraints, return null.

Definition at line 7741 of file ScalarEvolution.cpp.

References canConstantEvolve(), llvm::dyn_cast(), and getConstantEvolvingPHIOperands().

Referenced by getOtherIncomingValue().

◆ getConstantEvolvingPHIOperands()

static PHINode* getConstantEvolvingPHIOperands ( Instruction UseInst,
const Loop L,
DenseMap< Instruction *, PHINode *> &  PHIMap,
unsigned  Depth 
)
static

getConstantEvolvingPHIOperands - Implement getConstantEvolvingPHI by recursing through each instruction operand until reaching a loop header phi.

Definition at line 7699 of file ScalarEvolution.cpp.

References canConstantEvolve(), llvm::dyn_cast(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), MaxConstantEvolvingDepth, llvm::SCEVCastExpr::Op, llvm::User::operands(), and P.

Referenced by getConstantEvolvingPHI().

◆ getConstantTripCount()

static unsigned getConstantTripCount ( const SCEVConstant ExitCount)
static

◆ getExtendAddRecStart()

template<typename ExtendOpTy >
static const SCEV* getExtendAddRecStart ( const SCEVAddRecExpr AR,
Type Ty,
ScalarEvolution SE,
unsigned  Depth 
)
static

Definition at line 1486 of file ScalarEvolution.cpp.

References llvm::Depth, and llvm::SCEVCastExpr::Ty.

◆ getOtherIncomingValue()

static Constant* getOtherIncomingValue ( PHINode PN,
BasicBlock BB 
)
static

◆ getPreStartForExtend()

template<typename ExtendOpTy >
static const SCEV* getPreStartForExtend ( const SCEVAddRecExpr AR,
Type Ty,
ScalarEvolution SE,
unsigned  Depth 
)
static

Definition at line 1412 of file ScalarEvolution.cpp.

References llvm::SCEVAddRecExpr::getLoop().

◆ GetQuadraticEquation()

static Optional<std::tuple<APInt, APInt, APInt, APInt, unsigned> > GetQuadraticEquation ( const SCEVAddRecExpr AddRec)
static

For a given quadratic addrec, generate coefficients of the corresponding quadratic equation, multiplied by a common value to ensure that they are integers.

The returned value is a tuple { A, B, C, M, BitWidth }, where Ax^2 + Bx + C is the quadratic function, M is the value that A, B and C were multiplied by, and BitWidth is the bit width of the original addrec coefficients. This function returns None if the addrec coefficients are not compile- time constants.

Definition at line 8380 of file ScalarEvolution.cpp.

References assert(), B, C, llvm::dbgs(), llvm::dyn_cast(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), llvm::APInt::isNullValue(), LLVM_DEBUG, N, NC, llvm::None, and llvm::APInt::sext().

Referenced by SolveQuadraticAddRecExact(), and SolveQuadraticAddRecRange().

◆ getRangeForAffineARHelper()

static ConstantRange getRangeForAffineARHelper ( APInt  Step,
const ConstantRange StartRange,
const APInt MaxBECount,
unsigned  BitWidth,
bool  Signed 
)
static

Definition at line 5757 of file ScalarEvolution.cpp.

References llvm::APInt::abs(), llvm::MCID::Add, llvm::SmallVectorImpl< T >::append(), assert(), llvm::MCID::Call, llvm::computeKnownBits(), llvm::ConstantRange::contains(), llvm::APInt::countLeadingZeros(), llvm::APInt::countTrailingZeros(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::UndefValue::get(), getBitWidth(), llvm::ConstantRange::getBitWidth(), llvm::APInt::getBitWidth(), llvm::LoopBase< BlockT, LoopT >::getBlocks(), getConstant(), llvm::LoopBase< BlockT, LoopT >::getExitingBlock(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::APInt::getLowBitsSet(), llvm::ConstantRange::getLower(), llvm::APInt::getMaxValue(), llvm::SCEVNAryExpr::getNoWrapFlags(), llvm::User::getNumOperands(), llvm::APInt::getOneBitSet(), llvm::Operator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getReturnedArgOperand(), llvm::ConstantRange::getSignedMax(), llvm::ConstantRange::getSignedMin(), llvm::SCEV::getType(), llvm::Value::getType(), llvm::ScalarEvolution::getTypeSizeInBits(), llvm::ConstantRange::getUpper(), llvm::ConstantInt::getValue(), llvm::ConstantInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Optional< T >::hasValue(), I, if(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::ConstantRange::isFullSet(), llvm::isGuaranteedToExecuteForEveryIteration(), llvm::isGuaranteedToTransferExecutionToSuccessor(), isLoopInvariant(), llvm::APInt::isNegative(), llvm::APInt::isSignMask(), llvm::ConstantInt::isZero(), llvm_unreachable, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), MatchBinaryOp(), llvm::Instruction::mayHaveSideEffects(), llvm::SCEVCastExpr::Op, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::programUndefinedIfFullPoison(), llvm::propagatesFullPoison(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::scSignExtend, llvm::scTruncate, llvm::scZeroExtend, llvm::MCID::Select, llvm::ScalarEvolution::setFlags(), llvm::APInt::sext(), llvm::APInt::shl(), SI, llvm::APInt::trunc(), llvm::SCEVCastExpr::Ty, llvm::APInt::uge(), llvm::APInt::ult(), llvm::ConstantRange::unionWith(), llvm::Value::users(), llvm::NVPTX::PTXLdStInstCode::V2, X, llvm::Z, llvm::KnownBits::Zero, and llvm::APInt::zext().

◆ GetRangeFromMetadata()

static Optional<ConstantRange> GetRangeFromMetadata ( Value V)
static

◆ getSignedOverflowLimitForStep()

static const SCEV* getSignedOverflowLimitForStep ( const SCEV Step,
ICmpInst::Predicate *  Pred,
ScalarEvolution SE 
)
static

◆ getUnsignedOverflowLimitForStep()

static const SCEV* getUnsignedOverflowLimitForStep ( const SCEV Step,
ICmpInst::Predicate *  Pred,
ScalarEvolution SE 
)
static

◆ GroupByComplexity()

static void GroupByComplexity ( SmallVectorImpl< const SCEV *> &  Ops,
LoopInfo LI,
DominatorTree DT 
)
static

Given a list of SCEV objects, order them by their complexity, and group objects of the same complexity together by value.

When this routine is finished, we know that any duplicates in the vector are consecutive and that complexity is monotonically increasing.

Note that we go take special precautions to ensure that we get deterministic results from this routine. In other words, we don't want the results of this to depend on where the addresses of various SCEV objects happened to land in memory.

Definition at line 786 of file ScalarEvolution.cpp.

References llvm::SmallVectorTemplateCommon< T >::begin(), CompareSCEVComplexity(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SCEV::getSCEVType(), llvm::SmallVectorBase::size(), and std::swap().

Referenced by llvm::ScalarEvolution::getAddExpr(), llvm::ScalarEvolution::getMulExpr(), llvm::ScalarEvolution::getSMaxExpr(), and llvm::ScalarEvolution::getUMaxExpr().

◆ hasHugeExpression()

static bool hasHugeExpression ( ArrayRef< const SCEV *>  Ops)
static

◆ HasSameValue()

static bool HasSameValue ( const SCEV A,
const SCEV B 
)
static

SCEV structural equivalence is usually sufficient for testing whether two expressions are equal, however for the purposes of looking for a condition guarding a loop, it can be useful to be a little more general, since a front-end may have replicated the controlling expression.

Definition at line 8808 of file ScalarEvolution.cpp.

References B, and llvm::Instruction::isIdenticalTo().

Referenced by IsKnownPredicateViaMinOrMax(), llvm::ScalarEvolution::isLoopInvariantPredicate(), and llvm::ScalarEvolution::SimplifyICmpOperands().

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( ScalarEvolutionWrapperPass  ,
"scalar-evolution ,
"Scalar Evolution Analysis ,
false  ,
true   
)

◆ IsAvailableOnEntry()

static bool IsAvailableOnEntry ( const Loop L,
DominatorTree DT,
const SCEV S,
BasicBlock BB 
)
static

◆ isHugeExpression()

static bool isHugeExpression ( const SCEV S)
static

Returns true if the subtree of S contains at least HugeExprThreshold nodes.

Definition at line 855 of file ScalarEvolution.cpp.

References llvm::SCEV::getExpressionSize(), and HugeExprThreshold.

Referenced by llvm::ScalarEvolution::getMulExpr(), and hasHugeExpression().

◆ isIntegerLoopHeaderPHI()

static const Loop* isIntegerLoopHeaderPHI ( const PHINode PN,
LoopInfo LI 
)
static

◆ IsKnownPredicateViaAddRecStart()

static bool IsKnownPredicateViaAddRecStart ( ScalarEvolution SE,
ICmpInst::Predicate  Pred,
const SCEV LHS,
const SCEV RHS 
)
static

◆ IsKnownPredicateViaMinOrMax()

static bool IsKnownPredicateViaMinOrMax ( ScalarEvolution SE,
ICmpInst::Predicate  Pred,
const SCEV LHS,
const SCEV RHS 
)
static

◆ IsMaxConsistingOf()

template<typename MaxExprType >
static bool IsMaxConsistingOf ( const SCEV MaybeMaxExpr,
const SCEV Candidate 
)
static

Is MaybeMaxExpr an SMax or UMax of Candidate and some other values?

Definition at line 10083 of file ScalarEvolution.cpp.

References llvm::dyn_cast(), and llvm::find().

◆ IsMinConsistingOf()

template<typename MaxExprType >
static bool IsMinConsistingOf ( ScalarEvolution SE,
const SCEV MaybeMinExpr,
const SCEV Candidate 
)
static

Is MaybeMinExpr an SMin or UMin of Candidate and some other values?

Definition at line 10093 of file ScalarEvolution.cpp.

References llvm::ScalarEvolution::getNotSCEV(), and MatchNotExpr().

◆ isSimpleCastedPHI()

static Type* isSimpleCastedPHI ( const SCEV Op,
const SCEVUnknown SymbolicPHI,
bool Signed,
ScalarEvolution SE 
)
static

Helper function to createAddRecFromPHIWithCasts.

We have a phi node whose symbolic (unknown) SCEV is SymbolicPHI, which is updated via the loop backedge by a SCEVAddExpr, possibly also with a few casts on the way. This function checks if Op, an operand of this SCEVAddExpr, follows one of the following patterns: Op == (SExt ix (Trunc iy (SymbolicPHI) to ix) to iy) Op == (ZExt ix (Trunc iy (SymbolicPHI) to ix) to iy) If the SCEV expression of Op conforms with one of the expected patterns we return the type of the truncation operation, and indicate whether the truncated type should be treated as signed/unsigned by setting Signed to true/false, respectively.

Definition at line 4615 of file ScalarEvolution.cpp.

References llvm::dyn_cast(), llvm::SCEVCastExpr::getOperand(), llvm::SCEVCastExpr::getType(), llvm::SCEV::getType(), llvm::SCEVUnknown::getType(), llvm::ScalarEvolution::getTypeSizeInBits(), llvm::SCEVCastExpr::Op, and X.

Referenced by isIntegerLoopHeaderPHI().

◆ loopDispositionToStr()

static StringRef loopDispositionToStr ( ScalarEvolution::LoopDisposition  LD)
static

◆ MatchBinaryOp()

static Optional<BinaryOp> MatchBinaryOp ( Value V,
DominatorTree DT 
)
static

◆ MatchNotExpr()

static const SCEV* MatchNotExpr ( const SCEV Expr)
static

If Expr computes ~A, return A else return nullptr.

Definition at line 10067 of file ScalarEvolution.cpp.

References llvm::MCID::Add, llvm::dyn_cast(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), and llvm::SCEV::isAllOnesValue().

Referenced by IsMinConsistingOf().

◆ MinOptional()

static Optional<APInt> MinOptional ( Optional< APInt X,
Optional< APInt Y 
)
static

Helper function to compare optional APInts: (a) if X and Y both exist, return min(X, Y), (b) if neither X nor Y exist, return None, (c) if exactly one of X and Y exists, return that value.

Definition at line 8433 of file ScalarEvolution.cpp.

References llvm::APInt::getBitWidth(), llvm::Optional< T >::hasValue(), llvm::max(), llvm::None, llvm::APInt::sextOrSelf(), llvm::APInt::slt(), llvm::RISCVFenceField::W, X, and Y.

Referenced by SolveQuadraticAddRecRange().

◆ numberOfTerms()

static int numberOfTerms ( const SCEV S)
inlinestatic

Definition at line 11040 of file ScalarEvolution.cpp.

Referenced by llvm::ScalarEvolution::findArrayDimensions().

◆ PrintLoopInfo()

static void PrintLoopInfo ( raw_ostream OS,
ScalarEvolution SE,
const Loop L 
)
static

◆ PushDefUseChildren()

static void PushDefUseChildren ( Instruction I,
SmallVectorImpl< Instruction *> &  Worklist 
)
static

Push users of the given Instruction onto the given Worklist.

Definition at line 4183 of file ScalarEvolution.cpp.

References llvm::MCID::Add, assert(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::SelectInst::getCondition(), llvm::BranchInst::getCondition(), llvm::ScalarEvolution::getCouldNotCompute(), llvm::SelectInst::getFalseValue(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::Type::getInt1Ty(), llvm::SCEVAddRecExpr::getLoop(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::ScalarEvolution::getMinusSCEV(), llvm::Operator::getOpcode(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::SCEVAddRecExpr::getPostIncExpr(), llvm::ScalarEvolution::getSCEV(), llvm::SCEVAddRecExpr::getStart(), llvm::SCEVAddRecExpr::getStepRecurrence(), llvm::BranchInst::getSuccessor(), llvm::SelectInst::getTrueValue(), llvm::Optional< T >::getValue(), llvm::SCEVUnknown::getValue(), llvm::SCEVNAryExpr::hasNoSignedWrap(), llvm::SCEVNAryExpr::hasNoUnsignedWrap(), llvm::Optional< T >::hasValue(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SCEVAddRecExpr::isAffine(), llvm::BranchInst::isConditional(), llvm::ScalarEvolution::isLoopInvariant(), llvm::ConstantRange::makeGuaranteedNoWrapRegion(), llvm::None, llvm::SCEVCastExpr::Op, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T >::push_back(), Rewriter, llvm::MCID::Select, llvm::ScalarEvolution::setFlags(), SI, and llvm::Value::users().

Referenced by llvm::ScalarEvolution::forgetLoop(), and llvm::ScalarEvolution::forgetValue().

◆ PushLoopPHIs()

static void PushLoopPHIs ( const Loop L,
SmallVectorImpl< Instruction *> &  Worklist 
)
static

◆ removeConstantFactors()

static const SCEV* removeConstantFactors ( ScalarEvolution SE,
const SCEV T 
)
static

◆ SCEVLostPoisonFlags()

static bool SCEVLostPoisonFlags ( const SCEV S,
const Value V 
)
static

Check whether value has nuw/nsw/exact set but SCEV does not.

TODO: In reality it is better to check the poison recursively but this is better than nothing.

Definition at line 3913 of file ScalarEvolution.cpp.

References I.

Referenced by llvm::ScalarEvolution::getSCEV().

◆ sizeOfSCEV()

static int sizeOfSCEV ( const SCEV S)
inlinestatic

Definition at line 830 of file ScalarEvolution.cpp.

References F(), Size, llvm::ARM_MB::ST, and llvm::SCEVTraversal< SV >::visitAll().

Referenced by hasHugeExpression().

◆ SolveLinEquationWithOverflow()

static const SCEV* SolveLinEquationWithOverflow ( const APInt A,
const SCEV B,
ScalarEvolution SE 
)
static

◆ SolveQuadraticAddRecExact()

static Optional<APInt> SolveQuadraticAddRecExact ( const SCEVAddRecExpr AddRec,
ScalarEvolution SE 
)
static

Let c(n) be the value of the quadratic chrec {L,+,M,+,N} after n iterations.

The values L, M, N are assumed to be signed, and they should all have the same bit widths. Find the least n >= 0 such that c(n) = 0 in the arithmetic modulo 2^BW, where BW is the bit width of the addrec's coefficients. If the calculated value is a BW-bit integer (for BW > 1), it will be returned as such, otherwise the bit width of the returned value may be greater than BW.

This function returns None if (a) the addrec coefficients are not constant, or (b) SolveQuadraticEquationWrap was unable to find a solution. For cases like x^2 = 5, no integer solutions exist, in other cases an integer solution may exist, but SolveQuadraticEquationWrap may fail to find it.

Definition at line 8480 of file ScalarEvolution.cpp.

References B, C, llvm::dbgs(), EvaluateConstantChrecAtConstant(), llvm::ConstantInt::get(), llvm::ScalarEvolution::getContext(), GetQuadraticEquation(), llvm::Optional< T >::hasValue(), LLVM_DEBUG, llvm::None, llvm::APIntOps::SolveQuadraticEquationWrap(), T, TruncIfPossible(), and X.

Referenced by SolveQuadraticAddRecRange().

◆ SolveQuadraticAddRecRange()

static Optional<APInt> SolveQuadraticAddRecRange ( const SCEVAddRecExpr AddRec,
const ConstantRange Range,
ScalarEvolution SE 
)
static

◆ splitAddExpr()

static std::pair<const SCEV *, ConstantInt *> splitAddExpr ( const SCEV S)
static

Try to split a SCEVAddExpr into a pair of {SCEV, ConstantInt}.

If S is a SCEVAddExpr and is composed of a sub SCEV S' and an offset I, then return {S', I}, else return {S, nullptr}.

Definition at line 3855 of file ScalarEvolution.cpp.

References llvm::MCID::Add, assert(), llvm::dyn_cast(), SI, and VerifySCEVMap.

Referenced by llvm::ScalarEvolution::eraseValueFromMap(), and llvm::ScalarEvolution::getSCEV().

◆ STATISTIC() [1/4]

STATISTIC ( NumArrayLenItCounts  ,
"Number of trip counts computed with array length"   
)

◆ STATISTIC() [2/4]

STATISTIC ( NumTripCountsComputed  ,
"Number of loops with predictable loop counts"   
)

◆ STATISTIC() [3/4]

STATISTIC ( NumTripCountsNotComputed  ,
"Number of loops without predictable loop counts"   
)

◆ STATISTIC() [4/4]

STATISTIC ( NumBruteForceTripCountsComputed  ,
"Number of loops with trip counts computed by force"   
)

◆ StrengthenNoWrapFlags()

static SCEV::NoWrapFlags StrengthenNoWrapFlags ( ScalarEvolution SE,
SCEVTypes  Type,
const ArrayRef< const SCEV *>  Ops,
SCEV::NoWrapFlags  Flags 
)
static

◆ TruncIfPossible()

static Optional<APInt> TruncIfPossible ( Optional< APInt X,
unsigned  BitWidth 
)
static

Helper function to truncate an optional APInt to a given BitWidth.

When solving addrec-related equations, it is preferable to return a value that has the same bit width as the original addrec's coefficients. If the solution fits in the original bit width, truncate it (except for i1). Returning a value of a different bit width may inhibit some optimizations.

In general, a solution to a quadratic equation generated from an addrec may require BW+1 bits, where BW is the bit width of the addrec's coefficients. The reason is that the coefficients of the quadratic equation are BW+1 bits wide (to avoid truncation when converting from the addrec to the equation).

Definition at line 8456 of file ScalarEvolution.cpp.

References llvm::APInt::getBitWidth(), llvm::Optional< T >::hasValue(), llvm::isIntN(), llvm::None, llvm::APInt::trunc(), llvm::RISCVFenceField::W, and X.

Referenced by SolveQuadraticAddRecExact(), and SolveQuadraticAddRecRange().

◆ umul_ov()

static uint64_t umul_ov ( uint64_t  i,
uint64_t  j,
bool Overflow 
)
static

Variable Documentation

◆ AddOpsInlineThreshold

cl::opt<unsigned> AddOpsInlineThreshold("scev-addops-inline-threshold", cl::Hidden, cl::desc("Threshold for inlining addition operands into a SCEV"), cl::init(500))
static

◆ Analysis

scalar Scalar Evolution Analysis

Definition at line 11949 of file ScalarEvolution.cpp.

◆ evolution

scalar evolution

Definition at line 11949 of file ScalarEvolution.cpp.

◆ false

scalar Scalar Evolution false

Definition at line 11949 of file ScalarEvolution.cpp.

◆ HugeExprThreshold

cl::opt<unsigned> HugeExprThreshold("scalar-evolution-huge-expr-threshold", cl::Hidden, cl::desc("Size of the expression which is considered huge"), cl::init(4096))
static

Referenced by isHugeExpression().

◆ MaxAddRecSize

cl::opt<unsigned> MaxAddRecSize("scalar-evolution-max-add-rec-size", cl::Hidden, cl::desc("Max coefficients in AddRec during evolving"), cl::init(8))
static

◆ MaxArithDepth

cl::opt<unsigned> MaxArithDepth("scalar-evolution-max-arith-depth", cl::Hidden, cl::desc("Maximum depth of recursive arithmetics"), cl::init(32))
static

◆ MaxBruteForceIterations

cl::opt<unsigned> MaxBruteForceIterations("scalar-evolution-max-iterations", cl::ReallyHidden, cl::desc("Maximum number of iterations SCEV will " "symbolically execute a constant " "derived loop"), cl::init(100))
static

◆ MaxConstantEvolvingDepth

cl::opt<unsigned> MaxConstantEvolvingDepth("scalar-evolution-max-constant-evolving-depth", cl::Hidden, cl::desc("Maximum depth of recursive constant evolving"), cl::init(32))
static

◆ MaxExtDepth

cl::opt<unsigned> MaxExtDepth("scalar-evolution-max-ext-depth", cl::Hidden, cl::desc("Maximum depth of recursive SExt/ZExt"), cl::init(8))
static

◆ MaxSCEVCompareDepth

cl::opt<unsigned> MaxSCEVCompareDepth("scalar-evolution-max-scev-compare-depth", cl::Hidden, cl::desc("Maximum depth of recursive SCEV complexity comparisons"), cl::init(32))
static

Referenced by CompareSCEVComplexity().

◆ MaxSCEVOperationsImplicationDepth

cl::opt<unsigned> MaxSCEVOperationsImplicationDepth("scalar-evolution-max-scev-operations-implication-depth", cl::Hidden, cl::desc("Maximum depth of recursive SCEV operations implication analysis"), cl::init(2))
static

◆ MaxValueCompareDepth

cl::opt<unsigned> MaxValueCompareDepth("scalar-evolution-max-value-compare-depth", cl::Hidden, cl::desc("Maximum depth of recursive value complexity comparisons"), cl::init(2))
static

Referenced by CompareValueComplexity().

◆ MulOpsInlineThreshold

cl::opt<unsigned> MulOpsInlineThreshold("scev-mulops-inline-threshold", cl::Hidden, cl::desc("Threshold for inlining multiplication operands into a SCEV"), cl::init(32))
static

◆ VerifyIR

cl::opt<bool> VerifyIR("scev-verify-ir", cl::Hidden, cl::desc("Verify IR correctness when making sensitive SCEV queries (slow)"), cl::init(false))
static

◆ VerifySCEV

cl::opt<bool> VerifySCEV("verify-scev", cl::Hidden, cl::desc("Verify ScalarEvolution's backedge taken counts (slow)"))
static

◆ VerifySCEVMap

cl::opt<bool> VerifySCEVMap("verify-scev-maps", cl::Hidden, cl::desc("Verify no dangling value in ScalarEvolution's " "ExprValueMap (slow)"))
static

Referenced by splitAddExpr().