LLVM 20.0.0git
|
#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 } |
Functions | |
STATISTIC (NumExpand, "Number of expansions") | |
STATISTIC (NumReassoc, "Number of reassociations") | |
static Value * | simplifyAndInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an And, see if we can fold the result. | |
static Value * | simplifyUnOp (unsigned Opcode, Value *Op, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given the operand for a UnaryOperator, see if we can fold the result. | |
static Value * | simplifyFPUnOp (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 Value * | simplifyBinOp (unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a BinaryOperator, see if we can fold the result. | |
static Value * | simplifyBinOp (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 Value * | simplifyCmpInst (unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a CmpInst, see if we can fold the result. | |
static Value * | simplifyICmpInst (unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an ICmpInst, see if we can fold the result. | |
static Value * | simplifyOrInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an Or, see if we can fold the result. | |
static Value * | simplifyXorInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a Xor, see if we can fold the result. | |
static Value * | simplifyCastInst (unsigned, Value *, Type *, const SimplifyQuery &, unsigned) |
static Value * | simplifyGEPInst (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 Value * | simplifySelectInst (Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a SelectInst, see if we can fold the result. | |
static Value * | simplifyInstructionWithOperands (Instruction *I, ArrayRef< Value * > NewOps, const SimplifyQuery &SQ, unsigned MaxRecurse) |
See if we can compute a simplified version of this instruction. | |
static Value * | foldSelectWithBinaryOp (Value *Cond, Value *TrueVal, Value *FalseVal) |
static Constant * | getFalse (Type *Ty) |
For a boolean type or a vector of boolean type, return false or a vector with every element false. | |
static Constant * | getTrue (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, CmpInst::Predicate Pred, Value *LHS, Value *RHS) |
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"? | |
static Value * | simplifyCmpSelCase (CmpInst::Predicate 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 Value * | simplifyCmpSelTrueCase (CmpInst::Predicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse) |
Simplify comparison with true branch of select. | |
static Value * | simplifyCmpSelFalseCase (CmpInst::Predicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse) |
Simplify comparison with false branch of select. | |
static Value * | handleOtherCmpSelSimplifications (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 Value * | expandBinOp (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 Value * | expandCommutativeBinOp (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 Value * | simplifyAssociativeBinOp (Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
Generic simplifications for associative binary operations. | |
static Value * | threadBinOpOverSelect (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 Value * | threadCmpOverSelect (CmpInst::Predicate 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 Value * | threadBinOpOverPHI (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 Value * | threadCmpOverPHI (CmpInst::Predicate 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 Constant * | foldOrCommuteConstant (Instruction::BinaryOps Opcode, Value *&Op0, Value *&Op1, const SimplifyQuery &Q) |
static Value * | simplifyAddInst (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 Constant * | computePointerDifference (const DataLayout &DL, Value *LHS, Value *RHS) |
Compute the constant difference between two pointer values. | |
static Value * | simplifyByDomEq (unsigned Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Test if there is a dominating equivalence condition for the two operands. | |
static Value * | simplifySubInst (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 Value * | simplifyMulInst (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 (ICmpInst::Predicate 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 Value * | simplifyDivRem (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 Value * | simplifyDiv (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse) |
These are simplifications common to SDiv and UDiv. | |
static Value * | simplifyRem (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
These are simplifications common to SRem and URem. | |
static Value * | simplifySDivInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an SDiv, see if we can fold the result. | |
static Value * | simplifyUDivInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a UDiv, see if we can fold the result. | |
static Value * | simplifySRemInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an SRem, see if we can fold the result. | |
static Value * | simplifyURemInst (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 Value * | simplifyShift (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 Value * | simplifyRightShift (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 Value * | simplifyShlInst (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 Value * | simplifyLShrInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an LShr, see if we can fold the result. | |
static Value * | simplifyAShrInst (Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an AShr, see if we can fold the result. | |
static Value * | simplifyUnsignedRangeCheck (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 Value * | simplifyAndOrOfICmpsWithConstants (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 Value * | simplifyAndOfICmpsWithAdd (ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ) |
static Value * | simplifyAndOrOfICmpsWithCtpop (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd) |
Try to simplify and/or of icmp with ctpop intrinsic. | |
static Value * | simplifyAndOfICmps (ICmpInst *Op0, ICmpInst *Op1, const SimplifyQuery &Q) |
static Value * | simplifyOrOfICmpsWithAdd (ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ) |
static Value * | simplifyOrOfICmps (ICmpInst *Op0, ICmpInst *Op1, const SimplifyQuery &Q) |
static Value * | simplifyAndOrOfFCmps (const SimplifyQuery &Q, FCmpInst *LHS, FCmpInst *RHS, bool IsAnd) |
static Value * | simplifyAndOrOfCmps (const SimplifyQuery &Q, Value *Op0, Value *Op1, bool IsAnd) |
static Value * | simplifyWithOpReplaced (Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags, unsigned MaxRecurse) |
static Value * | simplifyAndOrWithICmpEq (unsigned Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
static Value * | simplifyLogicOfAddSub (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 Value * | simplifyAndCommutative (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
static Value * | simplifyOrLogic (Value *X, Value *Y) |
static Type * | getCompareTy (Value *Op) |
static Value * | extractEquivalentCondition (Value *V, CmpInst::Predicate 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 Constant * | computePointerICmp (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q) |
static Value * | simplifyICmpOfBools (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q) |
Fold an icmp when its operands have i1 scalar type. | |
static Value * | simplifyICmpWithZero (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q) |
Try hard to fold icmp with zero RHS because this is a common case. | |
static Value * | simplifyICmpWithConstant (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const InstrInfoQuery &IIQ) |
static Value * | simplifyICmpWithBinOpOnLHS (CmpInst::Predicate Pred, BinaryOperator *LBO, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
static bool | trySimplifyICmpWithAdds (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const InstrInfoQuery &IIQ) |
static Value * | simplifyICmpWithBinOp (CmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
TODO: A large part of this logic is duplicated in InstCombine's foldICmpBinOp(). | |
static Value * | simplifyICmpWithMinMax (CmpInst::Predicate 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 Value * | simplifyICmpWithDominatingAssume (CmpInst::Predicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q) |
static Value * | simplifyICmpWithIntrinsicOnLHS (CmpInst::Predicate Pred, Value *LHS, Value *RHS) |
static std::optional< ConstantRange > | getRange (Value *V, const InstrInfoQuery &IIQ) |
Helper method to get range from metadata or attribute. | |
static Value * | simplifyFCmpInst (unsigned Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an FCmpInst, see if we can fold the result. | |
static Value * | simplifySelectBitTest (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 Value * | simplifyCmpSelOfMaxMin (Value *CmpLHS, Value *CmpRHS, ICmpInst::Predicate Pred, Value *TVal, Value *FVal) |
static Value * | simplifySelectWithFakeICmpEq (Value *CmpLHS, Value *CmpRHS, ICmpInst::Predicate 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 Value * | simplifySelectWithICmpEq (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 comparison. | |
static Value * | simplifySelectWithICmpCond (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 Value * | simplifySelectWithFCmp (Value *Cond, Value *T, Value *F, const SimplifyQuery &Q) |
Try to simplify a select instruction when its condition operand is a floating-point comparison. | |
static Value * | simplifyInsertValueInst (Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q, unsigned) |
Given operands for an InsertValueInst, see if we can fold the result. | |
static Value * | simplifyExtractValueInst (Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &, unsigned) |
Given operands for an ExtractValueInst, see if we can fold the result. | |
static Value * | simplifyExtractElementInst (Value *Vec, Value *Idx, const SimplifyQuery &Q, unsigned) |
Given operands for an ExtractElementInst, see if we can fold the result. | |
static Value * | simplifyPHINode (PHINode *PN, ArrayRef< Value * > IncomingValues, const SimplifyQuery &Q) |
See if we can fold the given phi. If not, returns null. | |
static Value * | foldIdentityShuffles (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 Value * | simplifyShuffleVectorInst (Value *Op0, Value *Op1, ArrayRef< int > Mask, Type *RetTy, const SimplifyQuery &Q, unsigned MaxRecurse) |
static Constant * | foldConstant (Instruction::UnaryOps Opcode, Value *&Op, const SimplifyQuery &Q) |
static Value * | simplifyFNegInst (Value *Op, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given the operand for an FNeg, see if we can fold the result. | |
static Constant * | propagateNaN (Constant *In) |
Try to propagate existing NaN values when possible. | |
static Constant * | simplifyFPOp (ArrayRef< Value * > Ops, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior, RoundingMode Rounding) |
Perform folds that are common to any floating-point operation. | |
static Value * | simplifyFAddInst (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 Value * | simplifyFSubInst (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 Value * | simplifyFMAFMul (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse, fp::ExceptionBehavior ExBehavior, RoundingMode Rounding) |
static Value * | simplifyFMulInst (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 Value * | simplifyFDivInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven) |
static Value * | simplifyFRemInst (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 Value * | simplifyRelativeLoad (Constant *Ptr, Constant *Offset, const DataLayout &DL) |
static Value * | simplifyLdexp (Value *Op0, Value *Op1, const SimplifyQuery &Q, bool IsStrict) |
static Value * | simplifyUnaryIntrinsic (Function *F, Value *Op0, const SimplifyQuery &Q, const CallBase *Call) |
static Value * | foldMinMaxSharedOp (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 Value * | foldMinimumMaximumSharedOp (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 Value * | simplifyIntrinsic (CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q) |
static Value * | tryConstantFoldCall (CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q) |
static Value * | simplifyFreezeInst (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 &) |
#define DEBUG_TYPE "instsimplify" |
Definition at line 50 of file InstructionSimplify.cpp.
#define HANDLE_CAST_INST | ( | num, | |
opc, | |||
clas | |||
) | case Instruction::opc: |
anonymous enum |
Enumerator | |
---|---|
RecursionLimit |
Definition at line 52 of file InstructionSimplify.cpp.
|
static |
Compute the constant difference between two pointer values.
If the difference is not a constant, returns zero.
Definition at line 730 of file InstructionSimplify.cpp.
References DL, llvm::Value::getContext(), llvm::ConstantVector::getSplat(), llvm::Value::getType(), LHS, RHS, and stripAndComputeConstantOffsets().
Referenced by simplifySubInst().
|
static |
Definition at line 2722 of file InstructionSimplify.cpp.
References A, llvm::all_of(), assert(), llvm::CaptureTracker::captured(), llvm::ICmpInst::compare(), llvm::SimplifyQuery::DL, DL, llvm::ObjectSizeOpts::EvalMode, F, getCompareTy(), llvm::getObjectSize(), llvm::ICmpInst::getSignedPredicate(), llvm::Value::getType(), llvm::getUnderlyingObjects(), haveNonOverlappingStorage(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, isAllocDisjoint(), llvm::isAllocLikeFn(), llvm::ICmpInst::isEquality(), llvm::CmpInst::isFalseWhenEqual(), llvm::isKnownNonZero(), llvm::isNoAliasCall(), llvm::APInt::isNonNegative(), llvm::CmpInst::isTrueWhenEqual(), LHS, MI, llvm::ObjectSizeOpts::NullIsUnknownSize, llvm::NullPointerIsDefined(), llvm::PointerMayBeCaptured(), RHS, llvm::Value::stripAndAccumulateConstantOffsets(), llvm::SimplifyQuery::TLI, llvm::CaptureTracker::tooManyUses(), and llvm::APInt::ult().
Referenced by simplifyICmpInst().
|
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 239 of file InstructionSimplify.cpp.
References B, llvm::SimplifyQuery::getWithoutUndef(), llvm::Instruction::isCommutative(), and simplifyBinOp().
Referenced by expandCommutativeBinOp().
|
static |
Try to simplify binops of form "A op (B op' C)" or the commuted variant by distributing op over op'.
Definition at line 273 of file InstructionSimplify.cpp.
References expandBinOp().
Referenced by simplifyAndInst(), simplifyMulInst(), and simplifyOrInst().
|
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 2613 of file InstructionSimplify.cpp.
References llvm::CmpInst::getSwappedPredicate(), LHS, and RHS.
Referenced by simplifyICmpWithMinMax().
|
static |
Definition at line 5559 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldUnaryOpOperand(), and llvm::SimplifyQuery::DL.
Referenced by simplifyFMAFMul(), simplifyFNegInst(), and simplifyFSubInst().
|
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 5392 of file InstructionSimplify.cpp.
References foldIdentityShuffles(), and llvm::Value::getType().
Referenced by foldIdentityShuffles(), and simplifyShuffleVectorInst().
|
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 6408 of file InstructionSimplify.cpp.
References assert(), llvm::getInverseMinMaxIntrinsic(), llvm::M0(), and llvm::M1().
Referenced by llvm::simplifyBinaryIntrinsic().
|
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 6383 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().
|
static |
Definition at line 608 of file InstructionSimplify.cpp.
References llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldFPInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::Instruction::isCommutative(), and std::swap().
Referenced by simplifyAddInst(), simplifyAndInst(), simplifyDiv(), simplifyFAddInst(), simplifyFDivInst(), simplifyFMulInst(), simplifyFRemInst(), simplifyFSubInst(), simplifyMulInst(), simplifyOrInst(), simplifyRem(), simplifyShift(), simplifySubInst(), and simplifyXorInst().
Definition at line 84 of file InstructionSimplify.cpp.
References Cond, llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_SpecificICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
Referenced by simplifySelectInst().
Definition at line 2606 of file InstructionSimplify.cpp.
References llvm::CmpInst::makeCmpResultType().
Referenced by computePointerICmp(), simplifyFCmpInst(), simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithBinOpOnLHS(), simplifyICmpWithConstant(), simplifyICmpWithDominatingAssume(), simplifyICmpWithIntrinsicOnLHS(), simplifyICmpWithMinMax(), and simplifyICmpWithZero().
For a boolean type or a vector of boolean type, return false or a vector with every element false.
Definition at line 128 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getFalse().
Referenced by simplifyAndOfICmpsWithAdd(), simplifyAndOrOfICmpsWithConstants(), simplifyCmpSelFalseCase(), simplifyFCmpInst(), simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOpOnLHS(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), and simplifyUnsignedRangeCheck().
|
static |
Helper method to get range from metadata or attribute.
Definition at line 3753 of file InstructionSimplify.cpp.
References A, llvm::getConstantRangeFromMetadata(), llvm::InstrInfoQuery::getMetadata(), and I.
Referenced by getFromRangeMetadata(), llvm::SelectionDAGBuilder::lowerRangeToAssertZExt(), and simplifyICmpInst().
For a boolean type or a vector of boolean type, return true or a vector with every element true.
Definition at line 132 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getTrue().
Referenced by simplifyAndOrOfICmpsWithConstants(), simplifyCmpSelTrueCase(), simplifyFCmpInst(), simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOpOnLHS(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), simplifyOrOfICmpsWithAdd(), and simplifyUnsignedRangeCheck().
|
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 189 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().
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 2652 of file InstructionSimplify.cpp.
References A.
Referenced by computePointerICmp().
Return true if the underlying object (storage) must be disjoint from storage returned by any noalias return call.
Definition at line 2632 of file InstructionSimplify.cpp.
References A.
Referenced by computePointerICmp().
|
static |
Return true if we can simplify X / Y to 0.
Remainder can adapt that answer to simplify X % Y to X.
Definition at line 1013 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::computeKnownBits(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, isICmpTrue(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
Referenced by simplifyDivRem().
|
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 1004 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, LHS, RHS, and simplifyICmpInst().
Referenced by isDivZero(), and llvm::simplifyBinaryIntrinsic().
|
static |
Definition at line 6124 of file InstructionSimplify.cpp.
Referenced by simplifyUnaryIntrinsic().
|
static |
Returns true if a shift by Amount
always yields poison.
Definition at line 1317 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::APInt::getBitWidth(), I, isPoisonShift(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), and llvm::APInt::uge().
Referenced by isPoisonShift(), and simplifyShift().
|
static |
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
Definition at line 135 of file InstructionSimplify.cpp.
References llvm::CmpInst::getSwappedPredicate(), LHS, and RHS.
Referenced by simplifyCmpSelCase().
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 5588 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().
|
static |
Return true if the intrinsic rounds a floating-point value to an integral floating-point value (not an integer type).
Definition at line 6146 of file InstructionSimplify.cpp.
Referenced by simplifyUnaryIntrinsic().
|
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 7243 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().
|
static |
Given operands for an Add, see if we can fold the result.
If not, this returns null.
i1 add -> xor.
Definition at line 636 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownNegation(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifyAssociativeBinOp(), simplifyXorInst(), and Y.
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Definition at line 2019 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isCheckForZeroAndMulWithOverflow(), llvm::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyAndOrWithICmpEq(), llvm::APInt::uge(), X, and Y.
Referenced by simplifyAndInst().
|
static |
Given operands for an And, see if we can fold the result.
If not, this returns null.
Definition at line 2072 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().
|
static |
Definition at line 1772 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::IIQ, simplifyAndOfICmpsWithAdd(), simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithCtpop(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
|
static |
Definition at line 1704 of file InstructionSimplify.cpp.
References llvm::APInt::getBoolValue(), getFalse(), llvm::User::getOperand(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::APInt::isStrictlyPositive(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by simplifyAndOfICmps().
|
static |
Definition at line 1902 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldCastOperand(), llvm::SimplifyQuery::DL, simplifyAndOfICmps(), simplifyAndOrOfFCmps(), and simplifyOrOfICmps().
Referenced by simplifyAndInst(), and simplifyOrInst().
|
static |
Definition at line 1865 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getBool(), llvm::Value::getType(), LHS, llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::match(), and RHS.
Referenced by simplifyAndOrOfCmps().
|
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 1667 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().
|
static |
Try to simplify and/or of icmp with ctpop intrinsic.
Definition at line 1752 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::match(), and X.
Referenced by simplifyAndOfICmps(), and simplifyOrOfICmps().
|
static |
Definition at line 1945 of file InstructionSimplify.cpp.
References A, assert(), B, llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), llvm::SimplifyQuery::getWithoutUndef(), llvm::ICmpInst::isEquality(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and simplifyWithOpReplaced().
Referenced by simplifyAndCommutative(), and simplifyOrInst().
|
static |
Given operands for an AShr, see if we can fold the result.
If not, this returns null.
Definition at line 1525 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::ComputeNumSignBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::Constant::getAllOnesValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyRightShift(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Generic simplifications for associative binary operations.
Returns the simpler value, or null if none was found.
Definition at line 291 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().
|
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 6084 of file InstructionSimplify.cpp.
References LHS, RHS, simplifyBinOp(), simplifyFAddInst(), simplifyFDivInst(), simplifyFMulInst(), and simplifyFSubInst().
|
static |
Given operands for a BinaryOperator, see if we can fold the result.
If not, this returns null.
Definition at line 6033 of file InstructionSimplify.cpp.
References LHS, llvm_unreachable, RHS, simplifyAddInst(), simplifyAndInst(), simplifyAShrInst(), simplifyFAddInst(), simplifyFDivInst(), simplifyFMulInst(), simplifyFRemInst(), simplifyFSubInst(), simplifyLShrInst(), simplifyMulInst(), simplifyOrInst(), simplifySDivInst(), simplifyShlInst(), simplifySRemInst(), simplifySubInst(), simplifyUDivInst(), simplifyURemInst(), and simplifyXorInst().
Referenced by expandBinOp(), simplifyAssociativeBinOp(), simplifyBinOp(), simplifySubInst(), threadBinOpOverPHI(), and threadBinOpOverSelect().
|
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 754 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().
|
static |
Definition at line 5342 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldCastOperand(), llvm::SimplifyQuery::DL, llvm::DataLayout::getIndexType(), llvm::DataLayout::getIntPtrType(), llvm::CastInst::isEliminableCastPair(), llvm::Type::isPtrOrPtrVectorTy(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_PtrAdd(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Ptr, and X.
Referenced by simplifyInstructionWithOperands(), and simplifySubInst().
|
static |
Given operands for a CmpInst, see if we can fold the result.
Definition at line 6112 of file InstructionSimplify.cpp.
References llvm::CmpInst::isIntPredicate(), LHS, RHS, simplifyFCmpInst(), and simplifyICmpInst().
Referenced by simplifyCmpSelCase(), and threadCmpOverPHI().
|
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 153 of file InstructionSimplify.cpp.
References Cond, isSameCompare(), LHS, RHS, and simplifyCmpInst().
Referenced by simplifyCmpSelFalseCase(), and simplifyCmpSelTrueCase().
|
static |
Simplify comparison with false branch of select.
Definition at line 179 of file InstructionSimplify.cpp.
References Cond, getFalse(), LHS, RHS, and simplifyCmpSelCase().
Referenced by threadCmpOverSelect().
|
static |
Definition at line 4550 of file InstructionSimplify.cpp.
References llvm::CmpInst::getInversePredicate(), llvm::CmpInst::getStrictPredicate(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::PatternMatch::m_c_MaxOrMin(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), std::swap(), X, and Y.
Referenced by simplifySelectWithICmpCond().
|
static |
Simplify comparison with true branch of select.
Definition at line 170 of file InstructionSimplify.cpp.
References Cond, getTrue(), LHS, RHS, and simplifyCmpSelCase().
Referenced by threadCmpOverSelect().
|
static |
These are simplifications common to SDiv and UDiv.
Definition at line 1186 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::computeKnownBits(), llvm::KnownBits::countMaxTrailingZeros(), llvm::APInt::countr_zero(), foldOrCommuteConstant(), llvm::PoisonValue::get(), llvm::Value::getType(), llvm::APInt::isPowerOf2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyDivRem(), and X.
Referenced by simplifySDivInst(), and simplifyUDivInst().
|
static |
Check for common or similar folds of integer division or integer remainder.
This applies to all 4 opcodes (sdiv/udiv/srem/urem).
Definition at line 1079 of file InstructionSimplify.cpp.
References llvm::computeKnownBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::KnownBits::getBitWidth(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::SimplifyQuery::IIQ, isDivZero(), llvm::Constant::isNullValue(), llvm::SimplifyQuery::isUndefValue(), llvm::KnownBits::isZero(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), Mul, simplifyByDomEq(), threadBinOpOverPHI(), threadBinOpOverSelect(), and X.
Referenced by simplifyDiv(), and simplifyRem().
|
static |
Given operands for an ExtractElementInst, see if we can fold the result.
If not, this returns null.
Definition at line 5246 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().
|
static |
Given operands for an ExtractValueInst, see if we can fold the result.
If not, this returns null.
Definition at line 5216 of file InstructionSimplify.cpp.
References llvm::ConstantFoldExtractValueInstruction(), llvm::ArrayRef< T >::size(), and llvm::ArrayRef< T >::slice().
Referenced by simplifyInstructionWithOperands().
|
static |
Given operands for an FAdd, see if we can fold the result.
If not, this returns null.
Definition at line 5672 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::CallingConv::C, llvm::canIgnoreSNaN(), llvm::cannotBeNegativeZero(), llvm::canRoundingModeBe(), foldOrCommuteConstant(), llvm::Value::getType(), llvm::ConstantFP::getZero(), llvm::isDefaultFPEnvironment(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_Inf(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPOp(), and X.
Referenced by simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyIntrinsic().
|
static |
Given operands for an FCmpInst, see if we can fold the result.
If not, this returns null.
Definition at line 4085 of file InstructionSimplify.cpp.
References assert(), llvm::CallingConv::C, llvm::KnownFPClass::cannotBeOrderedLessThanZero(), llvm::computeKnownFPClass(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::fcAllFlags, llvm::CmpInst::FCMP_UNO, llvm::fcmpToClassTest(), llvm::fcNan, llvm::fcNone, llvm::PoisonValue::get(), getCompareTy(), getFalse(), llvm::Instruction::getFunction(), llvm::CmpInst::getSwappedPredicate(), getTrue(), 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_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::KnownFPClass::OrderedLessThanZeroMask, RetTy, RHS, std::swap(), threadCmpOverPHI(), threadCmpOverSelect(), and llvm::SimplifyQuery::TLI.
Referenced by simplifyCmpInst(), and simplifyInstructionWithOperands().
|
static |
Definition at line 5898 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::CallingConv::C, foldOrCommuteConstant(), llvm::PoisonValue::get(), llvm::Value::getType(), llvm::ConstantFP::getZero(), llvm::isDefaultFPEnvironment(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_FNegNSZ(), llvm::PatternMatch::m_FPOne(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noInfs(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPOp(), and X.
Referenced by simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyIntrinsic().
|
static |
Definition at line 5804 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::CallingConv::C, llvm::computeKnownFPClass(), llvm::fcInf, llvm::fcNan, foldConstant(), llvm::Value::getType(), llvm::ConstantFP::getZero(), llvm::isDefaultFPEnvironment(), llvm::KnownFPClass::isKnownNever(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_FPOne(), llvm::PatternMatch::m_Sqrt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), llvm::KnownFPClass::SignBit, simplifyFPOp(), std::swap(), and X.
Referenced by simplifyFMulInst().
|
static |
Given the operands for an FMul, see if we can fold the result.
Definition at line 5853 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, foldOrCommuteConstant(), llvm::isDefaultFPEnvironment(), and simplifyFMAFMul().
Referenced by simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyIntrinsic().
|
static |
Given the operand for an FNeg, see if we can fold the result.
If not, this returns null.
Definition at line 5568 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().
|
static |
Perform folds that are common to any floating-point operation.
This implies transforms based on poison/undef/NaN because the operation itself makes no difference to the result.
Definition at line 5630 of file InstructionSimplify.cpp.
References llvm::any_of(), llvm::fp::ebStrict, llvm::PoisonValue::get(), llvm::ConstantFP::getNaN(), getType(), llvm::isDefaultFPEnvironment(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Inf(), llvm::PatternMatch::m_NaN(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::match(), llvm::FastMathFlags::noInfs(), llvm::FastMathFlags::noNaNs(), and propagateNaN().
Referenced by simplifyFAddInst(), simplifyFDivInst(), simplifyFMAFMul(), simplifyFRemInst(), simplifyFSubInst(), and simplifyIntrinsic().
|
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 6011 of file InstructionSimplify.cpp.
References simplifyFNegInst(), and simplifyUnOp().
|
static |
Given operands for a Freeze, see if we can fold the result.
Definition at line 7027 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DT, and llvm::isGuaranteedNotToBeUndefOrPoison().
|
static |
Definition at line 5957 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, foldOrCommuteConstant(), llvm::ConstantFP::getNegativeZero(), llvm::Value::getType(), llvm::ConstantFP::getZero(), llvm::isDefaultFPEnvironment(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), and simplifyFPOp().
Referenced by simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyIntrinsic().
|
static |
Given operands for an FSub, see if we can fold the result.
If not, this returns null.
Definition at line 5738 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::CallingConv::C, llvm::canIgnoreSNaN(), llvm::cannotBeNegativeZero(), llvm::canRoundingModeBe(), foldConstant(), foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isDefaultFPEnvironment(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_c_FAdd(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_Inf(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPOp(), and X.
Referenced by simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyIntrinsic().
|
static |
Given operands for an GetElementPtrInst, see if we can fold the result.
If not, this returns null.
Definition at line 4996 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().
|
static |
Given operands for an ICmpInst, see if we can fold the result.
If not, this returns null.
Definition at line 3769 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(), 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().
|
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 2871 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().
|
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 3264 of file InstructionSimplify.cpp.
References A, assert(), B, llvm::CallingConv::C, D, getCompareTy(), llvm::ConstantInt::getFalse(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::SimplifyQuery::IIQ, 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::PatternMatch::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, simplifyICmpInst(), simplifyICmpWithBinOpOnLHS(), std::swap(), trySimplifyICmpWithAdds(), and Y.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3082 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::computeKnownBits(), llvm::APInt::getBitWidth(), getCompareTy(), getFalse(), getTrue(), llvm::ICmpInst::isEquality(), llvm::isKnownNonZero(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm_unreachable, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), RHS, llvm::APInt::ule(), and Y.
Referenced by simplifyICmpWithBinOp().
|
static |
Definition at line 3034 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::computeConstantRange(), llvm::ConstantRange::contains(), llvm::ConstantInt::getBool(), getCompareTy(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::ConstantRange::inverse(), llvm::ConstantRange::isEmptySet(), llvm::ICmpInst::isEquality(), llvm::ConstantRange::isFullSet(), llvm::isSignBitCheck(), llvm::CmpInst::isSigned(), LHS, llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_UIToFP(), llvm::PatternMatch::m_Value(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), RHS, llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3683 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::AssumptionCache::assumptionsFor(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::CallBase::getArgOperand(), getCompareTy(), llvm::isImpliedCondition(), llvm::isValidAssumeForContext(), LHS, and RHS.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3706 of file InstructionSimplify.cpp.
References getCompareTy(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), II, LHS, llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::match(), and RHS.
Referenced by simplifyICmpInst().
|
static |
simplify integer comparisons where at least one operand of the compare matches an integer min/max idiom.
Definition at line 3498 of file InstructionSimplify.cpp.
References A, B, llvm::CmpInst::BAD_ICMP_PREDICATE, llvm::CallingConv::C, D, extractEquivalentCondition(), getCompareTy(), getFalse(), llvm::CmpInst::getInversePredicate(), llvm::CmpInst::getSwappedPredicate(), 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, LHS, llvm::PatternMatch::m_SMax(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_UMax(), llvm::PatternMatch::m_UMin(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), P, RHS, simplifyICmpInst(), and std::swap().
Referenced by simplifyICmpInst().
|
static |
Try hard to fold icmp with zero RHS because this is a common case.
Definition at line 2974 of file InstructionSimplify.cpp.
References llvm::computeKnownBits(), getCompareTy(), getFalse(), getTrue(), llvm::isKnownNonZero(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), LHS, llvm_unreachable, llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), and RHS.
Referenced by simplifyICmpInst().
|
static |
Given operands for an InsertValueInst, see if we can fold the result.
If not, this returns null.
Definition at line 5137 of file InstructionSimplify.cpp.
References llvm::ConstantFoldInsertValueInstruction(), llvm::Value::getType(), llvm::isGuaranteedNotToBePoison(), and llvm::SimplifyQuery::isUndefValue().
Referenced by simplifyInstructionWithOperands().
|
static |
See if we can compute a simplified version of this instruction.
If not, this returns null.
Definition at line 7078 of file InstructionSimplify.cpp.
References llvm::all_of(), assert(), llvm::ArrayRef< T >::back(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), 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::InstrInfoQuery::isExact(), IV, simplifyAddInst(), simplifyAndInst(), simplifyAShrInst(), llvm::simplifyCall(), simplifyCastInst(), simplifyExtractElementInst(), simplifyExtractValueInst(), simplifyFAddInst(), simplifyFCmpInst(), simplifyFDivInst(), simplifyFMulInst(), simplifyFNegInst(), llvm::simplifyFreezeInst(), simplifyFRemInst(), simplifyFSubInst(), simplifyGEPInst(), simplifyICmpInst(), llvm::simplifyInsertElementInst(), simplifyInsertValueInst(), llvm::simplifyLoadInst(), simplifyLShrInst(), simplifyMulInst(), simplifyOrInst(), simplifyPHINode(), simplifySDivInst(), simplifySelectInst(), simplifyShlInst(), simplifyShuffleVectorInst(), simplifySRemInst(), simplifySubInst(), simplifyUDivInst(), simplifyURemInst(), simplifyXorInst(), llvm::ArrayRef< T >::size(), llvm::SimplifyQuery::TLI, and llvm::transform().
Referenced by llvm::simplifyInstruction(), and simplifyWithOpReplaced().
|
static |
Definition at line 6775 of file InstructionSimplify.cpp.
References assert(), llvm::BitWidth, llvm::CallingConv::C, llvm::fp::ebIgnore, F, llvm::ConstantPointerNull::get(), llvm::UndefValue::get(), llvm::GCRelocateInst::getBasePtr(), llvm::APInt::getBitWidth(), llvm::GCRelocateInst::getDerivedPtr(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::ConstantRange::getSingleElement(), llvm::Value::getType(), llvm::getVScaleRange(), Idx, llvm::APInt::isNonNegative(), llvm::SimplifyQuery::isUndefValue(), llvm::APInt::isZero(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::maskIsAllZeroOrUndef(), llvm::PatternMatch::match(), RetTy, llvm::simplifyBinaryIntrinsic(), simplifyFAddInst(), simplifyFDivInst(), simplifyFMulInst(), simplifyFPOp(), simplifyFRemInst(), simplifyFSubInst(), simplifyLdexp(), simplifyUnaryIntrinsic(), std::swap(), llvm::APInt::urem(), and X.
Referenced by llvm::simplifyCall(), and llvm::simplifyConstrainedFPCall().
|
static |
Definition at line 6215 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFP::getNaN(), llvm::Value::getType(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_ZeroInt(), and llvm::PatternMatch::match().
Referenced by llvm::simplifyBinaryIntrinsic(), and simplifyIntrinsic().
|
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 1996 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().
|
static |
Given operands for an LShr, see if we can fold the result.
If not, this returns null.
Definition at line 1488 of file InstructionSimplify.cpp.
References llvm::computeKnownBits(), llvm::KnownBits::countMaxActiveBits(), llvm::SimplifyQuery::IIQ, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyRightShift(), llvm::APInt::uge(), llvm::InstrInfoQuery::UseInstrInfo, X, and Y.
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Given operands for a Mul, see if we can fold the result.
If not, this returns null.
Definition at line 931 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, expandCommutativeBinOp(), foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, llvm::Type::isIntOrIntVectorTy(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_IDiv(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifyAndInst(), simplifyAssociativeBinOp(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Given operands for an Or, see if we can fold the result.
If not, this returns null.
Definition at line 2347 of file InstructionSimplify.cpp.
References A, B, llvm::CallingConv::C, llvm::SimplifyQuery::DL, expandCommutativeBinOp(), foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::isCheckForZeroAndMulWithOverflow(), llvm::isImpliedCondition(), llvm::Type::isIntOrIntVectorTy(), llvm::APInt::isMask(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shl(), 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::MaskedValueIsZero(), llvm::PatternMatch::match(), N, simplifyAndOrOfCmps(), simplifyAndOrWithICmpEq(), simplifyAssociativeBinOp(), simplifyByDomEq(), simplifyLogicOfAddSub(), simplifyOrLogic(), threadBinOpOverPHI(), threadBinOpOverSelect(), X, and Y.
Referenced by handleOtherCmpSelSimplifications(), simplifyBinOp(), and simplifyInstructionWithOperands().
Definition at line 2256 of file InstructionSimplify.cpp.
References A, assert(), B, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_LogicalAnd(), llvm::PatternMatch::m_c_LogicalOr(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::match(), X, and Y.
Referenced by simplifyOrInst().
|
static |
Definition at line 1842 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::IIQ, simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithCtpop(), simplifyOrOfICmpsWithAdd(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
|
static |
Definition at line 1795 of file InstructionSimplify.cpp.
References llvm::APInt::getBoolValue(), llvm::User::getOperand(), getTrue(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::APInt::isStrictlyPositive(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by simplifyOrOfICmps().
|
static |
See if we can fold the given phi. If not, returns null.
Definition at line 5297 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::DT, llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::Value::getType(), llvm::SimplifyQuery::isUndefValue(), and valueDominatesPHI().
Referenced by simplifyInstructionWithOperands().
|
static |
Definition at line 6162 of file InstructionSimplify.cpp.
References llvm::ConstantFoldLoadFromConstPtr(), DL, llvm::Type::getInt32Ty(), llvm::User::getOperand(), llvm::IsConstantOffsetFromGlobal(), llvm::Offset, Ptr, llvm::APInt::sextOrTrunc(), and llvm::APInt::srem().
Referenced by llvm::simplifyBinaryIntrinsic().
|
static |
These are simplifications common to SRem and URem.
Definition at line 1221 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CheckedInt(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyDivRem(), and llvm::InstrInfoQuery::UseInstrInfo.
Referenced by simplifySRemInst(), and simplifyURemInst().
|
static |
Given operands for an LShr or AShr, see if we can fold the result.
If not, this returns null.
Definition at line 1418 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().
|
static |
Given operands for an SDiv, see if we can fold the result.
If not, this returns null.
Definition at line 1258 of file InstructionSimplify.cpp.
References llvm::Constant::getAllOnesValue(), llvm::Value::getType(), llvm::isKnownNegation(), and simplifyDiv().
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
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 4509 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().
|
static |
Given operands for a SelectInst, see if we can fold the result.
If not, this returns null.
Definition at line 4812 of file InstructionSimplify.cpp.
References assert(), llvm::CallingConv::C, Cond, llvm::ConstantFoldSelectInstruction(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, foldSelectWithBinaryOp(), llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::impliesPoison(), llvm::isGuaranteedNotToBePoison(), llvm::isImpliedByDomCondition(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_c_LogicalAnd(), llvm::PatternMatch::m_c_LogicalOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), simplifySelectWithFCmp(), simplifySelectWithICmpCond(), llvm::SmallVectorBase< Size_T >::size(), X, and Y.
Referenced by simplifyInstructionWithOperands().
|
static |
An alternative way to test if a bit is set or not uses sgt/slt instead of eq/ne.
Definition at line 4624 of file InstructionSimplify.cpp.
References llvm::decomposeBitTestICmp(), simplifySelectBitTest(), and X.
Referenced by simplifySelectWithICmpCond().
|
static |
Try to simplify a select instruction when its condition operand is a floating-point comparison.
Definition at line 4781 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, Cond, llvm::SimplifyQuery::CxtI, F, llvm::Instruction::hasNoSignedZeros(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_FCmp(), llvm::PatternMatch::m_Specific(), and llvm::PatternMatch::match().
Referenced by simplifySelectInst().
|
static |
Try to simplify a select instruction when its condition operand is an integer comparison.
Definition at line 4656 of file InstructionSimplify.cpp.
References llvm::SelectPatternResult::Flavor, llvm::getInverseMinMaxFlavor(), llvm::getMinMaxLimit(), llvm::getMinMaxPred(), llvm::SelectPatternResult::isMinOrMax(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FShl(), llvm::PatternMatch::m_FShr(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::matchDecomposedSelectPattern(), simplifyCmpSelOfMaxMin(), simplifySelectBitTest(), simplifySelectWithFakeICmpEq(), simplifySelectWithICmpEq(), std::swap(), X, and Y.
Referenced by simplifySelectInst().
|
static |
Try to simplify a select instruction when its condition operand is an integer equality comparison.
Definition at line 4638 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::getWithoutUndef(), and simplifyWithOpReplaced().
Referenced by simplifySelectWithICmpCond().
|
static |
Given operands for an Shl, LShr or AShr, see if we can fold the result.
If not, this returns null.
Definition at line 1348 of file InstructionSimplify.cpp.
References assert(), llvm::CallingConv::C, llvm::computeKnownBits(), llvm::KnownBits::countMinTrailingZeros(), foldOrCommuteConstant(), llvm::PoisonValue::get(), llvm::KnownBits::getBitWidth(), llvm::KnownBits::getMinValue(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::KnownBits::hasConflict(), isPoisonShift(), llvm::APInt::isSignBitSet(), llvm::Log2_32_Ceil(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::KnownBits::One, llvm::APInt::setSignBit(), llvm::KnownBits::shl(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::APInt::uge(), X, and llvm::KnownBits::Zero.
Referenced by simplifyRightShift(), and simplifyShlInst().
|
static |
Given operands for an Shl, see if we can fold the result.
If not, this returns null.
Definition at line 1447 of file InstructionSimplify.cpp.
References llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_Negative(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyShift(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Definition at line 5437 of file InstructionSimplify.cpp.
References llvm::all_equal(), llvm::all_of(), assert(), llvm::SmallVectorImpl< T >::assign(), llvm::CallingConv::C, llvm::ShuffleVectorInst::commuteShuffleMask(), foldIdentityShuffles(), llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getKnownMinValue(), llvm::ConstantExpr::getShuffleVector(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), llvm::is_contained(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, RetTy, and std::swap().
Referenced by simplifyInstructionWithOperands().
|
static |
Given operands for an SRem, see if we can fold the result.
If not, this returns null.
Definition at line 1286 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().
|
static |
Given operands for a Sub, see if we can fold the result.
If not, this returns null.
Definition at line 788 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::computeKnownBits(), computePointerDifference(), llvm::ConstantFoldIntegerCast(), llvm::SimplifyQuery::DL, foldOrCommuteConstant(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::APInt::isMaxSignedValue(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifyBinOp(), simplifyByDomEq(), simplifyCastInst(), simplifyXorInst(), X, Y, and llvm::KnownBits::Zero.
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Given operands for a UDiv, see if we can fold the result.
If not, this returns null.
Definition at line 1274 of file InstructionSimplify.cpp.
References simplifyDiv().
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Definition at line 6264 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::BitWidth, llvm::computeKnownFPSignBit(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, F, llvm::APInt::getHighBitsSet(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), II, isIdempotent(), llvm::isKnownToBeAPowerOfTwo(), llvm::isSplatValue(), llvm::PatternMatch::m_BitReverse(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_SIToFP(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_UIToFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VecReverse(), llvm::MaskedValueIsZero(), llvm::PatternMatch::match(), removesFPFraction(), and X.
Referenced by simplifyIntrinsic().
|
static |
Given the operand for a UnaryOperator, see if we can fold the result.
If not, this returns null.
Definition at line 5998 of file InstructionSimplify.cpp.
References llvm_unreachable, and simplifyFNegInst().
Referenced by simplifyFPUnOp().
|
static |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
Definition at line 1558 of file InstructionSimplify.cpp.
References A, B, llvm::ConstantInt::getFalse(), getFalse(), llvm::ConstantInt::getTrue(), getTrue(), llvm::Value::getType(), llvm::ICmpInst::isEquality(), llvm::isKnownNonZero(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), X, and Y.
Referenced by simplifyAndOfICmps(), and simplifyOrOfICmps().
|
static |
Given operands for a URem, see if we can fold the result.
If not, this returns null.
Definition at line 1307 of file InstructionSimplify.cpp.
References simplifyRem().
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Definition at line 4318 of file InstructionSimplify.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::canCreatePoison(), llvm::SimplifyQuery::CanUseUndef, llvm::ConstantFoldInstOperands(), llvm::SimplifyQuery::DL, llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), llvm::Constant::getNullValue(), I, II, llvm::impliesPoison(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), simplifyInstructionWithOperands(), simplifyWithOpReplaced(), llvm::SmallVectorBase< Size_T >::size(), and llvm::SimplifyQuery::TLI.
Referenced by simplifyAndOrWithICmpEq(), simplifySelectWithICmpEq(), and simplifyWithOpReplaced().
|
static |
Given operands for a Xor, see if we can fold the result.
If not, this returns null.
Definition at line 2531 of file InstructionSimplify.cpp.
References A, B, llvm::CallingConv::C, foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifyAssociativeBinOp(), simplifyByDomEq(), simplifyLogicOfAddSub(), X, and Y.
Referenced by handleOtherCmpSelSimplifications(), simplifyAddInst(), simplifyBinOp(), simplifyInstructionWithOperands(), and simplifySubInst().
STATISTIC | ( | NumExpand | , |
"Number of expansions" | |||
) |
STATISTIC | ( | NumReassoc | , |
"Number of reassociations" | |||
) |
|
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 717 of file InstructionSimplify.cpp.
References assert(), DL, llvm::APInt::getZero(), and llvm::Offset.
Referenced by computePointerDifference().
|
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 520 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().
|
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 395 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::isUndefValue(), LHS, RHS, and simplifyBinOp().
Referenced by simplifyAndInst(), simplifyDivRem(), simplifyMulInst(), simplifyOrInst(), and simplifyShift().
|
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 567 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().
|
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 474 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().
|
static |
Definition at line 6968 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::canConstantFoldCallTo(), llvm::ConstantFoldCall(), F, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), and llvm::SimplifyQuery::TLI.
Referenced by llvm::simplifyCall(), and llvm::simplifyConstrainedFPCall().
|
static |
Definition at line 3239 of file InstructionSimplify.cpp.
References llvm::CmpInst::ICMP_SLT, llvm::APInt::isNonNegative(), llvm::APInt::isNonPositive(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_NSWAdd(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), RHS, llvm::APInt::slt(), std::swap(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyICmpWithBinOp().
|
static |
Does the given value dominate the specified phi node?
Definition at line 217 of file InstructionSimplify.cpp.
References llvm::DominatorTree::dominates(), I, and P.
Referenced by simplifyPHINode(), threadBinOpOverPHI(), and threadCmpOverPHI().