LLVM 20.0.0git
Namespaces | Macros | Enumerations | Functions
InstructionSimplify.cpp File Reference
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/CmpInstAnalysis.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstSimplifyFolder.h"
#include "llvm/Analysis/LoopAnalysisManager.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/OverflowInstAnalysis.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Statepoint.h"
#include "llvm/Support/KnownBits.h"
#include <algorithm>
#include <optional>
#include "llvm/IR/Instruction.def"

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)   case Instruction::opc:
 

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 InstrInfoQuery &IIQ)
 
static void getUnsignedMonotonicValues (SmallPtrSetImpl< Value * > &Res, Value *V, MonotonicType Type, 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)
 
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 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 ValuesimplifySelectWithFakeICmpEq (Value *CmpLHS, Value *CmpRHS, CmpPredicate Pred, Value *TrueVal, Value *FalseVal)
 An alternative way to test if a bit is set or not uses sgt/slt instead of eq/ne.
 
static ValuesimplifySelectWithEquivalence (Value *CmpLHS, Value *CmpRHS, 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.
 
const SimplifyQuery llvm::getBestSimplifyQuery (Pass &, Function &)
 
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 50 of file InstructionSimplify.cpp.

◆ HANDLE_CAST_INST

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

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RecursionLimit 

Definition at line 52 of file InstructionSimplify.cpp.

◆ MonotonicType

enum class MonotonicType
strong
Enumerator
GreaterEq 
LowerEq 

Definition at line 3026 of file InstructionSimplify.cpp.

Function Documentation

◆ computePointerDifference()

static 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 683 of file InstructionSimplify.cpp.

References DL, llvm::Value::getContext(), llvm::ConstantVector::getSplat(), llvm::Value::getType(), LHS, RHS, and stripAndComputeConstantOffsets().

Referenced by simplifySubInst().

◆ computePointerICmp()

static Constant * computePointerICmp ( CmpPredicate  Pred,
Value LHS,
Value RHS,
const SimplifyQuery Q 
)
static

◆ expandBinOp()

static 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 193 of file InstructionSimplify.cpp.

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

Referenced by expandCommutativeBinOp().

◆ expandCommutativeBinOp()

static 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 227 of file InstructionSimplify.cpp.

References expandBinOp().

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

◆ extractEquivalentCondition()

static 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 2557 of file InstructionSimplify.cpp.

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

Referenced by simplifyICmpWithMinMax().

◆ foldConstant()

static Constant * foldConstant ( Instruction::UnaryOps  Opcode,
Value *&  Op,
const SimplifyQuery Q 
)
static

◆ foldIdentityShuffles()

static 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 5375 of file InstructionSimplify.cpp.

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

Referenced by foldIdentityShuffles(), and simplifyShuffleVectorInst().

◆ foldMinimumMaximumSharedOp()

static 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 6391 of file InstructionSimplify.cpp.

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

Referenced by llvm::simplifyBinaryIntrinsic().

◆ foldMinMaxSharedOp()

static 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 6366 of file InstructionSimplify.cpp.

References 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()

static Constant * foldOrCommuteConstant ( Instruction::BinaryOps  Opcode,
Value *&  Op0,
Value *&  Op1,
const SimplifyQuery Q 
)
static

◆ getCompareTy()

static Type * getCompareTy ( Value Op)
static

◆ getFalse()

static Constant * getFalse ( Type Ty)
static

◆ getRange()

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

Helper method to get range from metadata or attribute.

Definition at line 3709 of file InstructionSimplify.cpp.

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

Referenced by getFromRangeMetadata(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), and simplifyICmpInst().

◆ getTrue()

static Constant * getTrue ( Type Ty)
static

◆ getUnsignedMonotonicValues()

static void getUnsignedMonotonicValues ( SmallPtrSetImpl< Value * > &  Res,
Value V,
MonotonicType  Type,
unsigned  Depth = 0 
)
static

◆ handleOtherCmpSelSimplifications()

static 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 143 of file InstructionSimplify.cpp.

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

Referenced by threadCmpOverSelect().

◆ haveNonOverlappingStorage()

static 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 2596 of file InstructionSimplify.cpp.

References A.

Referenced by computePointerICmp().

◆ isAllocDisjoint()

static 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 2576 of file InstructionSimplify.cpp.

References A.

Referenced by computePointerICmp().

◆ isDivZero()

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

◆ isICmpTrue()

static 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 957 of file InstructionSimplify.cpp.

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

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

◆ isIdempotent()

static bool isIdempotent ( Intrinsic::ID  ID)
static

Definition at line 6107 of file InstructionSimplify.cpp.

Referenced by simplifyUnaryIntrinsic().

◆ isPoisonShift()

static bool isPoisonShift ( Value Amount,
const SimplifyQuery Q 
)
static

◆ isSameCompare()

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

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

Definition at line 93 of file InstructionSimplify.cpp.

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

Referenced by simplifyCmpSelCase().

◆ propagateNaN()

static 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 5571 of file InstructionSimplify.cpp.

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

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

◆ removesFPFraction()

static 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 6129 of file InstructionSimplify.cpp.

Referenced by simplifyUnaryIntrinsic().

◆ replaceAndRecursivelySimplifyImpl()

static 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 7225 of file InstructionSimplify.cpp.

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

Referenced by llvm::replaceAndRecursivelySimplify().

◆ simplifyAddInst()

static Value * simplifyAddInst ( Value Op0,
Value Op1,
bool  IsNSW,
bool  IsNUW,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyAndCommutative()

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

◆ simplifyAndInst()

static 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 2016 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::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(), llvm::Or, simplifyAndCommutative(), simplifyAndOrOfCmps(), simplifyAssociativeBinOp(), simplifyByDomEq(), simplifyLogicOfAddSub(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::InstrInfoQuery::UseInstrInfo, X, and Y.

Referenced by handleOtherCmpSelSimplifications(), simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyMulInst().

◆ simplifyAndOfICmps()

static Value * simplifyAndOfICmps ( ICmpInst Op0,
ICmpInst Op1,
const SimplifyQuery Q 
)
static

◆ simplifyAndOfICmpsWithAdd()

static Value * simplifyAndOfICmpsWithAdd ( ICmpInst Op0,
ICmpInst Op1,
const InstrInfoQuery IIQ 
)
static

◆ simplifyAndOrOfCmps()

static Value * simplifyAndOrOfCmps ( const SimplifyQuery Q,
Value Op0,
Value Op1,
bool  IsAnd 
)
static

◆ simplifyAndOrOfFCmps()

static Value * simplifyAndOrOfFCmps ( const SimplifyQuery Q,
FCmpInst LHS,
FCmpInst RHS,
bool  IsAnd 
)
static

◆ simplifyAndOrOfICmpsWithConstants()

static 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 1607 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()

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

◆ simplifyAndOrWithICmpEq()

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

◆ simplifyAShrInst()

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

◆ simplifyAssociativeBinOp()

static 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 245 of file InstructionSimplify.cpp.

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

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

◆ simplifyBinOp() [1/2]

static 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 6067 of file InstructionSimplify.cpp.

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

◆ simplifyBinOp() [2/2]

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

◆ simplifyByDomEq()

static 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 707 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()

static Value * simplifyCastInst ( unsigned  CastOpc,
Value Op,
Type Ty,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyCmpInst()

static 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 6095 of file InstructionSimplify.cpp.

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

Referenced by simplifyCmpSelCase(), and threadCmpOverPHI().

◆ simplifyCmpSelCase()

static 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 110 of file InstructionSimplify.cpp.

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

Referenced by simplifyCmpSelFalseCase(), and simplifyCmpSelTrueCase().

◆ simplifyCmpSelFalseCase()

static 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 134 of file InstructionSimplify.cpp.

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

Referenced by threadCmpOverSelect().

◆ simplifyCmpSelOfMaxMin()

static Value * simplifyCmpSelOfMaxMin ( Value CmpLHS,
Value CmpRHS,
CmpPredicate  Pred,
Value TVal,
Value FVal 
)
static

◆ simplifyCmpSelTrueCase()

static 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 126 of file InstructionSimplify.cpp.

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

Referenced by threadCmpOverSelect().

◆ simplifyDiv()

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

◆ simplifyDivRem()

static Value * simplifyDivRem ( Instruction::BinaryOps  Opcode,
Value Op0,
Value Op1,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyExtractElementInst()

static Value * simplifyExtractElementInst ( Value Vec,
Value Idx,
const SimplifyQuery Q,
unsigned   
)
static

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

If not, this returns null.

Definition at line 5222 of file InstructionSimplify.cpp.

References llvm::findScalarElement(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantExpr::getExtractElement(), llvm::getSplatValue(), llvm::Value::getType(), Idx, llvm::SimplifyQuery::isUndefValue(), and llvm::Splat.

Referenced by simplifyInstructionWithOperands().

◆ simplifyExtractValueInst()

static Value * simplifyExtractValueInst ( Value Agg,
ArrayRef< unsigned Idxs,
const SimplifyQuery ,
unsigned   
)
static

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

If not, this returns null.

Definition at line 5192 of file InstructionSimplify.cpp.

References llvm::ConstantFoldExtractValueInstruction(), llvm::ArrayRef< T >::size(), and llvm::ArrayRef< T >::slice().

Referenced by simplifyInstructionWithOperands().

◆ simplifyFAddInst()

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

◆ simplifyFCmpInst()

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

◆ simplifyFDivInst()

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

◆ simplifyFMAFMul()

static Value * simplifyFMAFMul ( Value Op0,
Value Op1,
FastMathFlags  FMF,
const SimplifyQuery Q,
unsigned  MaxRecurse,
fp::ExceptionBehavior  ExBehavior,
RoundingMode  Rounding 
)
static

◆ simplifyFMulInst()

static 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 5836 of file InstructionSimplify.cpp.

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

Referenced by simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyIntrinsic().

◆ simplifyFNegInst()

static 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 5551 of file InstructionSimplify.cpp.

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

Referenced by simplifyFPUnOp(), simplifyInstructionWithOperands(), and simplifyUnOp().

◆ simplifyFPOp()

static Constant * simplifyFPOp ( ArrayRef< Value * >  Ops,
FastMathFlags  FMF,
const SimplifyQuery Q,
fp::ExceptionBehavior  ExBehavior,
RoundingMode  Rounding 
)
static

◆ simplifyFPUnOp()

static 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 5994 of file InstructionSimplify.cpp.

References simplifyFNegInst(), and simplifyUnOp().

◆ simplifyFreezeInst()

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

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

Definition at line 7010 of file InstructionSimplify.cpp.

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

◆ simplifyFRemInst()

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

◆ simplifyFSubInst()

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

◆ simplifyGEPInst()

static 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 4972 of file InstructionSimplify.cpp.

References llvm::all_of(), llvm::any_of(), llvm::ArrayRef< T >::back(), llvm::CallingConv::C, llvm::ConstantFoldConstant(), llvm::ConstantFoldGetElementPtr(), llvm::SimplifyQuery::DL, llvm::ArrayRef< T >::drop_back(), llvm::ArrayRef< T >::empty(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::Type::getContext(), llvm::ConstantExpr::getGetElementPtr(), llvm::GetElementPtrInst::getIndexedType(), llvm::DataLayout::getIndexSizeInBits(), llvm::ConstantExpr::getIntToPtr(), llvm::DataLayout::getPointerSizeInBits(), getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeSizeInBits(), llvm::getUnderlyingObject(), Idx, llvm::APInt::isOne(), llvm::Type::isScalableTy(), llvm::Type::isSized(), 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::PatternMatch::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 simplifyInstructionWithOperands().

◆ simplifyICmpInst()

static 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 3725 of file InstructionSimplify.cpp.

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

Referenced by isICmpTrue(), simplifyCmpInst(), simplifyICmpInst(), simplifyICmpWithBinOp(), simplifyICmpWithMinMax(), and simplifyInstructionWithOperands().

◆ simplifyICmpOfBools()

static 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 2815 of file InstructionSimplify.cpp.

References llvm::SimplifyQuery::DL, getCompareTy(), getFalse(), getTrue(), llvm::Value::getType(), 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::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), RHS, and X.

Referenced by simplifyICmpInst().

◆ simplifyICmpUsingMonotonicValues()

static Value * simplifyICmpUsingMonotonicValues ( CmpPredicate  Pred,
Value LHS,
Value RHS 
)
static

◆ simplifyICmpWithBinOp()

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

◆ simplifyICmpWithBinOpOnLHS()

static Value * simplifyICmpWithBinOpOnLHS ( CmpPredicate  Pred,
BinaryOperator LBO,
Value RHS,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyICmpWithConstant()

static Value * simplifyICmpWithConstant ( CmpPredicate  Pred,
Value LHS,
Value RHS,
const InstrInfoQuery IIQ 
)
static

◆ simplifyICmpWithDominatingAssume()

static Value * simplifyICmpWithDominatingAssume ( CmpPredicate  Predicate,
Value LHS,
Value RHS,
const SimplifyQuery Q 
)
static

◆ simplifyICmpWithIntrinsicOnLHS()

static Value * simplifyICmpWithIntrinsicOnLHS ( CmpPredicate  Pred,
Value LHS,
Value RHS 
)
static

◆ simplifyICmpWithMinMax()

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

◆ simplifyICmpWithZero()

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

◆ simplifyInsertValueInst()

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

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

If not, this returns null.

Definition at line 5113 of file InstructionSimplify.cpp.

References llvm::ConstantFoldInsertValueInstruction(), llvm::Value::getType(), llvm::isGuaranteedNotToBePoison(), and llvm::SimplifyQuery::isUndefValue().

Referenced by simplifyInstructionWithOperands().

◆ simplifyInstructionWithOperands()

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

◆ simplifyIntrinsic()

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

◆ simplifyLdexp()

static Value * simplifyLdexp ( Value Op0,
Value Op1,
const SimplifyQuery Q,
bool  IsStrict 
)
static

◆ simplifyLogicOfAddSub()

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

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)).

Definition at line 1940 of file InstructionSimplify.cpp.

References assert(), llvm::ConstantExpr::getNot(), llvm::Value::getType(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.

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

◆ simplifyLShrInst()

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

◆ simplifyMulInst()

static Value * simplifyMulInst ( Value Op0,
Value Op1,
bool  IsNSW,
bool  IsNUW,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyOrInst()

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

◆ simplifyOrLogic()

static Value * simplifyOrLogic ( Value X,
Value Y 
)
static

◆ simplifyOrOfICmps()

static Value * simplifyOrOfICmps ( ICmpInst Op0,
ICmpInst Op1,
const SimplifyQuery Q 
)
static

◆ simplifyOrOfICmpsWithAdd()

static Value * simplifyOrOfICmpsWithAdd ( ICmpInst Op0,
ICmpInst Op1,
const InstrInfoQuery IIQ 
)
static

◆ simplifyPHINode()

static Value * simplifyPHINode ( PHINode PN,
ArrayRef< Value * >  IncomingValues,
const SimplifyQuery Q 
)
static

◆ simplifyRelativeLoad()

static Value * simplifyRelativeLoad ( Constant Ptr,
Constant Offset,
const DataLayout DL 
)
static

◆ simplifyRem()

static Value * simplifyRem ( Instruction::BinaryOps  Opcode,
Value Op0,
Value Op1,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyRightShift()

static 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 1358 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()

static 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 1198 of file InstructionSimplify.cpp.

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

Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().

◆ simplifySelectBitTest()

static 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 4471 of file InstructionSimplify.cpp.

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

Referenced by simplifySelectWithFakeICmpEq(), and simplifySelectWithICmpCond().

◆ simplifySelectInst()

static Value * simplifySelectInst ( Value Cond,
Value TrueVal,
Value FalseVal,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifySelectWithEquivalence()

static Value * simplifySelectWithEquivalence ( Value CmpLHS,
Value CmpRHS,
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 4598 of file InstructionSimplify.cpp.

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

Referenced by simplifySelectWithFCmp(), and simplifySelectWithICmpCond().

◆ simplifySelectWithFakeICmpEq()

static Value * simplifySelectWithFakeICmpEq ( Value CmpLHS,
Value CmpRHS,
CmpPredicate  Pred,
Value TrueVal,
Value FalseVal 
)
static

An alternative way to test if a bit is set or not uses sgt/slt instead of eq/ne.

Definition at line 4586 of file InstructionSimplify.cpp.

References llvm::decomposeBitTestICmp(), and simplifySelectBitTest().

Referenced by simplifySelectWithICmpCond().

◆ simplifySelectWithFCmp()

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

Try to simplify a select instruction when its condition operand is a floating-point comparison.

Definition at line 4741 of file InstructionSimplify.cpp.

References Cond, llvm::SimplifyQuery::CxtI, F, llvm::Instruction::hasNoSignedZeros(), I, llvm::PatternMatch::m_FCmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifySelectWithEquivalence(), and std::swap().

Referenced by simplifySelectInst().

◆ simplifySelectWithICmpCond()

static Value * simplifySelectWithICmpCond ( Value CondVal,
Value TrueVal,
Value FalseVal,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyShift()

static Value * simplifyShift ( Instruction::BinaryOps  Opcode,
Value Op0,
Value Op1,
bool  IsNSW,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyShlInst()

static Value * simplifyShlInst ( Value Op0,
Value Op1,
bool  IsNSW,
bool  IsNUW,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyShuffleVectorInst()

static Value * simplifyShuffleVectorInst ( Value Op0,
Value Op1,
ArrayRef< int >  Mask,
Type RetTy,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifySRemInst()

static 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 1226 of file InstructionSimplify.cpp.

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

Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().

◆ simplifySubInst()

static Value * simplifySubInst ( Value Op0,
Value Op1,
bool  IsNSW,
bool  IsNUW,
const SimplifyQuery Q,
unsigned  MaxRecurse 
)
static

◆ simplifyUDivInst()

static 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 1214 of file InstructionSimplify.cpp.

References simplifyDiv().

Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().

◆ simplifyUnaryIntrinsic()

static Value * simplifyUnaryIntrinsic ( Function F,
Value Op0,
const SimplifyQuery Q,
const CallBase Call 
)
static

◆ simplifyUnOp()

static 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 5981 of file InstructionSimplify.cpp.

References llvm_unreachable, and simplifyFNegInst().

Referenced by simplifyFPUnOp().

◆ simplifyUnsignedRangeCheck()

static Value * simplifyUnsignedRangeCheck ( ICmpInst ZeroICmp,
ICmpInst UnsignedICmp,
bool  IsAnd,
const SimplifyQuery Q 
)
static

◆ simplifyURemInst()

static 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 1247 of file InstructionSimplify.cpp.

References simplifyRem().

Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().

◆ simplifyWithOpReplaced()

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

◆ simplifyXorInst()

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

◆ STATISTIC() [1/2]

STATISTIC ( NumExpand  ,
"Number of expansions"   
)

◆ STATISTIC() [2/2]

STATISTIC ( NumReassoc  ,
"Number of reassociations"   
)

◆ stripAndComputeConstantOffsets()

static 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 670 of file InstructionSimplify.cpp.

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

Referenced by computePointerDifference().

◆ threadBinOpOverPHI()

static 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 473 of file InstructionSimplify.cpp.

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

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

◆ threadBinOpOverSelect()

static 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 349 of file InstructionSimplify.cpp.

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

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

◆ threadCmpOverPHI()

static 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 520 of file InstructionSimplify.cpp.

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

Referenced by simplifyFCmpInst(), and simplifyICmpInst().

◆ threadCmpOverSelect()

static 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 428 of file InstructionSimplify.cpp.

References assert(), Cond, llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), handleOtherCmpSelSimplifications(), llvm::Type::isVectorTy(), LHS, RHS, simplifyCmpSelFalseCase(), simplifyCmpSelTrueCase(), and std::swap().

Referenced by simplifyFCmpInst(), and simplifyICmpInst().

◆ tryConstantFoldCall()

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

◆ trySimplifyICmpWithAdds()

static bool trySimplifyICmpWithAdds ( CmpPredicate  Pred,
Value LHS,
Value RHS,
const InstrInfoQuery IIQ 
)
static

◆ valueDominatesPHI()

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

Does the given value dominate the specified phi node?

Definition at line 171 of file InstructionSimplify.cpp.

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

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