LLVM 20.0.0git
Enumerations | Functions | Variables
ValueTracking.cpp File Reference
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumeBundleQueries.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/DomConditionCache.h"
#include "llvm/Analysis/GuardUtils.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/Analysis/WithCache.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.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/IntrinsicsAArch64.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/IntrinsicsRISCV.h"
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/TargetParser/RISCVTargetParser.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <optional>
#include <utility>

Go to the source code of this file.

Enumerations

enum class  UndefPoisonKind { PoisonOnly = (1 << 0) , UndefOnly = (1 << 1) , UndefOrPoison = PoisonOnly | UndefOnly }
 

Functions

static unsigned getBitWidth (Type *Ty, const DataLayout &DL)
 Returns the bitwidth of the given scalar or pointer type.
 
static const InstructionsafeCxtI (const Value *V, const Instruction *CxtI)
 
static const InstructionsafeCxtI (const Value *V1, const Value *V2, const Instruction *CxtI)
 
static bool getShuffleDemandedElts (const ShuffleVectorInst *Shuf, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS)
 
static void computeKnownBits (const Value *V, const APInt &DemandedElts, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q)
 Determine which bits of V are known to be either zero or one and return them in the Known bit set.
 
static bool haveNoCommonBitsSetSpecialCases (const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
 
static bool isKnownNonZero (const Value *V, const APInt &DemandedElts, const SimplifyQuery &Q, unsigned Depth)
 Return true if the given value is known to be non-zero when defined.
 
static bool isKnownNonEqual (const Value *V1, const Value *V2, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 Return true if it is known that V1 != V2.
 
static unsigned ComputeNumSignBits (const Value *V, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 
static unsigned ComputeNumSignBits (const Value *V, unsigned Depth, const SimplifyQuery &Q)
 
static void computeKnownBitsAddSub (bool Add, const Value *Op0, const Value *Op1, bool NSW, bool NUW, const APInt &DemandedElts, KnownBits &KnownOut, KnownBits &Known2, unsigned Depth, const SimplifyQuery &Q)
 
static void computeKnownBitsMul (const Value *Op0, const Value *Op1, bool NSW, bool NUW, const APInt &DemandedElts, KnownBits &Known, KnownBits &Known2, unsigned Depth, const SimplifyQuery &Q)
 
static bool isEphemeralValueOf (const Instruction *I, const Value *E)
 
static bool cmpExcludesZero (CmpInst::Predicate Pred, const Value *RHS)
 
static bool isKnownNonZeroFromAssume (const Value *V, const SimplifyQuery &Q)
 
static void computeKnownBitsFromCmp (const Value *V, CmpInst::Predicate Pred, Value *LHS, Value *RHS, KnownBits &Known, const SimplifyQuery &Q)
 
static void computeKnownBitsFromICmpCond (const Value *V, ICmpInst *Cmp, KnownBits &Known, const SimplifyQuery &SQ, bool Invert)
 
static void computeKnownBitsFromCond (const Value *V, Value *Cond, KnownBits &Known, unsigned Depth, const SimplifyQuery &SQ, bool Invert)
 
static void computeKnownBitsFromShiftOperator (const Operator *I, const APInt &DemandedElts, KnownBits &Known, KnownBits &Known2, unsigned Depth, const SimplifyQuery &Q, function_ref< KnownBits(const KnownBits &, const KnownBits &, bool)> KF)
 Compute known bits from a shift operator, including those with a non-constant shift amount.
 
static KnownBits getKnownBitsFromAndXorOr (const Operator *I, const APInt &DemandedElts, const KnownBits &KnownLHS, const KnownBits &KnownRHS, unsigned Depth, const SimplifyQuery &Q)
 
static KnownBits computeKnownBitsForHorizontalOperation (const Operator *I, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q, const function_ref< KnownBits(const KnownBits &, const KnownBits &)> KnownBitsFunc)
 
static void computeKnownBitsFromOperator (const Operator *I, const APInt &DemandedElts, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q)
 
static bool isPowerOfTwoRecurrence (const PHINode *PN, bool OrZero, unsigned Depth, SimplifyQuery &Q)
 Try to detect a recurrence that the value of the induction variable is always a power of two (or zero).
 
static bool isImpliedToBeAPowerOfTwoFromCond (const Value *V, bool OrZero, const Value *Cond, bool CondIsTrue)
 Return true if we can infer that V is known to be a power of 2 from dominating condition Cond (e.g., ctpop(V) == 1).
 
static bool isGEPKnownNonNull (const GEPOperator *GEP, unsigned Depth, const SimplifyQuery &Q)
 Test whether a GEP's result is known to be non-null.
 
static bool isKnownNonNullFromDominatingCondition (const Value *V, const Instruction *CtxI, const DominatorTree *DT)
 
static bool rangeMetadataExcludesValue (const MDNode *Ranges, const APInt &Value)
 Does the 'Range' metadata (which must be a valid MD_range operand list) ensure that the value it's attached to is never Value? 'RangeType' is is the type of the value described by the range.
 
static bool isNonZeroRecurrence (const PHINode *PN)
 Try to detect a recurrence that monotonically increases/decreases from a non-zero starting value.
 
static bool matchOpWithOpEqZero (Value *Op0, Value *Op1)
 
static bool isNonZeroAdd (const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q, unsigned BitWidth, Value *X, Value *Y, bool NSW, bool NUW)
 
static bool isNonZeroSub (const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q, unsigned BitWidth, Value *X, Value *Y)
 
static bool isNonZeroMul (const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q, unsigned BitWidth, Value *X, Value *Y, bool NSW, bool NUW)
 
static bool isNonZeroShift (const Operator *I, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q, const KnownBits &KnownVal)
 
static bool isKnownNonZeroFromOperator (const Operator *I, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 
static std::optional< std::pair< Value *, Value * > > getInvertibleOperands (const Operator *Op1, const Operator *Op2)
 If the pair of operators are the same invertible function, return the the operands of the function corresponding to each input.
 
static bool isModifyingBinopOfNonZero (const Value *V1, const Value *V2, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 Return true if V1 == (binop V2, X), where X is known non-zero.
 
static bool isNonEqualMul (const Value *V1, const Value *V2, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 Return true if V2 == V1 * C, where V1 is known non-zero, C is not 0/1 and the multiplication is nuw or nsw.
 
static bool isNonEqualShl (const Value *V1, const Value *V2, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 Return true if V2 == V1 << C, where V1 is known non-zero, C is not 0 and the shift is nuw or nsw.
 
static bool isNonEqualPHIs (const PHINode *PN1, const PHINode *PN2, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 
static bool isNonEqualSelect (const Value *V1, const Value *V2, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 
static bool isNonEqualPointersWithRecursiveGEP (const Value *A, const Value *B, const SimplifyQuery &Q)
 
static bool isSignedMinMaxClamp (const Value *Select, const Value *&In, const APInt *&CLow, const APInt *&CHigh)
 
static bool isSignedMinMaxIntrinsicClamp (const IntrinsicInst *II, const APInt *&CLow, const APInt *&CHigh)
 
static unsigned computeNumSignBitsVectorConstant (const Value *V, const APInt &DemandedElts, unsigned TyBits)
 For vector constants, loop over the elements and find the constant with the minimum number of sign bits.
 
static unsigned ComputeNumSignBitsImpl (const Value *V, const APInt &DemandedElts, unsigned Depth, const SimplifyQuery &Q)
 Return the number of times the sign bit of the register is replicated into the other bits.
 
static bool inputDenormalIsIEEE (const Function &F, const Type *Ty)
 Return true if it's possible to assume IEEE treatment of input denormals in F for Val.
 
static bool inputDenormalIsIEEEOrPosZero (const Function &F, const Type *Ty)
 
static bool outputDenormalIsIEEEOrPosZero (const Function &F, const Type *Ty)
 
static std::tuple< Value *, FPClassTest, FPClassTestexactClass (Value *V, FPClassTest M)
 Return the return value for fcmpImpliesClass for a compare that produces an exact class test.
 
static void computeKnownFPClassFromCond (const Value *V, Value *Cond, unsigned Depth, bool CondIsTrue, const Instruction *CxtI, KnownFPClass &KnownFromContext)
 
static KnownFPClass computeKnownFPClassFromContext (const Value *V, const SimplifyQuery &Q)
 
void computeKnownFPClass (const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, KnownFPClass &Known, unsigned Depth, const SimplifyQuery &Q)
 
static void computeKnownFPClass (const Value *V, KnownFPClass &Known, FPClassTest InterestedClasses, unsigned Depth, const SimplifyQuery &Q)
 
static void computeKnownFPClassForFPTrunc (const Operator *Op, const APInt &DemandedElts, FPClassTest InterestedClasses, KnownFPClass &Known, unsigned Depth, const SimplifyQuery &Q)
 
static ValueBuildSubAggregate (Value *From, Value *To, Type *IndexedType, SmallVectorImpl< unsigned > &Idxs, unsigned IdxSkip, BasicBlock::iterator InsertBefore)
 
static ValueBuildSubAggregate (Value *From, ArrayRef< unsigned > idx_range, BasicBlock::iterator InsertBefore)
 
static uint64_t GetStringLengthH (const Value *V, SmallPtrSetImpl< const PHINode * > &PHIs, unsigned CharSize)
 If we can compute the length of the string pointed to by the specified pointer, return 'len+1'.
 
static bool isSameUnderlyingObjectInLoop (const PHINode *PN, const LoopInfo *LI)
 PN defines a loop-variant pointer to an object.
 
static const ValuegetUnderlyingObjectFromInt (const Value *V)
 This is the function that does the work of looking through basic ptrtoint+arithmetic+inttoptr sequences.
 
static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper (const Value *V, bool AllowLifetime, bool AllowDroppable)
 
static OverflowResult mapOverflowResult (ConstantRange::OverflowResult OR)
 Convert ConstantRange OverflowResult into ValueTracking OverflowResult.
 
static OverflowResult computeOverflowForSignedAdd (const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const AddOperator *Add, const SimplifyQuery &SQ)
 
static bool shiftAmountKnownInRange (const Value *ShiftAmount)
 Shifts return poison if shiftwidth is larger than the bitwidth.
 
static bool includesPoison (UndefPoisonKind Kind)
 
static bool includesUndef (UndefPoisonKind Kind)
 
static bool canCreateUndefOrPoison (const Operator *Op, UndefPoisonKind Kind, bool ConsiderFlagsAndMetadata)
 
static bool directlyImpliesPoison (const Value *ValAssumedPoison, const Value *V, unsigned Depth)
 
static bool impliesPoison (const Value *ValAssumedPoison, const Value *V, unsigned Depth)
 
static bool programUndefinedIfUndefOrPoison (const Value *V, bool PoisonOnly)
 
static bool isGuaranteedNotToBeUndefOrPoison (const Value *V, AssumptionCache *AC, const Instruction *CtxI, const DominatorTree *DT, unsigned Depth, UndefPoisonKind Kind)
 
template<typename CallableT >
static bool handleGuaranteedWellDefinedOps (const Instruction *I, const CallableT &Handle)
 Enumerates all operands of I that are guaranteed to not be undef or poison.
 
template<typename CallableT >
static bool handleGuaranteedNonPoisonOps (const Instruction *I, const CallableT &Handle)
 Enumerates all operands of I that are guaranteed to not be poison.
 
static bool isKnownNonNaN (const Value *V, FastMathFlags FMF)
 
static bool isKnownNonZero (const Value *V)
 
static SelectPatternResult matchFastFloatClamp (CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS)
 Match clamp pattern for float types without care about NaNs or signed zeros.
 
static SelectPatternResult matchClamp (CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal)
 Recognize variations of: CLAMP(v,l,h) ==> ((v) < (l) ? (l) : ((v) > (h) ? (h) : (v)))
 
static SelectPatternResult matchMinMaxOfMinMax (CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TVal, Value *FVal, unsigned Depth)
 Recognize variations of: a < c ? min(a,b) : min(b,c) ==> min(min(a,b),min(b,c))
 
static ValuegetNotValue (Value *V)
 If the input value is the result of a 'not' op, constant integer, or vector splat of a constant integer, return the bitwise-not source value.
 
static SelectPatternResult matchMinMax (CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, unsigned Depth)
 Match non-obvious integer minimum and maximum sequences.
 
static SelectPatternResult matchSelectPattern (CmpInst::Predicate Pred, FastMathFlags FMF, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, unsigned Depth)
 
static ValuelookThroughCastConst (CmpInst *CmpI, Type *SrcTy, Constant *C, Instruction::CastOps *CastOp)
 
static ValuelookThroughCast (CmpInst *CmpI, Value *V1, Value *V2, Instruction::CastOps *CastOp)
 Helps to match a select pattern in case of a type mismatch.
 
static bool isTruePredicate (CmpInst::Predicate Pred, const Value *LHS, const Value *RHS)
 Return true if "icmp Pred LHS RHS" is always true.
 
static std::optional< boolisImpliedCondOperands (CmpInst::Predicate Pred, const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS)
 Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred ALHS ARHS" is true.
 
static std::optional< boolisImpliedCondMatchingOperands (CmpInst::Predicate LPred, CmpInst::Predicate RPred)
 Return true if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is true.
 
static std::optional< boolisImpliedCondCommonOperandWithCR (CmpInst::Predicate LPred, const ConstantRange &LCR, CmpInst::Predicate RPred, const ConstantRange &RCR)
 Return true if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is true.
 
static std::optional< boolisImpliedCondICmps (const ICmpInst *LHS, CmpInst::Predicate RPred, const Value *R0, const Value *R1, const DataLayout &DL, bool LHSIsTrue)
 Return true if LHS implies RHS (expanded to its components as "R0 RPred R1") is true.
 
static std::optional< boolisImpliedCondAndOr (const Instruction *LHS, CmpPredicate RHSPred, const Value *RHSOp0, const Value *RHSOp1, const DataLayout &DL, bool LHSIsTrue, unsigned Depth)
 Return true if LHS implies RHS is true.
 
static std::pair< Value *, boolgetDomPredecessorCondition (const Instruction *ContextI)
 
static void setLimitsForBinOp (const BinaryOperator &BO, APInt &Lower, APInt &Upper, const InstrInfoQuery &IIQ, bool PreferSignedRange)
 
static ConstantRange getRangeForIntrinsic (const IntrinsicInst &II)
 
static ConstantRange getRangeForSelectPattern (const SelectInst &SI, const InstrInfoQuery &IIQ)
 
static void setLimitForFPToI (const Instruction *I, APInt &Lower, APInt &Upper)
 
static void addValueAffectedByCondition (Value *V, function_ref< void(Value *)> InsertAffected)
 

Variables

static cl::opt< unsignedDomConditionsMaxUses ("dom-conditions-max-uses", cl::Hidden, cl::init(20))
 

Enumeration Type Documentation

◆ UndefPoisonKind

enum class UndefPoisonKind
strong
Enumerator
PoisonOnly 
UndefOnly 
UndefOrPoison 

Definition at line 7431 of file ValueTracking.cpp.

Function Documentation

◆ addValueAffectedByCondition()

static void addValueAffectedByCondition ( Value V,
function_ref< void(Value *)>  InsertAffected 
)
static

◆ BuildSubAggregate() [1/2]

static Value * BuildSubAggregate ( Value From,
ArrayRef< unsigned idx_range,
BasicBlock::iterator  InsertBefore 
)
static

◆ BuildSubAggregate() [2/2]

static Value * BuildSubAggregate ( Value From,
Value To,
Type IndexedType,
SmallVectorImpl< unsigned > &  Idxs,
unsigned  IdxSkip,
BasicBlock::iterator  InsertBefore 
)
static

◆ canCreateUndefOrPoison()

static bool canCreateUndefOrPoison ( const Operator Op,
UndefPoisonKind  Kind,
bool  ConsiderFlagsAndMetadata 
)
static

◆ cmpExcludesZero()

static bool cmpExcludesZero ( CmpInst::Predicate  Pred,
const Value RHS 
)
static

◆ computeKnownBits()

void computeKnownBits ( const Value V,
const APInt DemandedElts,
KnownBits Known,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Determine which bits of V are known to be either zero or one and return them in the Known bit set.

NOTE: we cannot consider 'undef' to be "IsZero" here. The problem is that we cannot optimize based on the assumption that it is zero without changing it to be an explicit zero. If we don't change it to zero, other code could optimized based on the contradictory assumption that it is non-zero. Because instcombine aggressively folds operations with undef args anyway, this won't lose us code quality.

This function is defined on values with integer type, values with pointer type, and vectors of integers. In the case where V is a vector, known zero, and known one values are the same width as the vector element, and the bit is set only if it is true for all of the demanded elements in the vector specified by DemandedElts.

Definition at line 2056 of file ValueTracking.cpp.

References A, assert(), llvm::BitWidth, llvm::CallingConv::C, computeKnownBits(), llvm::computeKnownBitsFromContext(), computeKnownBitsFromOperator(), llvm::Depth, llvm::SimplifyQuery::DL, llvm::Constant::getAggregateElement(), llvm::APInt::getBitWidth(), llvm::KnownBits::getBitWidth(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::Type::getScalarType(), llvm::DataLayout::getTypeSizeInBits(), llvm::KnownBits::hasConflict(), I, llvm::Type::isIntOrIntVectorTy(), llvm::Type::isPointerTy(), llvm::Type::isPtrOrPtrVectorTy(), llvm::Log2(), llvm::PatternMatch::m_APInt(), llvm::KnownBits::makeConstant(), llvm::PatternMatch::match(), llvm::MaxAnalysisRecursionDepth, llvm::KnownBits::One, Range, llvm::KnownBits::resetAll(), llvm::APInt::setAllBits(), llvm::KnownBits::setAllZero(), llvm::APInt::setLowBits(), llvm::ConstantRange::toKnownBits(), and llvm::KnownBits::Zero.

Referenced by computeKnownBits(), llvm::computeKnownBits(), computeKnownBitsAddSub(), computeKnownBitsForHorizontalOperation(), computeKnownBitsFromOperator(), computeKnownBitsFromShiftOperator(), computeKnownBitsMul(), ComputeNumSignBitsImpl(), getKnownBitsFromAndXorOr(), llvm::isKnownNegative(), isKnownNonEqual(), llvm::isKnownNonNegative(), isKnownNonZeroFromOperator(), llvm::isKnownPositive(), llvm::isKnownToBeAPowerOfTwo(), isNonZeroAdd(), isNonZeroMul(), isNonZeroShift(), and llvm::MaskedValueIsZero().

◆ computeKnownBitsAddSub()

static void computeKnownBitsAddSub ( bool  Add,
const Value Op0,
const Value Op1,
bool  NSW,
bool  NUW,
const APInt DemandedElts,
KnownBits KnownOut,
KnownBits Known2,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ computeKnownBitsForHorizontalOperation()

static KnownBits computeKnownBitsForHorizontalOperation ( const Operator I,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q,
const function_ref< KnownBits(const KnownBits &, const KnownBits &)>  KnownBitsFunc 
)
static

◆ computeKnownBitsFromCmp()

static void computeKnownBitsFromCmp ( const Value V,
CmpInst::Predicate  Pred,
Value LHS,
Value RHS,
KnownBits Known,
const SimplifyQuery Q 
)
static

◆ computeKnownBitsFromCond()

static void computeKnownBitsFromCond ( const Value V,
Value Cond,
KnownBits Known,
unsigned  Depth,
const SimplifyQuery SQ,
bool  Invert 
)
static

◆ computeKnownBitsFromICmpCond()

static void computeKnownBitsFromICmpCond ( const Value V,
ICmpInst Cmp,
KnownBits Known,
const SimplifyQuery SQ,
bool  Invert 
)
static

◆ computeKnownBitsFromOperator()

static void computeKnownBitsFromOperator ( const Operator I,
const APInt DemandedElts,
KnownBits Known,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Definition at line 1068 of file ValueTracking.cpp.

References llvm::KnownBits::abs(), llvm::SimplifyQuery::AC, llvm::KnownBits::add(), llvm::adjustKnownBitsForSelectArm(), llvm::KnownBits::anyextOrTrunc(), llvm::KnownBits::ashr(), assert(), llvm::bit_width(), llvm::APFloat::bitcastToAPInt(), llvm::BitWidth, llvm::APInt::byteSwap(), llvm::CallingConv::C, llvm::APInt::clearAllBits(), llvm::APInt::clearBit(), llvm::APInt::clearSignBit(), computeKnownBits(), computeKnownBitsAddSub(), computeKnownBitsForHorizontalOperation(), llvm::computeKnownBitsFromRangeMetadata(), computeKnownBitsFromShiftOperator(), computeKnownBitsMul(), computeKnownFPClass(), llvm::KnownBits::countMaxLeadingZeros(), llvm::KnownBits::countMaxPopulation(), llvm::KnownBits::countMaxTrailingZeros(), llvm::KnownBits::countMinLeadingOnes(), llvm::KnownBits::countMinLeadingZeros(), llvm::KnownBits::countMinTrailingZeros(), llvm::countr_zero(), llvm::SimplifyQuery::CxtI, llvm::RISCVVType::decodeVSEW(), llvm::Depth, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::fcAllFlags, llvm::fcInf, llvm::fcNan, llvm::fcNone, llvm::fcNormal, llvm::fcSubnormal, llvm::fcZero, llvm::gep_type_begin(), getAlign(), llvm::APInt::getAllOnes(), llvm::APInt::getBitWidth(), llvm::KnownBits::getBitWidth(), llvm::KnownBits::getConstant(), llvm::StructLayout::getElementOffset(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::ExtractValueInst::getIndices(), llvm::APFloat::getInf(), llvm::CmpInst::getInversePredicate(), getKnownBitsFromAndXorOr(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getKnownMinValue(), llvm::InstrInfoQuery::getMetadata(), llvm::ExtractValueInst::getNumIndices(), llvm::APInt::getOneBitSet(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::Type::getScalarType(), llvm::generic_gep_type_iterator< ItTy >::getSequentialElementStride(), llvm::RISCVVType::getSEWLMULRatio(), getShuffleDemandedElts(), llvm::Constant::getSplatValue(), llvm::DataLayout::getStructLayout(), llvm::generic_gep_type_iterator< ItTy >::getStructTypeOrNull(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), llvm::ConstantRange::getUnsignedMax(), llvm::getVScaleRange(), llvm::SimplifyQuery::getWithoutCondContext(), llvm::APInt::getZero(), llvm::APInt::getZExtValue(), llvm::KnownBits::hasConflict(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), I, Idx, II, llvm::SimplifyQuery::IIQ, llvm::KnownBits::insertBits(), llvm::KnownBits::intersectWith(), llvm::KnownBits::isConstant(), llvm::InstrInfoQuery::isExact(), llvm::isGuaranteedNotToBePoison(), llvm::Type::isIntOrPtrTy(), llvm::DataLayout::isLittleEndian(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm::Type::isPointerTy(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), llvm::Type::isSized(), llvm::KnownBits::isUnknown(), llvm::Type::isVectorTy(), llvm::APInt::isZero(), llvm::Constant::isZeroValue(), LHS, llvm::Log2(), llvm::Log2_32(), llvm::KnownBits::lshr(), llvm::APInt::lshr(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BasicBlock(), llvm::PatternMatch::m_Br(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::KnownBits::makeConstant(), llvm::ConstantRange::makeExactICmpRegion(), llvm::KnownBits::makeNegative(), llvm::KnownBits::makeNonNegative(), llvm::PatternMatch::match(), llvm::matchSimpleRecurrence(), llvm::MaxAnalysisRecursionDepth, llvm::KnownBits::mul(), llvm::KnownBits::mulhs(), llvm::KnownBits::mulhu(), llvm::Offset, llvm::KnownBits::One, P, Range, llvm::KnownBits::resetAll(), llvm::APInt::reverseBits(), RHS, llvm::RISCV::RVVBitsPerBlock, llvm::KnownBits::sadd_sat(), llvm::KnownBits::sdiv(), llvm::APInt::setAllBits(), llvm::APInt::setBit(), llvm::APInt::setBitsFrom(), llvm::APInt::setHighBits(), llvm::APInt::setLowBits(), llvm::KnownBits::sext(), llvm::KnownBits::sextOrTrunc(), llvm::APInt::sextOrTrunc(), llvm::KnownBits::shl(), llvm::APInt::shl(), llvm::KnownBits::smax(), llvm::KnownBits::smin(), llvm::KnownBits::srem(), llvm::KnownBits::ssub_sat(), llvm::KnownBits::sub(), llvm::ConstantRange::toKnownBits(), llvm::KnownBits::trunc(), llvm::KnownBits::uadd_sat(), llvm::KnownBits::udiv(), llvm::KnownBits::umax(), llvm::KnownBits::umin(), llvm::KnownBits::unionWith(), llvm::APInt::urem(), llvm::KnownBits::urem(), llvm::KnownBits::usub_sat(), llvm::KnownBits::Zero, and llvm::KnownBits::zextOrTrunc().

Referenced by computeKnownBits().

◆ computeKnownBitsFromShiftOperator()

static void computeKnownBitsFromShiftOperator ( const Operator I,
const APInt DemandedElts,
KnownBits Known,
KnownBits Known2,
unsigned  Depth,
const SimplifyQuery Q,
function_ref< KnownBits(const KnownBits &, const KnownBits &, bool)>  KF 
)
static

Compute known bits from a shift operator, including those with a non-constant shift amount.

Known is the output of this function. Known2 is a pre-allocated temporary with the same bit width as Known and on return contains the known bit of the shift value source. KF is an operator-specific function that, given the known-bits and a shift amount, compute the implied known-bits of the shift operator's result respectively for that shift amount. The results from calling KF are conservatively combined for all permitted shift amounts.

Definition at line 889 of file ValueTracking.cpp.

References computeKnownBits(), llvm::Depth, llvm::KnownBits::getBitWidth(), llvm::KnownBits::getMaxValue(), I, isKnownNonZero(), llvm::KnownBits::isNonZero(), and llvm::APInt::ult().

Referenced by computeKnownBitsFromOperator().

◆ computeKnownBitsMul()

static void computeKnownBitsMul ( const Value Op0,
const Value Op1,
bool  NSW,
bool  NUW,
const APInt DemandedElts,
KnownBits Known,
KnownBits Known2,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ computeKnownFPClass() [1/2]

void computeKnownFPClass ( const Value V,
const APInt DemandedElts,
FPClassTest  InterestedClasses,
KnownFPClass Known,
unsigned  Depth,
const SimplifyQuery Q 
)

Definition at line 5009 of file ValueTracking.cpp.

References llvm::SimplifyQuery::AC, assert(), llvm::APFloat::bitcastToAPInt(), llvm::BitWidth, llvm::CallingConv::C, llvm::KnownFPClass::cannotBeOrderedGreaterThanZero(), llvm::KnownFPClass::cannotBeOrderedLessThanZero(), llvm::APInt::clearBit(), llvm::computeConstantRange(), llvm::computeKnownBits(), llvm::computeKnownFPClass(), computeKnownFPClassForFPTrunc(), computeKnownFPClassFromContext(), Cond, llvm::KnownFPClass::copysign(), llvm::SimplifyQuery::CxtI, llvm::Depth, llvm::SimplifyQuery::DT, llvm::KnownBits::eq(), F, llvm::KnownFPClass::fabs(), llvm::fcAllFlags, llvm::fcInf, llvm::fcmpImpliesClass(), llvm::fcNan, llvm::fcNegative, llvm::fcNegFinite, llvm::fcNegInf, llvm::fcNegNormal, llvm::fcNegSubnormal, llvm::fcNegZero, llvm::fcNone, llvm::fcPosFinite, llvm::fcPosInf, llvm::fcPositive, llvm::fcPosNormal, llvm::fcPosSubnormal, llvm::fcPosZero, llvm::fcQNan, llvm::fcSNan, llvm::fcSubnormal, llvm::fcZero, llvm::First, Flt, llvm::KnownFPClass::fneg(), llvm::Constant::getAggregateElement(), llvm::ExtractValueInst::getAggregateOperand(), llvm::APInt::getAllOnes(), llvm::APInt::getBitWidth(), llvm::Function::getDenormalMode(), llvm::Type::getFltSemantics(), llvm::DenormalMode::getIEEE(), llvm::ExtractValueInst::getIndices(), llvm::APFloat::getInf(), llvm::Type::getIntegerBitWidth(), llvm::APFloat::getLargest(), llvm::APInt::getOneBitSet(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::getShuffleDemandedElts(), llvm::ConstantRange::getSignedMin(), llvm::ConstantRange::getSingleElement(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::SimplifyQuery::getWithoutCondContext(), llvm::APFloat::getZero(), llvm::InstrInfoQuery::hasNoSignedZeros(), Idx, llvm::DenormalMode::IEEE, II, llvm::SimplifyQuery::IIQ, llvm::DenormalMode::Input, llvm::DenormalMode::inputsAreZero(), llvm::ConstantRange::isAllNegative(), llvm::ConstantRange::isAllNonNegative(), llvm::Type::isIEEE(), llvm::KnownFPClass::isKnownNever(), llvm::KnownFPClass::isKnownNeverInfinity(), llvm::KnownFPClass::isKnownNeverLogicalNegZero(), llvm::KnownFPClass::isKnownNeverLogicalPosZero(), llvm::KnownFPClass::isKnownNeverLogicalZero(), llvm::KnownFPClass::isKnownNeverNaN(), llvm::KnownFPClass::isKnownNeverNegInfinity(), llvm::KnownFPClass::isKnownNeverNegSubnormal(), llvm::KnownFPClass::isKnownNeverNegZero(), llvm::KnownFPClass::isKnownNeverPosInfinity(), llvm::KnownFPClass::isKnownNeverPosSubnormal(), llvm::KnownFPClass::isKnownNeverPosZero(), llvm::KnownFPClass::isKnownNeverSubnormal(), llvm::APFloat::isNaN(), llvm::APFloatBase::isRepresentableAsNormalIn(), llvm::KnownFPClass::isUnknown(), llvm::APInt::isZero(), llvm::KnownFPClass::KnownFPClasses, llvm::KnownFPClass::knownNot(), LHS, llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_FCmp(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::make_scope_exit(), llvm::KnownBits::makeConstant(), llvm::PatternMatch::match(), llvm::MaxAnalysisRecursionDepth, llvm::KnownFPClass::OrderedGreaterThanZeroMask, llvm::KnownFPClass::OrderedLessThanZeroMask, llvm::DenormalMode::Output, outputDenormalIsIEEEOrPosZero(), llvm::DenormalMode::outputsAreZero(), P, llvm::DenormalMode::PositiveZero, llvm::KnownFPClass::propagateCanonicalizingSrc(), llvm::KnownFPClass::propagateNaN(), llvm::KnownFPClass::resetAll(), llvm::APInt::reverseBits(), RHS, llvm::APFloatBase::semanticsPrecision(), llvm::APInt::sge(), llvm::KnownFPClass::SignBit, llvm::KnownFPClass::signBitMustBeOne(), llvm::KnownFPClass::signBitMustBeZero(), llvm::ArrayRef< T >::size(), llvm::InstrInfoQuery::UseInstrInfo, and llvm::KnownBits::Zero.

Referenced by computeKnownBitsFromOperator().

◆ computeKnownFPClass() [2/2]

static void computeKnownFPClass ( const Value V,
KnownFPClass Known,
FPClassTest  InterestedClasses,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ computeKnownFPClassForFPTrunc()

static void computeKnownFPClassForFPTrunc ( const Operator Op,
const APInt DemandedElts,
FPClassTest  InterestedClasses,
KnownFPClass Known,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ computeKnownFPClassFromCond()

static void computeKnownFPClassFromCond ( const Value V,
Value Cond,
unsigned  Depth,
bool  CondIsTrue,
const Instruction CxtI,
KnownFPClass KnownFromContext 
)
static

◆ computeKnownFPClassFromContext()

static KnownFPClass computeKnownFPClassFromContext ( const Value V,
const SimplifyQuery Q 
)
static

◆ ComputeNumSignBits() [1/2]

static unsigned ComputeNumSignBits ( const Value V,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ ComputeNumSignBits() [2/2]

static unsigned ComputeNumSignBits ( const Value V,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Definition at line 330 of file ValueTracking.cpp.

References ComputeNumSignBits(), llvm::Depth, and llvm::APInt::getAllOnes().

◆ ComputeNumSignBitsImpl()

static unsigned ComputeNumSignBitsImpl ( const Value V,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Return the number of times the sign bit of the register is replicated into the other bits.

We know that at least 1 bit is always equal to the sign bit (itself), but other cases can give us information. For example, immediately after an "ashr X, 2", we know that the top 3 bits are all equal to each other, so we return 3. For vectors, return the number of sign bits for the vector element with the minimum number of known sign bits of the demanded elements in the vector specified by DemandedElts.

Definition at line 3848 of file ValueTracking.cpp.

References assert(), llvm::APInt::ceilLogBase2(), computeKnownBits(), ComputeNumSignBits(), computeNumSignBitsVectorConstant(), llvm::KnownBits::countMinSignBits(), llvm::SimplifyQuery::CxtI, llvm::Depth, llvm::SimplifyQuery::DL, llvm::APInt::getBitWidth(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::APInt::getNumSignBits(), llvm::Operator::getOpcode(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::Type::getScalarType(), getShuffleDemandedElts(), llvm::BasicBlock::getTerminator(), llvm::DataLayout::getTypeSizeInBits(), llvm::SimplifyQuery::getWithoutCondContext(), llvm::APInt::getZExtValue(), II, llvm::KnownBits::isNonNegative(), llvm::Type::isPointerTy(), isSignedMinMaxClamp(), isSignedMinMaxIntrinsicClamp(), llvm::APInt::isStrictlyPositive(), LHS, llvm::APInt::logBase2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::MaxAnalysisRecursionDepth, RHS, llvm::APInt::uge(), X, and llvm::KnownBits::Zero.

Referenced by ComputeNumSignBits().

◆ computeNumSignBitsVectorConstant()

static unsigned computeNumSignBitsVectorConstant ( const Value V,
const APInt DemandedElts,
unsigned  TyBits 
)
static

For vector constants, loop over the elements and find the constant with the minimum number of sign bits.

Return 0 if the value is not a vector constant or if any element was not analyzed; otherwise, return the count for the element with the minimum number of sign bits.

Definition at line 3807 of file ValueTracking.cpp.

Referenced by ComputeNumSignBitsImpl().

◆ computeOverflowForSignedAdd()

static OverflowResult computeOverflowForSignedAdd ( const WithCache< const Value * > &  LHS,
const WithCache< const Value * > &  RHS,
const AddOperator Add,
const SimplifyQuery SQ 
)
static

◆ directlyImpliesPoison()

static bool directlyImpliesPoison ( const Value ValAssumedPoison,
const Value V,
unsigned  Depth 
)
static

◆ exactClass()

static std::tuple< Value *, FPClassTest, FPClassTest > exactClass ( Value V,
FPClassTest  M 
)
static

Return the return value for fcmpImpliesClass for a compare that produces an exact class test.

Definition at line 4495 of file ValueTracking.cpp.

Referenced by llvm::fcmpImpliesClass().

◆ getBitWidth()

static unsigned getBitWidth ( Type Ty,
const DataLayout DL 
)
static

◆ getDomPredecessorCondition()

static std::pair< Value *, bool > getDomPredecessorCondition ( const Instruction ContextI)
static

◆ getInvertibleOperands()

static std::optional< std::pair< Value *, Value * > > getInvertibleOperands ( const Operator Op1,
const Operator Op2 
)
static

If the pair of operators are the same invertible function, return the the operands of the function corresponding to each input.

Otherwise, return std::nullopt. An invertible function is one that is 1-to-1 and maps every input value to exactly one output value. This is equivalent to saying that Op1 and Op2 are equal exactly when the specified pair of operands are equal, (except that Op1 and Op2 may be poison more often.)

Definition at line 3405 of file ValueTracking.cpp.

References getInvertibleOperands(), llvm::Operator::getOpcode(), llvm::User::getOperand(), getOperands(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Value::getType(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::matchSimpleRecurrence(), and Other.

Referenced by getInvertibleOperands(), and isKnownNonEqual().

◆ getKnownBitsFromAndXorOr()

static KnownBits getKnownBitsFromAndXorOr ( const Operator I,
const APInt DemandedElts,
const KnownBits KnownLHS,
const KnownBits KnownRHS,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ getNotValue()

static Value * getNotValue ( Value V)
static

If the input value is the result of a 'not' op, constant integer, or vector splat of a constant integer, return the bitwise-not source value.

TODO: This could be extended to handle non-splat vector integer constants.

Definition at line 8458 of file ValueTracking.cpp.

References llvm::CallingConv::C, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().

Referenced by matchMinMax().

◆ getRangeForIntrinsic()

static ConstantRange getRangeForIntrinsic ( const IntrinsicInst II)
static

◆ getRangeForSelectPattern()

static ConstantRange getRangeForSelectPattern ( const SelectInst SI,
const InstrInfoQuery IIQ 
)
static

◆ getShuffleDemandedElts()

static bool getShuffleDemandedElts ( const ShuffleVectorInst Shuf,
const APInt DemandedElts,
APInt DemandedLHS,
APInt DemandedRHS 
)
static

◆ GetStringLengthH()

static uint64_t GetStringLengthH ( const Value V,
SmallPtrSetImpl< const PHINode * > &  PHIs,
unsigned  CharSize 
)
static

◆ getUnderlyingObjectFromInt()

static const Value * getUnderlyingObjectFromInt ( const Value V)
static

This is the function that does the work of looking through basic ptrtoint+arithmetic+inttoptr sequences.

Definition at line 6870 of file ValueTracking.cpp.

References assert(), and llvm::Operator::getOpcode().

Referenced by llvm::getUnderlyingObjectsForCodeGen().

◆ handleGuaranteedNonPoisonOps()

template<typename CallableT >
static bool handleGuaranteedNonPoisonOps ( const Instruction I,
const CallableT &  Handle 
)
static

Enumerates all operands of I that are guaranteed to not be poison.

Definition at line 8096 of file ValueTracking.cpp.

References handleGuaranteedWellDefinedOps(), and I.

Referenced by llvm::getGuaranteedNonPoisonOps(), and llvm::mustTriggerUB().

◆ handleGuaranteedWellDefinedOps()

template<typename CallableT >
static bool handleGuaranteedWellDefinedOps ( const Instruction I,
const CallableT &  Handle 
)
static

Enumerates all operands of I that are guaranteed to not be undef or poison.

If the callback Handle returns true, stop processing and return true. Otherwise, return false.

Definition at line 8026 of file ValueTracking.cpp.

References llvm::CallBase::arg_size(), llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledOperand(), llvm::getPointerOperand(), I, llvm::CallBase::isIndirectCall(), and llvm::CallBase::paramHasAttr().

Referenced by llvm::getGuaranteedWellDefinedOps(), handleGuaranteedNonPoisonOps(), and programUndefinedIfUndefOrPoison().

◆ haveNoCommonBitsSetSpecialCases()

static bool haveNoCommonBitsSetSpecialCases ( const Value LHS,
const Value RHS,
const SimplifyQuery SQ 
)
static

◆ impliesPoison()

static bool impliesPoison ( const Value ValAssumedPoison,
const Value V,
unsigned  Depth 
)
static

◆ includesPoison()

static bool includesPoison ( UndefPoisonKind  Kind)
static

Definition at line 7437 of file ValueTracking.cpp.

Referenced by canCreateUndefOrPoison(), and isGuaranteedNotToBeUndefOrPoison().

◆ includesUndef()

static bool includesUndef ( UndefPoisonKind  Kind)
static

Definition at line 7441 of file ValueTracking.cpp.

Referenced by isGuaranteedNotToBeUndefOrPoison().

◆ inputDenormalIsIEEE()

static bool inputDenormalIsIEEE ( const Function F,
const Type Ty 
)
static

Return true if it's possible to assume IEEE treatment of input denormals in F for Val.

Definition at line 4340 of file ValueTracking.cpp.

References F, llvm::Type::getFltSemantics(), llvm::Type::getScalarType(), and llvm::DenormalMode::IEEE.

Referenced by llvm::fcmpImpliesClass(), fpclassTestIsFCmp0(), and llvm::KnownFPClass::isKnownNeverLogicalZero().

◆ inputDenormalIsIEEEOrPosZero()

static bool inputDenormalIsIEEEOrPosZero ( const Function F,
const Type Ty 
)
static

◆ isEphemeralValueOf()

static bool isEphemeralValueOf ( const Instruction I,
const Value E 
)
static

◆ isGEPKnownNonNull()

static bool isGEPKnownNonNull ( const GEPOperator GEP,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Test whether a GEP's result is known to be non-null.

Uses properties inherent in a GEP to try to determine whether it is known to be non-null.

Currently this routine does not support vector GEPs.

Definition at line 2478 of file ValueTracking.cpp.

References assert(), llvm::Depth, llvm::SimplifyQuery::DL, F, GEP, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::StructLayout::getElementOffset(), llvm::DataLayout::getStructLayout(), llvm::ConstantInt::getZExtValue(), I, isKnownNonZero(), llvm::MaxAnalysisRecursionDepth, and llvm::NullPointerIsDefined().

Referenced by isKnownNonZeroFromOperator().

◆ isGuaranteedNotToBeUndefOrPoison()

static bool isGuaranteedNotToBeUndefOrPoison ( const Value V,
AssumptionCache AC,
const Instruction CtxI,
const DominatorTree DT,
unsigned  Depth,
UndefPoisonKind  Kind 
)
static

◆ isImpliedCondAndOr()

static std::optional< bool > isImpliedCondAndOr ( const Instruction LHS,
CmpPredicate  RHSPred,
const Value RHSOp0,
const Value RHSOp1,
const DataLayout DL,
bool  LHSIsTrue,
unsigned  Depth 
)
static

Return true if LHS implies RHS is true.

Return false if LHS implies RHS is false. Otherwise, return std::nullopt if we can't infer anything. We expect the RHS to be an icmp and the LHS to be an 'and', 'or', or a 'select' instruction.

Definition at line 9422 of file ValueTracking.cpp.

References assert(), llvm::Depth, DL, llvm::isImpliedCondition(), LHS, llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::MaxAnalysisRecursionDepth.

Referenced by llvm::isImpliedCondition().

◆ isImpliedCondCommonOperandWithCR()

static std::optional< bool > isImpliedCondCommonOperandWithCR ( CmpInst::Predicate  LPred,
const ConstantRange LCR,
CmpInst::Predicate  RPred,
const ConstantRange RCR 
)
static

Return true if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is true.

Return false if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is false. Otherwise, return std::nullopt if we can't infer anything.

Definition at line 9306 of file ValueTracking.cpp.

References llvm::CmpInst::getInversePredicate(), llvm::ConstantRange::icmp(), and llvm::ConstantRange::makeAllowedICmpRegion().

Referenced by isImpliedCondICmps().

◆ isImpliedCondICmps()

static std::optional< bool > isImpliedCondICmps ( const ICmpInst LHS,
CmpInst::Predicate  RPred,
const Value R0,
const Value R1,
const DataLayout DL,
bool  LHSIsTrue 
)
static

◆ isImpliedCondMatchingOperands()

static std::optional< bool > isImpliedCondMatchingOperands ( CmpInst::Predicate  LPred,
CmpInst::Predicate  RPred 
)
static

Return true if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is true.

Return false if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is false. Otherwise, return std::nullopt if we can't infer anything.

Definition at line 9293 of file ValueTracking.cpp.

References llvm::CmpInst::isImpliedFalseByMatchingCmp(), and llvm::CmpInst::isImpliedTrueByMatchingCmp().

Referenced by isImpliedCondICmps().

◆ isImpliedCondOperands()

static std::optional< bool > isImpliedCondOperands ( CmpInst::Predicate  Pred,
const Value ALHS,
const Value ARHS,
const Value BLHS,
const Value BRHS 
)
static

Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred ALHS ARHS" is true.

Otherwise, return std::nullopt.

Definition at line 9253 of file ValueTracking.cpp.

References llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, and isTruePredicate().

Referenced by isImpliedCondICmps().

◆ isImpliedToBeAPowerOfTwoFromCond()

static bool isImpliedToBeAPowerOfTwoFromCond ( const Value V,
bool  OrZero,
const Value Cond,
bool  CondIsTrue 
)
static

Return true if we can infer that V is known to be a power of 2 from dominating condition Cond (e.g., ctpop(V) == 1).

Definition at line 2255 of file ValueTracking.cpp.

References Cond, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), and llvm::PatternMatch::match().

Referenced by llvm::isKnownToBeAPowerOfTwo().

◆ isKnownNonEqual()

static bool isKnownNonEqual ( const Value V1,
const Value V2,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ isKnownNonNaN()

static bool isKnownNonNaN ( const Value V,
FastMathFlags  FMF 
)
static

Definition at line 8232 of file ValueTracking.cpp.

References llvm::CallingConv::C, I, and llvm::FastMathFlags::noNaNs().

Referenced by matchSelectPattern().

◆ isKnownNonNullFromDominatingCondition()

static bool isKnownNonNullFromDominatingCondition ( const Value V,
const Instruction CtxI,
const DominatorTree DT 
)
static

◆ isKnownNonZero() [1/2]

static bool isKnownNonZero ( const Value V)
static

Definition at line 8255 of file ValueTracking.cpp.

References llvm::CallingConv::C, and I.

◆ isKnownNonZero() [2/2]

bool isKnownNonZero ( const Value V,
const APInt DemandedElts,
const SimplifyQuery Q,
unsigned  Depth 
)
static

Return true if the given value is known to be non-zero when defined.

For vectors, return true if every demanded element is known to be non-zero when defined. For pointers, if the context instruction and dominator tree are specified, perform context-sensitive analysis and return true if the pointer couldn't possibly be null at the specified instruction. Supports values with integer or pointer type and vectors of integers.

Definition at line 3295 of file ValueTracking.cpp.

References A, assert(), llvm::CallingConv::C, llvm::ConstantRange::contains(), llvm::SimplifyQuery::CxtI, llvm::Depth, llvm::SimplifyQuery::DT, llvm::APInt::getBitWidth(), llvm::ConstantRange::getBitWidth(), I, isKnownNonNullFromDominatingCondition(), isKnownNonZero(), isKnownNonZeroFromAssume(), isKnownNonZeroFromOperator(), llvm::Constant::isNullValue(), llvm::MaxAnalysisRecursionDepth, llvm::NullPointerIsDefined(), and Range.

Referenced by computeKnownBitsFromShiftOperator(), isGEPKnownNonNull(), isKnownNonZero(), isKnownNonZeroFromOperator(), llvm::isKnownPositive(), llvm::isKnownToBeAPowerOfTwo(), isModifyingBinopOfNonZero(), isNonEqualMul(), isNonEqualShl(), isNonZeroAdd(), isNonZeroMul(), isNonZeroShift(), and isNonZeroSub().

◆ isKnownNonZeroFromAssume()

static bool isKnownNonZeroFromAssume ( const Value V,
const SimplifyQuery Q 
)
static

◆ isKnownNonZeroFromOperator()

static bool isKnownNonZeroFromOperator ( const Operator I,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Definition at line 2832 of file ValueTracking.cpp.

References llvm::KnownBits::abs(), llvm::SimplifyQuery::AC, llvm::all_of(), llvm::BitWidth, llvm::APInt::clearBit(), cmpExcludesZero(), computeKnownBits(), llvm::ConstantRange::contains(), llvm::SimplifyQuery::CxtI, llvm::Depth, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::APInt::getAllOnes(), llvm::CallBase::getArgOperand(), llvm::getArgumentAliasingToReturnedPointer(), llvm::BinaryOpIntrinsic::getBinaryOp(), llvm::APInt::getBitWidth(), llvm::ConstantRange::getBitWidth(), getBitWidth(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::InstrInfoQuery::getMetadata(), llvm::APInt::getOneBitSet(), llvm::Type::getScalarType(), getShuffleDemandedElts(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), llvm::SimplifyQuery::getWithoutCondContext(), llvm::APInt::getZero(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), I, Idx, II, llvm::SimplifyQuery::IIQ, llvm::PossiblyExactOperator::isExact(), isGEPKnownNonNull(), llvm::isGuaranteedNotToBePoison(), llvm::Type::isIntOrIntVectorTy(), isKnownNonZero(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm::KnownBits::isNonZero(), isNonZeroAdd(), isNonZeroMul(), isNonZeroRecurrence(), isNonZeroShift(), isNonZeroSub(), llvm::Type::isPtrOrPtrVectorTy(), llvm::KnownBits::isUnknown(), llvm::APInt::isZero(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_WithOverflowInst(), llvm::PatternMatch::match(), matchOpWithOpEqZero(), llvm::MaxAnalysisRecursionDepth, llvm::NullPointerIsDefined(), llvm::KnownBits::One, Range, rangeMetadataExcludesValue(), llvm::APInt::reverseBits(), llvm::KnownBits::uge(), llvm::InstrInfoQuery::UseInstrInfo, and X.

Referenced by isKnownNonZero().

◆ isModifyingBinopOfNonZero()

static bool isModifyingBinopOfNonZero ( const Value V1,
const Value V2,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Return true if V1 == (binop V2, X), where X is known non-zero.

Only handle a small subset of binops where (binop V2, X) with non-zero X implies V2 != V1.

Definition at line 3521 of file ValueTracking.cpp.

References llvm::Depth, llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), and isKnownNonZero().

Referenced by isKnownNonEqual().

◆ isNonEqualMul()

static bool isNonEqualMul ( const Value V1,
const Value V2,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Return true if V2 == V1 * C, where V1 is known non-zero, C is not 0/1 and the multiplication is nuw or nsw.

Definition at line 3550 of file ValueTracking.cpp.

References llvm::CallingConv::C, llvm::Depth, isKnownNonZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Specific(), and llvm::PatternMatch::match().

Referenced by isKnownNonEqual().

◆ isNonEqualPHIs()

static bool isNonEqualPHIs ( const PHINode PN1,
const PHINode PN2,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ isNonEqualPointersWithRecursiveGEP()

static bool isNonEqualPointersWithRecursiveGEP ( const Value A,
const Value B,
const SimplifyQuery Q 
)
static

◆ isNonEqualSelect()

static bool isNonEqualSelect ( const Value V1,
const Value V2,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

◆ isNonEqualShl()

static bool isNonEqualShl ( const Value V1,
const Value V2,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q 
)
static

Return true if V2 == V1 << C, where V1 is known non-zero, C is not 0 and the shift is nuw or nsw.

Definition at line 3565 of file ValueTracking.cpp.

References llvm::CallingConv::C, llvm::Depth, isKnownNonZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), and llvm::PatternMatch::match().

Referenced by isKnownNonEqual().

◆ isNonZeroAdd()

static bool isNonZeroAdd ( const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q,
unsigned  BitWidth,
Value X,
Value Y,
bool  NSW,
bool  NUW 
)
static

◆ isNonZeroMul()

static bool isNonZeroMul ( const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q,
unsigned  BitWidth,
Value X,
Value Y,
bool  NSW,
bool  NUW 
)
static

◆ isNonZeroRecurrence()

static bool isNonZeroRecurrence ( const PHINode PN)
static

Try to detect a recurrence that monotonically increases/decreases from a non-zero starting value.

These are common as induction variables.

Definition at line 2656 of file ValueTracking.cpp.

References llvm::BinaryOperator::getOpcode(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Instruction::isExact(), llvm::APInt::isNegative(), llvm::APInt::isZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), and llvm::matchSimpleRecurrence().

Referenced by isKnownNonZeroFromOperator().

◆ isNonZeroShift()

static bool isNonZeroShift ( const Operator I,
const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q,
const KnownBits KnownVal 
)
static

◆ isNonZeroSub()

static bool isNonZeroSub ( const APInt DemandedElts,
unsigned  Depth,
const SimplifyQuery Q,
unsigned  BitWidth,
Value X,
Value Y 
)
static

◆ isPowerOfTwoRecurrence()

static bool isPowerOfTwoRecurrence ( const PHINode PN,
bool  OrZero,
unsigned  Depth,
SimplifyQuery Q 
)
static

◆ isSameUnderlyingObjectInLoop()

static bool isSameUnderlyingObjectInLoop ( const PHINode PN,
const LoopInfo LI 
)
static

PN defines a loop-variant pointer to an object.

Check if the previous iteration of the loop was referring to the same object as PN.

Definition at line 6712 of file ValueTracking.cpp.

References llvm::PHINode::getIncomingValue(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::PHINode::getNumIncomingValues(), and llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent().

Referenced by llvm::getUnderlyingObjects().

◆ isSignedMinMaxClamp()

static bool isSignedMinMaxClamp ( const Value Select,
const Value *&  In,
const APInt *&  CLow,
const APInt *&  CHigh 
)
static

◆ isSignedMinMaxIntrinsicClamp()

static bool isSignedMinMaxIntrinsicClamp ( const IntrinsicInst II,
const APInt *&  CLow,
const APInt *&  CHigh 
)
static

◆ isTruePredicate()

static bool isTruePredicate ( CmpInst::Predicate  Pred,
const Value LHS,
const Value RHS 
)
static

◆ lookThroughCast()

static Value * lookThroughCast ( CmpInst CmpI,
Value V1,
Value V2,
Instruction::CastOps CastOp 
)
static

Helps to match a select pattern in case of a type mismatch.

The function processes the case when type of true and false values of a select instruction differs from type of the cmp instruction operands because of a cast instruction. The function checks if it is legal to move the cast operation after "select". If yes, it returns the new second value of "select" (with the assumption that cast is moved):

  1. As operand of cast instruction when both values of "select" are same cast instructions.
  2. As restored constant (by applying reverse cast operation) when the first value of the "select" is a cast operation and the second value is a constant. It is implemented in lookThroughCastConst().
  3. As one operand is cast instruction and the other is not. The operands in sel(cmp) are in different type integer. NOTE: We return only the new second value because the first value could be accessed as operand of cast instruction.

Definition at line 8901 of file ValueTracking.cpp.

References assert(), llvm::CallingConv::C, llvm::User::getOperand(), lookThroughCastConst(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_ZExtOrSExt(), and llvm::PatternMatch::match().

Referenced by llvm::matchDecomposedSelectPattern().

◆ lookThroughCastConst()

static Value * lookThroughCastConst ( CmpInst CmpI,
Type SrcTy,
Constant C,
Instruction::CastOps CastOp 
)
static

◆ mapOverflowResult()

static OverflowResult mapOverflowResult ( ConstantRange::OverflowResult  OR)
static

◆ matchClamp()

static SelectPatternResult matchClamp ( CmpInst::Predicate  Pred,
Value CmpLHS,
Value CmpRHS,
Value TrueVal,
Value FalseVal 
)
static

◆ matchFastFloatClamp()

static SelectPatternResult matchFastFloatClamp ( CmpInst::Predicate  Pred,
Value CmpLHS,
Value CmpRHS,
Value TrueVal,
Value FalseVal,
Value *&  LHS,
Value *&  RHS 
)
static

◆ matchMinMax()

static SelectPatternResult matchMinMax ( CmpInst::Predicate  Pred,
Value CmpLHS,
Value CmpRHS,
Value TrueVal,
Value FalseVal,
Value *&  LHS,
Value *&  RHS,
unsigned  Depth 
)
static

◆ matchMinMaxOfMinMax()

static SelectPatternResult matchMinMaxOfMinMax ( CmpInst::Predicate  Pred,
Value CmpLHS,
Value CmpRHS,
Value TVal,
Value FVal,
unsigned  Depth 
)
static

◆ matchOpWithOpEqZero()

static bool matchOpWithOpEqZero ( Value Op0,
Value Op1 
)
static

◆ matchSelectPattern()

static SelectPatternResult matchSelectPattern ( CmpInst::Predicate  Pred,
FastMathFlags  FMF,
Value CmpLHS,
Value CmpRHS,
Value TrueVal,
Value FalseVal,
Value *&  LHS,
Value *&  RHS,
unsigned  Depth 
)
static

◆ onlyUsedByLifetimeMarkersOrDroppableInstsHelper()

static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper ( const Value V,
bool  AllowLifetime,
bool  AllowDroppable 
)
static

◆ outputDenormalIsIEEEOrPosZero()

static bool outputDenormalIsIEEEOrPosZero ( const Function F,
const Type Ty 
)
static

◆ programUndefinedIfUndefOrPoison()

static bool programUndefinedIfUndefOrPoison ( const Value V,
bool  PoisonOnly 
)
static

◆ rangeMetadataExcludesValue()

static bool rangeMetadataExcludesValue ( const MDNode Ranges,
const APInt Value 
)
static

Does the 'Range' metadata (which must be a valid MD_range operand list) ensure that the value it's attached to is never Value? 'RangeType' is is the type of the value described by the range.

Definition at line 2639 of file ValueTracking.cpp.

References assert(), llvm::ConstantRange::contains(), llvm::Lower, Range, and llvm::Upper.

Referenced by isKnownNonZeroFromOperator().

◆ safeCxtI() [1/2]

static const Instruction * safeCxtI ( const Value V,
const Instruction CxtI 
)
static

◆ safeCxtI() [2/2]

static const Instruction * safeCxtI ( const Value V1,
const Value V2,
const Instruction CxtI 
)
static

◆ setLimitForFPToI()

static void setLimitForFPToI ( const Instruction I,
APInt Lower,
APInt Upper 
)
static

Definition at line 9947 of file ValueTracking.cpp.

References llvm::BitWidth, I, llvm::Lower, and llvm::Upper.

Referenced by llvm::computeConstantRange().

◆ setLimitsForBinOp()

static void setLimitsForBinOp ( const BinaryOperator BO,
APInt Lower,
APInt Upper,
const InstrInfoQuery IIQ,
bool  PreferSignedRange 
)
static

◆ shiftAmountKnownInRange()

static bool shiftAmountKnownInRange ( const Value ShiftAmount)
static

Shifts return poison if shiftwidth is larger than the bitwidth.

Definition at line 7407 of file ValueTracking.cpp.

References llvm::all_of(), llvm::CallingConv::C, and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by canCreateUndefOrPoison().

Variable Documentation

◆ DomConditionsMaxUses

cl::opt< unsigned > DomConditionsMaxUses("dom-conditions-max-uses", cl::Hidden, cl::init(20)) ( "dom-conditions-max-uses"  ,
cl::Hidden  ,
cl::init(20)   
)
static