LLVM 22.0.0git
InstructionSimplify.cpp File Reference

Go to the source code of this file.

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.

Macros

#define DEBUG_TYPE   "instsimplify"
#define HANDLE_CAST_INST(num, opc, clas)

Enumerations

enum  { RecursionLimit = 3 }
enum class  MonotonicType { GreaterEq , LowerEq }

Functions

 STATISTIC (NumExpand, "Number of expansions")
 STATISTIC (NumReassoc, "Number of reassociations")
static ValuesimplifyAndInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an And, see if we can fold the result.
static ValuesimplifyUnOp (unsigned Opcode, Value *Op, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given the operand for a UnaryOperator, see if we can fold the result.
static ValuesimplifyFPUnOp (unsigned Opcode, Value *Op, const FastMathFlags &FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given the operand for a UnaryOperator, see if we can fold the result.
static ValuesimplifyBinOp (unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a BinaryOperator, see if we can fold the result.
static ValuesimplifyBinOp (unsigned Opcode, Value *LHS, Value *RHS, const FastMathFlags &FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a BinaryOperator, see if we can fold the result.
static ValuesimplifyCmpInst (CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a CmpInst, see if we can fold the result.
static ValuesimplifyICmpInst (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an ICmpInst, see if we can fold the result.
static ValuesimplifyOrInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an Or, see if we can fold the result.
static ValuesimplifyXorInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a Xor, see if we can fold the result.
static ValuesimplifyCastInst (unsigned, Value *, Type *, const SimplifyQuery &, unsigned)
static ValuesimplifyGEPInst (Type *SrcTy, Value *Ptr, ArrayRef< Value * > Indices, GEPNoWrapFlags NW, const SimplifyQuery &Q, unsigned)
 Given operands for an GetElementPtrInst, see if we can fold the result.
static ValuesimplifySelectInst (Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a SelectInst, see if we can fold the result.
static ValuesimplifyInstructionWithOperands (Instruction *I, ArrayRef< Value * > NewOps, const SimplifyQuery &SQ, unsigned MaxRecurse)
 See if we can compute a simplified version of this instruction.
static ConstantgetFalse (Type *Ty)
 For a boolean type or a vector of boolean type, return false or a vector with every element false.
static ConstantgetTrue (Type *Ty)
 For a boolean type or a vector of boolean type, return true or a vector with every element true.
static bool isSameCompare (Value *V, CmpPredicate Pred, Value *LHS, Value *RHS)
 isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
static ValuesimplifyCmpSelCase (CmpPredicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse, Constant *TrueOrFalse)
 Simplify comparison with true or false branch of select: sel = select i1 cond, i32 tv, i32 fv cmp = icmp sle i32 sel, rhs Compose new comparison by substituting sel with either tv or fv and see if it simplifies.
static ValuesimplifyCmpSelTrueCase (CmpPredicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse)
 Simplify comparison with true branch of select.
static ValuesimplifyCmpSelFalseCase (CmpPredicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse)
 Simplify comparison with false branch of select.
static ValuehandleOtherCmpSelSimplifications (Value *TCmp, Value *FCmp, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse)
 We know comparison with both branches of select can be simplified, but they are not equal.
static bool valueDominatesPHI (Value *V, PHINode *P, const DominatorTree *DT)
 Does the given value dominate the specified phi node?
static ValueexpandBinOp (Instruction::BinaryOps Opcode, Value *V, Value *OtherOp, Instruction::BinaryOps OpcodeToExpand, const SimplifyQuery &Q, unsigned MaxRecurse)
 Try to simplify a binary operator of form "V op OtherOp" where V is "(B0 opex B1)" by distributing 'op' across 'opex' as "(B0 op OtherOp) opex (B1 op OtherOp)".
static ValueexpandCommutativeBinOp (Instruction::BinaryOps Opcode, Value *L, Value *R, Instruction::BinaryOps OpcodeToExpand, const SimplifyQuery &Q, unsigned MaxRecurse)
 Try to simplify binops of form "A op (B op' C)" or the commuted variant by distributing op over op'.
static ValuesimplifyAssociativeBinOp (Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 Generic simplifications for associative binary operations.
static ValuethreadBinOpOverSelect (Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 In the case of a binary operation with a select instruction as an operand, try to simplify the binop by seeing whether evaluating it on both branches of the select results in the same value.
static ValuethreadCmpOverSelect (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 In the case of a comparison with a select instruction, try to simplify the comparison by seeing whether both branches of the select result in the same value.
static ValuethreadBinOpOverPHI (Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 In the case of a binary operation with an operand that is a PHI instruction, try to simplify the binop by seeing whether evaluating it on the incoming phi values yields the same result for every value.
static ValuethreadCmpOverPHI (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 In the case of a comparison with a PHI instruction, try to simplify the comparison by seeing whether comparing with all of the incoming phi values yields the same result every time.
static ConstantfoldOrCommuteConstant (Instruction::BinaryOps Opcode, Value *&Op0, Value *&Op1, const SimplifyQuery &Q)
static ValuesimplifyAddInst (Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an Add, see if we can fold the result.
static APInt stripAndComputeConstantOffsets (const DataLayout &DL, Value *&V, bool AllowNonInbounds=false)
 Compute the base pointer and cumulative constant offsets for V.
static ConstantcomputePointerDifference (const DataLayout &DL, Value *LHS, Value *RHS)
 Compute the constant difference between two pointer values.
static ValuesimplifyByDomEq (unsigned Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Test if there is a dominating equivalence condition for the two operands.
static ValuesimplifySubInst (Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a Sub, see if we can fold the result.
static ValuesimplifyMulInst (Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a Mul, see if we can fold the result.
static bool isICmpTrue (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given a predicate and two operands, return true if the comparison is true.
static bool isDivZero (Value *X, Value *Y, const SimplifyQuery &Q, unsigned MaxRecurse, bool IsSigned)
 Return true if we can simplify X / Y to 0.
static ValuesimplifyDivRem (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Check for common or similar folds of integer division or integer remainder.
static ValuesimplifyDiv (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
 These are simplifications common to SDiv and UDiv.
static ValuesimplifyRem (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 These are simplifications common to SRem and URem.
static ValuesimplifySDivInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an SDiv, see if we can fold the result.
static ValuesimplifyUDivInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a UDiv, see if we can fold the result.
static ValuesimplifySRemInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an SRem, see if we can fold the result.
static ValuesimplifyURemInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for a URem, see if we can fold the result.
static bool isPoisonShift (Value *Amount, const SimplifyQuery &Q)
 Returns true if a shift by Amount always yields poison.
static ValuesimplifyShift (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsNSW, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an Shl, LShr or AShr, see if we can fold the result.
static ValuesimplifyRightShift (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an LShr or AShr, see if we can fold the result.
static ValuesimplifyShlInst (Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an Shl, see if we can fold the result.
static ValuesimplifyLShrInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an LShr, see if we can fold the result.
static ValuesimplifyAShrInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an AShr, see if we can fold the result.
static ValuesimplifyUnsignedRangeCheck (ICmpInst *ZeroICmp, ICmpInst *UnsignedICmp, bool IsAnd, const SimplifyQuery &Q)
 Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
static ValuesimplifyAndOrOfICmpsWithConstants (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd)
 Test if a pair of compares with a shared operand and 2 constants has an empty set intersection, full set union, or if one compare is a superset of the other.
static ValuesimplifyAndOfICmpsWithAdd (ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
static ValuesimplifyAndOrOfICmpsWithCtpop (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd)
 Try to simplify and/or of icmp with ctpop intrinsic.
static ValuesimplifyAndOfICmps (ICmpInst *Op0, ICmpInst *Op1, const SimplifyQuery &Q)
static ValuesimplifyOrOfICmpsWithAdd (ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
static ValuesimplifyOrOfICmps (ICmpInst *Op0, ICmpInst *Op1, const SimplifyQuery &Q)
static ValuesimplifyAndOrOfFCmps (const SimplifyQuery &Q, FCmpInst *LHS, FCmpInst *RHS, bool IsAnd)
static ValuesimplifyAndOrOfCmps (const SimplifyQuery &Q, Value *Op0, Value *Op1, bool IsAnd)
static ValuesimplifyWithOpReplaced (Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags, unsigned MaxRecurse)
static ValuesimplifyAndOrWithICmpEq (unsigned Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
static ValuesimplifyLogicOfAddSub (Value *Op0, Value *Op1, Instruction::BinaryOps Opcode)
 Given a bitwise logic op, check if the operands are add/sub with a common source value and inverted constant (identity: C - X -> ~(X + ~C)).
static ValuesimplifyAndCommutative (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
static ValuesimplifyOrLogic (Value *X, Value *Y)
static TypegetCompareTy (Value *Op)
static ValueextractEquivalentCondition (Value *V, CmpPredicate Pred, Value *LHS, Value *RHS)
 Rummage around inside V looking for something equivalent to the comparison "LHS Pred RHS".
static bool isAllocDisjoint (const Value *V)
 Return true if the underlying object (storage) must be disjoint from storage returned by any noalias return call.
static bool haveNonOverlappingStorage (const Value *V1, const Value *V2)
 Return true if V1 and V2 are each the base of some distict storage region [V, object_size(V)] which do not overlap.
static ConstantcomputePointerICmp (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static ValuesimplifyICmpOfBools (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
 Fold an icmp when its operands have i1 scalar type.
static ValuesimplifyICmpWithZero (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
 Try hard to fold icmp with zero RHS because this is a common case.
static ValuesimplifyICmpWithConstant (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static void getUnsignedMonotonicValues (SmallPtrSetImpl< Value * > &Res, Value *V, MonotonicType Type, const SimplifyQuery &Q, unsigned Depth=0)
 Get values V_i such that V uge V_i (GreaterEq) or V ule V_i (LowerEq).
static ValuesimplifyICmpUsingMonotonicValues (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static ValuesimplifyICmpWithBinOpOnLHS (CmpPredicate Pred, BinaryOperator *LBO, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
static bool trySimplifyICmpWithAdds (CmpPredicate Pred, Value *LHS, Value *RHS, const InstrInfoQuery &IIQ)
static ValuesimplifyICmpWithBinOp (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 TODO: A large part of this logic is duplicated in InstCombine's foldICmpBinOp().
static ValuesimplifyICmpWithMinMax (CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
 simplify integer comparisons where at least one operand of the compare matches an integer min/max idiom.
static ValuesimplifyICmpWithDominatingAssume (CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static ValuesimplifyICmpWithIntrinsicOnLHS (CmpPredicate Pred, Value *LHS, Value *RHS)
static std::optional< ConstantRangegetRange (Value *V, const InstrInfoQuery &IIQ)
 Helper method to get range from metadata or attribute.
static ValuesimplifyFCmpInst (CmpPredicate Pred, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given operands for an FCmpInst, see if we can fold the result.
static ValuesimplifyWithOpsReplaced (Value *V, ArrayRef< std::pair< Value *, Value * > > Ops, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags, unsigned MaxRecurse)
static ValuesimplifySelectBitTest (Value *TrueVal, Value *FalseVal, Value *X, const APInt *Y, bool TrueWhenUnset)
 Try to simplify a select instruction when its condition operand is an integer comparison where one operand of the compare is a constant.
static ValuesimplifyCmpSelOfMaxMin (Value *CmpLHS, Value *CmpRHS, CmpPredicate Pred, Value *TVal, Value *FVal)
static ValuesimplifySelectWithBitTest (Value *CondVal, Value *TrueVal, Value *FalseVal)
 An alternative way to test if a bit is set or not.
static ValuesimplifySelectWithEquivalence (ArrayRef< std::pair< Value *, Value * > > Replacements, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
 Try to simplify a select instruction when its condition operand is an integer equality or floating-point equivalence comparison.
static ValuesimplifySelectWithICmpCond (Value *CondVal, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
 Try to simplify a select instruction when its condition operand is an integer comparison.
static ValuesimplifySelectWithFCmp (Value *Cond, Value *T, Value *F, const SimplifyQuery &Q, unsigned MaxRecurse)
 Try to simplify a select instruction when its condition operand is a floating-point comparison.
static ValuesimplifyInsertValueInst (Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q, unsigned)
 Given operands for an InsertValueInst, see if we can fold the result.
static ValuesimplifyExtractValueInst (Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &, unsigned)
 Given operands for an ExtractValueInst, see if we can fold the result.
static ValuesimplifyExtractElementInst (Value *Vec, Value *Idx, const SimplifyQuery &Q, unsigned)
 Given operands for an ExtractElementInst, see if we can fold the result.
static ValuesimplifyPHINode (PHINode *PN, ArrayRef< Value * > IncomingValues, const SimplifyQuery &Q)
 See if we can fold the given phi. If not, returns null.
static ValuefoldIdentityShuffles (int DestElt, Value *Op0, Value *Op1, int MaskVal, Value *RootVec, unsigned MaxRecurse)
 For the given destination element of a shuffle, peek through shuffles to match a root vector source operand that contains that element in the same vector lane (ie, the same mask index), so we can eliminate the shuffle(s).
static ValuesimplifyShuffleVectorInst (Value *Op0, Value *Op1, ArrayRef< int > Mask, Type *RetTy, const SimplifyQuery &Q, unsigned MaxRecurse)
static ConstantfoldConstant (Instruction::UnaryOps Opcode, Value *&Op, const SimplifyQuery &Q)
static ValuesimplifyFNegInst (Value *Op, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
 Given the operand for an FNeg, see if we can fold the result.
static ConstantpropagateNaN (Constant *In)
 Try to propagate existing NaN values when possible.
static ConstantsimplifyFPOp (ArrayRef< Value * > Ops, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior, RoundingMode Rounding)
 Perform folds that are common to any floating-point operation.
static ValuesimplifyFAddInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
 Given operands for an FAdd, see if we can fold the result.
static ValuesimplifyFSubInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
 Given operands for an FSub, see if we can fold the result.
static ValuesimplifyFMAFMul (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse, fp::ExceptionBehavior ExBehavior, RoundingMode Rounding)
static ValuesimplifyFMulInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
 Given the operands for an FMul, see if we can fold the result.
static ValuesimplifyFDivInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
static ValuesimplifyFRemInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
static bool isIdempotent (Intrinsic::ID ID)
static bool removesFPFraction (Intrinsic::ID ID)
 Return true if the intrinsic rounds a floating-point value to an integral floating-point value (not an integer type).
static ValuesimplifyRelativeLoad (Constant *Ptr, Constant *Offset, const DataLayout &DL)
static ValuesimplifyLdexp (Value *Op0, Value *Op1, const SimplifyQuery &Q, bool IsStrict)
static ValuesimplifyUnaryIntrinsic (Function *F, Value *Op0, const SimplifyQuery &Q, const CallBase *Call)
static ValuefoldMinMaxSharedOp (Intrinsic::ID IID, Value *Op0, Value *Op1)
 Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/max intrinsic with shared operand(s).
static ValuefoldMinimumMaximumSharedOp (Intrinsic::ID IID, Value *Op0, Value *Op1)
 Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/max intrinsic with shared operand(s).
static ValuesimplifyIntrinsic (CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q)
static ValuetryConstantFoldCall (CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q)
static ValuesimplifyFreezeInst (Value *Op0, const SimplifyQuery &Q)
 Given operands for a Freeze, see if we can fold the result.
static bool replaceAndRecursivelySimplifyImpl (Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC, SmallSetVector< Instruction *, 8 > *UnsimplifiedUsers=nullptr)
 Implementation of recursive simplification through an instruction's uses.
LLVM_ABI const SimplifyQuery llvm::getBestSimplifyQuery (Pass &, Function &)
LLVM_ABI const SimplifyQuery llvm::getBestSimplifyQuery (LoopStandardAnalysisResults &, const DataLayout &)
template<class T, class... TArgs>
const SimplifyQuery llvm::getBestSimplifyQuery (AnalysisManager< T, TArgs... > &, Function &)
template const SimplifyQuery llvm::getBestSimplifyQuery (AnalysisManager< Function > &, Function &)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instsimplify"

Definition at line 53 of file InstructionSimplify.cpp.

◆ HANDLE_CAST_INST

#define HANDLE_CAST_INST ( num,
opc,
clas )
Value:
case Instruction::opc:

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RecursionLimit 

Definition at line 55 of file InstructionSimplify.cpp.

◆ MonotonicType

enum class MonotonicType
strong
Enumerator
GreaterEq 
LowerEq 

Definition at line 3034 of file InstructionSimplify.cpp.

Function Documentation

◆ computePointerDifference()

Constant * computePointerDifference ( const DataLayout & DL,
Value * LHS,
Value * RHS )
static

Compute the constant difference between two pointer values.

If the difference is not a constant, returns zero.

Definition at line 686 of file InstructionSimplify.cpp.

References DL, llvm::dyn_cast(), llvm::ConstantVector::getSplat(), LHS, RHS, and stripAndComputeConstantOffsets().

Referenced by simplifySubInst().

◆ computePointerICmp()

◆ expandBinOp()

Value * expandBinOp ( Instruction::BinaryOps Opcode,
Value * V,
Value * OtherOp,
Instruction::BinaryOps OpcodeToExpand,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Try to simplify a binary operator of form "V op OtherOp" where V is "(B0 opex B1)" by distributing 'op' across 'opex' as "(B0 op OtherOp) opex (B1 op OtherOp)".

Definition at line 196 of file InstructionSimplify.cpp.

References B(), llvm::dyn_cast(), llvm::SimplifyQuery::getWithoutUndef(), llvm::Instruction::isCommutative(), and llvm::simplifyBinOp().

Referenced by expandCommutativeBinOp().

◆ expandCommutativeBinOp()

Value * expandCommutativeBinOp ( Instruction::BinaryOps Opcode,
Value * L,
Value * R,
Instruction::BinaryOps OpcodeToExpand,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Try to simplify binops of form "A op (B op' C)" or the commuted variant by distributing op over op'.

Definition at line 230 of file InstructionSimplify.cpp.

References expandBinOp().

Referenced by simplifyAndInst(), simplifyMulInst(), and simplifyOrInst().

◆ extractEquivalentCondition()

Value * extractEquivalentCondition ( Value * V,
CmpPredicate Pred,
Value * LHS,
Value * RHS )
static

Rummage around inside V looking for something equivalent to the comparison "LHS Pred RHS".

Return such a value if found, otherwise return null. Helper function for analyzing max/min idioms.

Definition at line 2574 of file InstructionSimplify.cpp.

References llvm::dyn_cast(), llvm::CmpInst::getSwappedPredicate(), LHS, and RHS.

Referenced by simplifyICmpWithMinMax().

◆ foldConstant()

◆ foldIdentityShuffles()

Value * foldIdentityShuffles ( int DestElt,
Value * Op0,
Value * Op1,
int MaskVal,
Value * RootVec,
unsigned MaxRecurse )
static

For the given destination element of a shuffle, peek through shuffles to match a root vector source operand that contains that element in the same vector lane (ie, the same mask index), so we can eliminate the shuffle(s).

Definition at line 5421 of file InstructionSimplify.cpp.

References llvm::cast(), llvm::dyn_cast(), foldIdentityShuffles(), and llvm::Value::getType().

Referenced by foldIdentityShuffles(), and simplifyShuffleVectorInst().

◆ foldMinimumMaximumSharedOp()

Value * foldMinimumMaximumSharedOp ( Intrinsic::ID IID,
Value * Op0,
Value * Op1 )
static

Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/max intrinsic with shared operand(s).

The caller is expected to swap the operand arguments to handle commutation.

Definition at line 6429 of file InstructionSimplify.cpp.

References assert(), llvm::dyn_cast(), llvm::getInverseMinMaxIntrinsic(), llvm::M0(), and llvm::M1().

Referenced by llvm::simplifyBinaryIntrinsic().

◆ foldMinMaxSharedOp()

Value * foldMinMaxSharedOp ( Intrinsic::ID IID,
Value * Op0,
Value * Op1 )
static

Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/max intrinsic with shared operand(s).

The caller is expected to swap the operand arguments to handle commutation.

Definition at line 6404 of file InstructionSimplify.cpp.

References llvm::dyn_cast(), llvm::getInverseMinMaxIntrinsic(), llvm::PatternMatch::m_c_MaxOrMin(), llvm::PatternMatch::m_MaxOrMin(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.

Referenced by llvm::simplifyBinaryIntrinsic().

◆ foldOrCommuteConstant()

◆ getCompareTy()

◆ getFalse()

◆ getRange()

std::optional< ConstantRange > getRange ( Value * V,
const InstrInfoQuery & IIQ )
static

Helper method to get range from metadata or attribute.

Definition at line 3727 of file InstructionSimplify.cpp.

References A(), llvm::dyn_cast(), llvm::getConstantRangeFromMetadata(), llvm::InstrInfoQuery::getMetadata(), and I.

Referenced by simplifyICmpInst().

◆ getTrue()

Constant * getTrue ( Type * Ty)
static

◆ getUnsignedMonotonicValues()

◆ handleOtherCmpSelSimplifications()

Value * handleOtherCmpSelSimplifications ( Value * TCmp,
Value * FCmp,
Value * Cond,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

We know comparison with both branches of select can be simplified, but they are not equal.

This routine handles some logical simplifications.

Definition at line 146 of file InstructionSimplify.cpp.

References Cond, llvm::Constant::getAllOnesValue(), llvm::impliesPoison(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::simplifyAndInst(), llvm::simplifyOrInst(), and llvm::simplifyXorInst().

Referenced by threadCmpOverSelect().

◆ haveNonOverlappingStorage()

bool haveNonOverlappingStorage ( const Value * V1,
const Value * V2 )
static

Return true if V1 and V2 are each the base of some distict storage region [V, object_size(V)] which do not overlap.

Note that zero sized regions are possible, and that zero sized regions do not overlap with any other.

Definition at line 2613 of file InstructionSimplify.cpp.

References A(), llvm::dyn_cast(), and llvm::isa().

Referenced by computePointerICmp().

◆ isAllocDisjoint()

bool isAllocDisjoint ( const Value * V)
static

Return true if the underlying object (storage) must be disjoint from storage returned by any noalias return call.

Definition at line 2593 of file InstructionSimplify.cpp.

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

Referenced by computePointerICmp().

◆ isDivZero()

bool isDivZero ( Value * X,
Value * Y,
const SimplifyQuery & Q,
unsigned MaxRecurse,
bool IsSigned )
static

◆ isICmpTrue()

bool isICmpTrue ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given a predicate and two operands, return true if the comparison is true.

This is a helper for div/rem simplification where we return some other value when we can prove a relationship between the operands.

Definition at line 968 of file InstructionSimplify.cpp.

References llvm::CallingConv::C, llvm::dyn_cast_or_null(), LHS, RHS, and llvm::simplifyICmpInst().

Referenced by isDivZero(), and llvm::simplifyBinaryIntrinsic().

◆ isIdempotent()

bool isIdempotent ( Intrinsic::ID ID)
static

Definition at line 6155 of file InstructionSimplify.cpp.

Referenced by simplifyUnaryIntrinsic().

◆ isPoisonShift()

◆ isSameCompare()

bool isSameCompare ( Value * V,
CmpPredicate Pred,
Value * LHS,
Value * RHS )
static

isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?

Definition at line 96 of file InstructionSimplify.cpp.

References llvm::dyn_cast(), llvm::CmpInst::getSwappedPredicate(), LHS, and RHS.

Referenced by simplifyCmpSelCase().

◆ propagateNaN()

Constant * propagateNaN ( Constant * In)
static

Try to propagate existing NaN values when possible.

If not, replace the constant or elements in the constant with a canonical NaN.

Definition at line 5617 of file InstructionSimplify.cpp.

References assert(), llvm::cast(), llvm::dyn_cast(), llvm::ConstantVector::get(), llvm::ConstantFP::getNaN(), llvm::Value::getType(), llvm::isa(), llvm::Constant::isNaN(), and llvm::Splat.

Referenced by llvm::simplifyBinaryIntrinsic(), and simplifyFPOp().

◆ removesFPFraction()

bool removesFPFraction ( Intrinsic::ID ID)
static

Return true if the intrinsic rounds a floating-point value to an integral floating-point value (not an integer type).

Definition at line 6177 of file InstructionSimplify.cpp.

Referenced by simplifyUnaryIntrinsic().

◆ replaceAndRecursivelySimplifyImpl()

bool replaceAndRecursivelySimplifyImpl ( Instruction * I,
Value * SimpleV,
const TargetLibraryInfo * TLI,
const DominatorTree * DT,
AssumptionCache * AC,
SmallSetVector< Instruction *, 8 > * UnsimplifiedUsers = nullptr )
static

Implementation of recursive simplification through an instruction's uses.

This is the common implementation of the recursive simplification routines. If we have a pre-simplified value in 'SimpleV', that is forcibly used to replace the instruction 'I'. Otherwise, we simply add 'I' to the list of instructions to process and attempt to simplify it using InstructionSimplify. Recursively visited users which could not be simplified themselves are to the optional UnsimplifiedUsers set for further processing by the caller.

This routine returns 'true' only when it simplifies something. The passed in simplified value does not count toward this.

Definition at line 7281 of file InstructionSimplify.cpp.

References llvm::cast(), DL, I, llvm::SetVector< T, Vector, Set, N >::insert(), llvm::simplifyInstruction(), and llvm::SetVector< T, Vector, Set, N >::size().

Referenced by llvm::replaceAndRecursivelySimplify().

◆ simplifyAddInst()

◆ simplifyAndCommutative()

◆ simplifyAndInst()

Value * simplifyAndInst ( Value * Op0,
Value * Op1,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for an And, see if we can fold the result.

If not, this returns null.

Definition at line 2025 of file InstructionSimplify.cpp.

References A(), llvm::SimplifyQuery::AC, llvm::CallingConv::C, llvm::computeKnownBits(), llvm::KnownBits::countMaxActiveBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, expandCommutativeBinOp(), foldOrCommuteConstant(), llvm::APInt::getActiveBits(), llvm::ConstantInt::getFalse(), llvm::APInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::KnownBits::getMaxValue(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, llvm::APInt::intersects(), llvm::isa(), llvm::isImpliedCondition(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownToBeAPowerOfTwo(), llvm::APInt::isSubsetOf(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifyAndCommutative(), simplifyAndOrOfCmps(), simplifyAssociativeBinOp(), simplifyByDomEq(), simplifyLogicOfAddSub(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::InstrInfoQuery::UseInstrInfo, X, and Y.

◆ simplifyAndOfICmps()

◆ simplifyAndOfICmpsWithAdd()

◆ simplifyAndOrOfCmps()

◆ simplifyAndOrOfFCmps()

◆ simplifyAndOrOfICmpsWithConstants()

Value * simplifyAndOrOfICmpsWithConstants ( ICmpInst * Cmp0,
ICmpInst * Cmp1,
bool IsAnd )
static

Test if a pair of compares with a shared operand and 2 constants has an empty set intersection, full set union, or if one compare is a superset of the other.

Definition at line 1617 of file InstructionSimplify.cpp.

References getFalse(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), getTrue(), llvm::Value::getType(), llvm::PatternMatch::m_APInt(), llvm::ConstantRange::makeExactICmpRegion(), and llvm::PatternMatch::match().

Referenced by simplifyAndOfICmps(), and simplifyOrOfICmps().

◆ simplifyAndOrOfICmpsWithCtpop()

◆ simplifyAndOrWithICmpEq()

◆ simplifyAShrInst()

◆ simplifyAssociativeBinOp()

Value * simplifyAssociativeBinOp ( Instruction::BinaryOps Opcode,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Generic simplifications for associative binary operations.

Returns the simpler value, or null if none was found.

Definition at line 248 of file InstructionSimplify.cpp.

References A(), assert(), B(), llvm::CallingConv::C, llvm::dyn_cast(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), LHS, RHS, and llvm::simplifyBinOp().

Referenced by simplifyAddInst(), simplifyAndInst(), simplifyMulInst(), simplifyOrInst(), and simplifyXorInst().

◆ simplifyBinOp() [1/2]

Value * simplifyBinOp ( unsigned Opcode,
Value * LHS,
Value * RHS,
const FastMathFlags & FMF,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for a BinaryOperator, see if we can fold the result.

If not, this returns null. Try to use FastMathFlags when folding the result.

Definition at line 6115 of file InstructionSimplify.cpp.

References LHS, RHS, llvm::simplifyBinOp(), llvm::simplifyFAddInst(), llvm::simplifyFDivInst(), llvm::simplifyFMulInst(), and llvm::simplifyFSubInst().

◆ simplifyBinOp() [2/2]

◆ simplifyByDomEq()

Value * simplifyByDomEq ( unsigned Opcode,
Value * Op0,
Value * Op1,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Test if there is a dominating equivalence condition for the two operands.

If there is, try to reduce the binary operation between the two operands. Example: Op0 - Op1 --> 0 when Op0 == Op1

Definition at line 710 of file InstructionSimplify.cpp.

References llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::isImpliedByDomCondition(), and RecursionLimit.

Referenced by simplifyAndInst(), simplifyDivRem(), simplifyOrInst(), simplifySubInst(), and simplifyXorInst().

◆ simplifyCastInst()

◆ simplifyCmpInst()

Value * simplifyCmpInst ( CmpPredicate Predicate,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for a CmpInst, see if we can fold the result.

Definition at line 6143 of file InstructionSimplify.cpp.

References llvm::CmpInst::isIntPredicate(), LHS, RHS, llvm::simplifyFCmpInst(), and llvm::simplifyICmpInst().

Referenced by llvm::InstSimplifyFolder::FoldCmp().

◆ simplifyCmpSelCase()

Value * simplifyCmpSelCase ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
Value * Cond,
const SimplifyQuery & Q,
unsigned MaxRecurse,
Constant * TrueOrFalse )
static

Simplify comparison with true or false branch of select: sel = select i1 cond, i32 tv, i32 fv cmp = icmp sle i32 sel, rhs Compose new comparison by substituting sel with either tv or fv and see if it simplifies.

Definition at line 113 of file InstructionSimplify.cpp.

References Cond, isSameCompare(), LHS, RHS, and llvm::simplifyCmpInst().

Referenced by simplifyCmpSelFalseCase(), and simplifyCmpSelTrueCase().

◆ simplifyCmpSelFalseCase()

Value * simplifyCmpSelFalseCase ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
Value * Cond,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Simplify comparison with false branch of select.

Definition at line 137 of file InstructionSimplify.cpp.

References Cond, getFalse(), LHS, RHS, and simplifyCmpSelCase().

Referenced by threadCmpOverSelect().

◆ simplifyCmpSelOfMaxMin()

◆ simplifyCmpSelTrueCase()

Value * simplifyCmpSelTrueCase ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
Value * Cond,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Simplify comparison with true branch of select.

Definition at line 129 of file InstructionSimplify.cpp.

References Cond, getTrue(), LHS, RHS, and simplifyCmpSelCase().

Referenced by threadCmpOverSelect().

◆ simplifyDiv()

◆ simplifyDivRem()

◆ simplifyExtractElementInst()

◆ simplifyExtractValueInst()

◆ simplifyFAddInst()

◆ simplifyFCmpInst()

Value * simplifyFCmpInst ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
FastMathFlags FMF,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for an FCmpInst, see if we can fold the result.

If not, this returns null.

Definition at line 4064 of file InstructionSimplify.cpp.

References assert(), llvm::CallingConv::C, llvm::KnownFPClass::cannotBeOrderedLessThanZero(), llvm::cast(), llvm::computeKnownFPClass(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::dyn_cast(), llvm::fcAllFlags, llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::fcmpToClassTest(), llvm::fcNan, llvm::fcNone, llvm::PoisonValue::get(), getCompareTy(), getFalse(), llvm::Instruction::getFunction(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::isa(), llvm::CmpInst::isFalseWhenEqual(), llvm::CmpInst::isFPPredicate(), llvm::KnownFPClass::isKnownAlwaysNaN(), llvm::KnownFPClass::isKnownNeverNaN(), llvm::CmpInst::isTrueWhenEqual(), llvm::SimplifyQuery::isUndefValue(), llvm::CmpInst::isUnordered(), LHS, llvm_unreachable, llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_APFloatAllowPoison(), llvm::PatternMatch::m_Intrinsic(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::KnownFPClass::OrderedLessThanZeroMask, RHS, std::swap(), threadCmpOverPHI(), threadCmpOverSelect(), and llvm::SimplifyQuery::TLI.

◆ simplifyFDivInst()

◆ simplifyFMAFMul()

◆ simplifyFMulInst()

Value * simplifyFMulInst ( Value * Op0,
Value * Op1,
FastMathFlags FMF,
const SimplifyQuery & Q,
unsigned MaxRecurse,
fp::ExceptionBehavior ExBehavior = fp::ebIgnore,
RoundingMode Rounding = RoundingMode::NearestTiesToEven )
static

Given the operands for an FMul, see if we can fold the result.

Definition at line 5884 of file InstructionSimplify.cpp.

References llvm::CallingConv::C, llvm::fp::ebIgnore, foldOrCommuteConstant(), llvm::isDefaultFPEnvironment(), llvm::NearestTiesToEven, and llvm::simplifyFMAFMul().

◆ simplifyFNegInst()

Value * simplifyFNegInst ( Value * Op,
FastMathFlags FMF,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given the operand for an FNeg, see if we can fold the result.

If not, this returns null.

Definition at line 5597 of file InstructionSimplify.cpp.

References llvm::CallingConv::C, foldConstant(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.

◆ simplifyFPOp()

◆ simplifyFPUnOp()

Value * simplifyFPUnOp ( unsigned Opcode,
Value * Op,
const FastMathFlags & FMF,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given the operand for a UnaryOperator, see if we can fold the result.

If not, this returns null. Try to use FastMathFlags when folding the result.

Definition at line 6042 of file InstructionSimplify.cpp.

References llvm::simplifyFNegInst(), and llvm::simplifyUnOp().

◆ simplifyFreezeInst()

Value * simplifyFreezeInst ( Value * Op0,
const SimplifyQuery & Q )
static

Given operands for a Freeze, see if we can fold the result.

Definition at line 7066 of file InstructionSimplify.cpp.

References llvm::SimplifyQuery::AC, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DT, and llvm::isGuaranteedNotToBeUndefOrPoison().

◆ simplifyFRemInst()

◆ simplifyFSubInst()

◆ simplifyGEPInst()

Value * simplifyGEPInst ( Type * SrcTy,
Value * Ptr,
ArrayRef< Value * > Indices,
GEPNoWrapFlags NW,
const SimplifyQuery & Q,
unsigned  )
static

Given operands for an GetElementPtrInst, see if we can fold the result.

If not, this returns null.

Definition at line 5005 of file InstructionSimplify.cpp.

References llvm::all_of(), llvm::any_of(), llvm::ArrayRef< T >::back(), llvm::CallingConv::C, llvm::cast(), llvm::ConstantFoldConstant(), llvm::ConstantFoldGetElementPtr(), llvm::SimplifyQuery::DL, llvm::ArrayRef< T >::drop_back(), llvm::dyn_cast(), llvm::ArrayRef< T >::empty(), llvm::PoisonValue::get(), llvm::UndefValue::get(), llvm::VectorType::get(), llvm::Type::getContext(), llvm::ConstantExpr::getGetElementPtr(), llvm::GetElementPtrInst::getIndexedType(), llvm::DataLayout::getIndexSizeInBits(), llvm::ConstantExpr::getIntToPtr(), llvm::DataLayout::getPointerSizeInBits(), getScalarSizeInBits(), getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeSizeInBits(), llvm::getUnderlyingObject(), llvm::isa(), llvm::APInt::isOne(), llvm::ConstantExpr::isSupportedGetElementPtr(), llvm::SimplifyQuery::isUndefValue(), llvm::Type::isVectorTy(), llvm::APInt::isZero(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_ConstantInt(), llvm::MIPatternMatch::m_Neg(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), P, Ptr, and llvm::ArrayRef< T >::size().

Referenced by llvm::InstSimplifyFolder::FoldGEP().

◆ simplifyICmpInst()

Value * simplifyICmpInst ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for an ICmpInst, see if we can fold the result.

If not, this returns null.

Definition at line 3743 of file InstructionSimplify.cpp.

References assert(), llvm::CallingConv::C, llvm::cast(), computePointerICmp(), llvm::ConstantFoldCastOperand(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::dyn_cast(), llvm::PoisonValue::get(), llvm::UndefValue::get(), llvm::Constant::getAllOnesValue(), llvm::ConstantInt::getBool(), getCompareTy(), getFalse(), llvm::ConstantInt::getFalse(), llvm::ConstantExpr::getIntToPtr(), llvm::CmpInst::getInversePredicate(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), getRange(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), llvm::ICmpInst::getUnsignedPredicate(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, 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, llvm::SimplifyQuery::IIQ, llvm::isa(), llvm::Constant::isAllOnesValue(), llvm::ICmpInst::isEquality(), llvm::isImpliedByDomCondition(), llvm::CmpInst::isIntPredicate(), llvm::isKnownNonEqual(), llvm::Constant::isNullValue(), llvm::CmpInst::isTrueWhenEqual(), llvm::SimplifyQuery::isUndefValue(), LHS, llvm_unreachable, llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), RHS, llvm::simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpUsingMonotonicValues(), simplifyICmpWithBinOp(), simplifyICmpWithConstant(), simplifyICmpWithDominatingAssume(), simplifyICmpWithIntrinsicOnLHS(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), std::swap(), threadCmpOverPHI(), threadCmpOverSelect(), and llvm::SimplifyQuery::TLI.

◆ simplifyICmpOfBools()

Value * simplifyICmpOfBools ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q )
static

Fold an icmp when its operands have i1 scalar type.

For signed comparison, the values for an i1 are 0 and -1 respectively. This maps into a truth table of: LHS | RHS | LHS >=s RHS | LHS implies RHS 0 | 0 | 1 (0 >= 0) | 1 0 | 1 | 1 (0 >= -1) | 1 1 | 0 | 0 (-1 >= 0) | 0 1 | 1 | 1 (-1 >= -1) | 1

SLE follows the same logic as SGE with the LHS and RHS swapped.

Definition at line 2820 of file InstructionSimplify.cpp.

References llvm::SimplifyQuery::DL, getCompareTy(), getFalse(), getTrue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, 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, llvm::isImpliedCondition(), llvm::Type::isIntOrIntVectorTy(), LHS, llvm::MIPatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), RHS, and X.

Referenced by simplifyICmpInst().

◆ simplifyICmpUsingMonotonicValues()

◆ simplifyICmpWithBinOp()

Value * simplifyICmpWithBinOp ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

TODO: A large part of this logic is duplicated in InstCombine's foldICmpBinOp().

We should be able to share that and avoid the code duplication.

Definition at line 3252 of file InstructionSimplify.cpp.

References A(), assert(), B(), llvm::CallingConv::C, llvm::cast(), D(), llvm::dyn_cast(), getCompareTy(), llvm::ConstantInt::getFalse(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::SimplifyQuery::IIQ, llvm::ICmpInst::isEquality(), llvm::ICmpInst::isEquality(), llvm::InstrInfoQuery::isExact(), llvm::isKnownNonZero(), llvm::APInt::isNonNegative(), llvm::ICmpInst::isRelational(), llvm::CmpInst::isSigned(), llvm::APInt::isSubsetOf(), llvm::CmpInst::isUnsigned(), LHS, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::MIPatternMatch::m_Neg(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), RHS, llvm::simplifyICmpInst(), simplifyICmpWithBinOpOnLHS(), std::swap(), trySimplifyICmpWithAdds(), and Y.

Referenced by simplifyICmpInst().

◆ simplifyICmpWithBinOpOnLHS()

◆ simplifyICmpWithConstant()

◆ simplifyICmpWithDominatingAssume()

◆ simplifyICmpWithIntrinsicOnLHS()

◆ simplifyICmpWithMinMax()

◆ simplifyICmpWithZero()

◆ simplifyInsertValueInst()

Value * simplifyInsertValueInst ( Value * Agg,
Value * Val,
ArrayRef< unsigned > Idxs,
const SimplifyQuery & Q,
unsigned  )
static

◆ simplifyInstructionWithOperands()

Value * simplifyInstructionWithOperands ( Instruction * I,
ArrayRef< Value * > NewOps,
const SimplifyQuery & SQ,
unsigned MaxRecurse )
static

See if we can compute a simplified version of this instruction.

If not, this returns null.

Definition at line 7117 of file InstructionSimplify.cpp.

References llvm::all_of(), assert(), llvm::ArrayRef< T >::back(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::cast(), llvm::ConstantFoldInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::ArrayRef< T >::drop_back(), llvm::Instruction::getFunction(), llvm::SimplifyQuery::getWithInstruction(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), I, llvm::SimplifyQuery::IIQ, llvm::isa(), llvm::InstrInfoQuery::isExact(), IV, llvm::simplifyAddInst(), llvm::simplifyAndInst(), llvm::simplifyAShrInst(), llvm::simplifyCall(), llvm::simplifyCastInst(), llvm::simplifyExtractElementInst(), llvm::simplifyExtractValueInst(), llvm::simplifyFAddInst(), llvm::simplifyFCmpInst(), llvm::simplifyFDivInst(), llvm::simplifyFMulInst(), llvm::simplifyFNegInst(), llvm::simplifyFreezeInst(), llvm::simplifyFRemInst(), llvm::simplifyFSubInst(), llvm::simplifyGEPInst(), llvm::simplifyICmpInst(), llvm::simplifyInsertElementInst(), llvm::simplifyInsertValueInst(), llvm::simplifyLoadInst(), llvm::simplifyLShrInst(), llvm::simplifyMulInst(), llvm::simplifyOrInst(), simplifyPHINode(), llvm::simplifySDivInst(), llvm::simplifySelectInst(), llvm::simplifyShlInst(), llvm::simplifyShuffleVectorInst(), llvm::simplifySRemInst(), llvm::simplifySubInst(), llvm::simplifyUDivInst(), llvm::simplifyURemInst(), llvm::simplifyXorInst(), llvm::ArrayRef< T >::size(), llvm::SimplifyQuery::TLI, and llvm::transform().

◆ simplifyIntrinsic()

Value * simplifyIntrinsic ( CallBase * Call,
Value * Callee,
ArrayRef< Value * > Args,
const SimplifyQuery & Q )
static

◆ simplifyLdexp()

◆ simplifyLogicOfAddSub()

Value * simplifyLogicOfAddSub ( Value * Op0,
Value * Op1,
Instruction::BinaryOps Opcode )
static

◆ simplifyLShrInst()

◆ simplifyMulInst()

◆ simplifyOrInst()

◆ simplifyOrLogic()

◆ simplifyOrOfICmps()

◆ simplifyOrOfICmpsWithAdd()

◆ simplifyPHINode()

◆ simplifyRelativeLoad()

◆ simplifyRem()

◆ simplifyRightShift()

Value * simplifyRightShift ( Instruction::BinaryOps Opcode,
Value * Op0,
Value * Op1,
bool IsExact,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for an LShr or AShr, see if we can fold the result.

If not, this returns null.

Definition at line 1368 of file InstructionSimplify.cpp.

References llvm::computeKnownBits(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::isUndefValue(), llvm::KnownBits::One, and simplifyShift().

Referenced by simplifyAShrInst(), and simplifyLShrInst().

◆ simplifySDivInst()

Value * simplifySDivInst ( Value * Op0,
Value * Op1,
bool IsExact,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for an SDiv, see if we can fold the result.

If not, this returns null.

Definition at line 1208 of file InstructionSimplify.cpp.

References llvm::Constant::getAllOnesValue(), llvm::Value::getType(), llvm::isKnownNegation(), and simplifyDiv().

◆ simplifySelectBitTest()

Value * simplifySelectBitTest ( Value * TrueVal,
Value * FalseVal,
Value * X,
const APInt * Y,
bool TrueWhenUnset )
static

Try to simplify a select instruction when its condition operand is an integer comparison where one operand of the compare is a constant.

Definition at line 4502 of file InstructionSimplify.cpp.

References llvm::CallingConv::C, llvm::cast(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), X, and Y.

Referenced by simplifySelectWithBitTest(), and simplifySelectWithICmpCond().

◆ simplifySelectInst()

◆ simplifySelectWithBitTest()

Value * simplifySelectWithBitTest ( Value * CondVal,
Value * TrueVal,
Value * FalseVal )
static

An alternative way to test if a bit is set or not.

uses e.g. sgt/slt or trunc instead of eq/ne.

Definition at line 4617 of file InstructionSimplify.cpp.

References llvm::decomposeBitTest(), llvm::CmpInst::ICMP_EQ, and simplifySelectBitTest().

Referenced by simplifySelectInst().

◆ simplifySelectWithEquivalence()

Value * simplifySelectWithEquivalence ( ArrayRef< std::pair< Value *, Value * > > Replacements,
Value * TrueVal,
Value * FalseVal,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Try to simplify a select instruction when its condition operand is an integer equality or floating-point equivalence comparison.

Definition at line 4628 of file InstructionSimplify.cpp.

References llvm::SimplifyQuery::getWithoutUndef(), and simplifyWithOpsReplaced().

Referenced by simplifySelectWithFCmp(), and simplifySelectWithICmpCond().

◆ simplifySelectWithFCmp()

Value * simplifySelectWithFCmp ( Value * Cond,
Value * T,
Value * F,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

◆ simplifySelectWithICmpCond()

◆ simplifyShift()

◆ simplifyShlInst()

◆ simplifyShuffleVectorInst()

◆ simplifySRemInst()

Value * simplifySRemInst ( Value * Op0,
Value * Op1,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for an SRem, see if we can fold the result.

If not, this returns null.

Definition at line 1236 of file InstructionSimplify.cpp.

References llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isKnownNegation(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyRem(), and X.

◆ simplifySubInst()

◆ simplifyUDivInst()

Value * simplifyUDivInst ( Value * Op0,
Value * Op1,
bool IsExact,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for a UDiv, see if we can fold the result.

If not, this returns null.

Definition at line 1224 of file InstructionSimplify.cpp.

References simplifyDiv().

◆ simplifyUnaryIntrinsic()

◆ simplifyUnOp()

Value * simplifyUnOp ( unsigned Opcode,
Value * Op,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given the operand for a UnaryOperator, see if we can fold the result.

If not, this returns null.

Definition at line 6029 of file InstructionSimplify.cpp.

References llvm_unreachable, and llvm::simplifyFNegInst().

Referenced by llvm::InstSimplifyFolder::FoldUnOpFMF().

◆ simplifyUnsignedRangeCheck()

◆ simplifyURemInst()

Value * simplifyURemInst ( Value * Op0,
Value * Op1,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

Given operands for a URem, see if we can fold the result.

If not, this returns null.

Definition at line 1257 of file InstructionSimplify.cpp.

References simplifyRem().

◆ simplifyWithOpReplaced()

Value * simplifyWithOpReplaced ( Value * V,
Value * Op,
Value * RepOp,
const SimplifyQuery & Q,
bool AllowRefinement,
SmallVectorImpl< Instruction * > * DropFlags,
unsigned MaxRecurse )
static

Definition at line 4478 of file InstructionSimplify.cpp.

References simplifyWithOpsReplaced().

◆ simplifyWithOpsReplaced()

◆ simplifyXorInst()

◆ STATISTIC() [1/2]

STATISTIC ( NumExpand ,
"Number of expansions"  )

◆ STATISTIC() [2/2]

STATISTIC ( NumReassoc ,
"Number of reassociations"  )

References I, LHS, and RHS.

◆ stripAndComputeConstantOffsets()

APInt stripAndComputeConstantOffsets ( const DataLayout & DL,
Value *& V,
bool AllowNonInbounds = false )
static

Compute the base pointer and cumulative constant offsets for V.

This strips all constant offsets off of V, leaving it the base pointer, and accumulates the total constant offset applied in the returned constant. It returns zero if there are no constant offsets applied.

This is very similar to stripAndAccumulateConstantOffsets(), except it normalizes the offset bitwidth to the stripped pointer type, not the original pointer type.

Definition at line 673 of file InstructionSimplify.cpp.

References assert(), DL, llvm::APInt::getZero(), and llvm::Offset.

Referenced by computePointerDifference().

◆ threadBinOpOverPHI()

Value * threadBinOpOverPHI ( Instruction::BinaryOps Opcode,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

In the case of a binary operation with an operand that is a PHI instruction, try to simplify the binop by seeing whether evaluating it on the incoming phi values yields the same result for every value.

If so returns the common value, otherwise returns null.

Definition at line 476 of file InstructionSimplify.cpp.

References assert(), llvm::cast(), llvm::SimplifyQuery::DT, llvm::PHINode::getIncomingBlock(), llvm::BasicBlock::getTerminator(), llvm::SimplifyQuery::getWithInstruction(), llvm::PHINode::incoming_values(), llvm::isa(), LHS, RHS, llvm::simplifyBinOp(), and valueDominatesPHI().

Referenced by simplifyAndInst(), simplifyDivRem(), simplifyMulInst(), simplifyOrInst(), and simplifyShift().

◆ threadBinOpOverSelect()

Value * threadBinOpOverSelect ( Instruction::BinaryOps Opcode,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

In the case of a binary operation with a select instruction as an operand, try to simplify the binop by seeing whether evaluating it on both branches of the select results in the same value.

Returns the common value if so, otherwise returns null.

Definition at line 352 of file InstructionSimplify.cpp.

References assert(), llvm::cast(), llvm::dyn_cast(), llvm::isa(), llvm::SimplifyQuery::isUndefValue(), LHS, RHS, and llvm::simplifyBinOp().

Referenced by simplifyAndInst(), simplifyDivRem(), simplifyMulInst(), simplifyOrInst(), and simplifyShift().

◆ threadCmpOverPHI()

Value * threadCmpOverPHI ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

In the case of a comparison with a PHI instruction, try to simplify the comparison by seeing whether comparing with all of the incoming phi values yields the same result every time.

If so returns the common result, otherwise returns null.

Definition at line 523 of file InstructionSimplify.cpp.

References assert(), llvm::cast(), llvm::SimplifyQuery::DT, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), llvm::SimplifyQuery::getWithInstruction(), llvm::isa(), LHS, RHS, llvm::simplifyCmpInst(), std::swap(), and valueDominatesPHI().

Referenced by simplifyFCmpInst(), and simplifyICmpInst().

◆ threadCmpOverSelect()

Value * threadCmpOverSelect ( CmpPredicate Pred,
Value * LHS,
Value * RHS,
const SimplifyQuery & Q,
unsigned MaxRecurse )
static

In the case of a comparison with a select instruction, try to simplify the comparison by seeing whether both branches of the select result in the same value.

Returns the common value if so, otherwise returns null. For example, if we have: tmp = select i1 cmp, i32 1, i32 2 cmp1 = icmp sle i32 tmp, 3 We can simplify cmp1 to true, because both branches of select are less than 3. We compose new comparison by substituting tmp with both branches of select and see if it can be simplified.

Definition at line 431 of file InstructionSimplify.cpp.

References assert(), llvm::cast(), Cond, llvm::CmpInst::getSwappedPredicate(), handleOtherCmpSelSimplifications(), llvm::isa(), LHS, RHS, simplifyCmpSelFalseCase(), simplifyCmpSelTrueCase(), and std::swap().

Referenced by simplifyFCmpInst(), and simplifyICmpInst().

◆ tryConstantFoldCall()

◆ trySimplifyICmpWithAdds()

◆ valueDominatesPHI()

bool valueDominatesPHI ( Value * V,
PHINode * P,
const DominatorTree * DT )
static

Does the given value dominate the specified phi node?

Definition at line 174 of file InstructionSimplify.cpp.

References llvm::DominatorTree::dominates(), llvm::dyn_cast(), I, llvm::isa(), and P.

Referenced by simplifyPHINode(), threadBinOpOverPHI(), and threadCmpOverPHI().