LLVM
15.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/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/Support/KnownBits.h"
#include <algorithm>
#include "llvm/IR/Instruction.def"
Go to the source code of this file.
Namespaces | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static Value * | simplifyOrInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an Or, see if we can fold the result. More... | |
static Value * | simplifyXorInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a Xor, see if we can fold the result. More... | |
static Value * | simplifyCastInst (unsigned, Value *, Type *, const SimplifyQuery &, unsigned) |
static Value * | simplifyGEPInst (Type *SrcTy, Value *Ptr, ArrayRef< Value * > Indices, bool InBounds, const SimplifyQuery &Q, unsigned) |
Given operands for an GetElementPtrInst, see if we can fold the result. More... | |
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. More... | |
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. More... | |
static Constant * | getTrue (Type *Ty) |
For a boolean type or a vector of boolean type, return true or a vector with every element true. More... | |
static bool | isSameCompare (Value *V, CmpInst::Predicate Pred, Value *LHS, Value *RHS) |
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"? More... | |
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. More... | |
static Value * | simplifyCmpSelTrueCase (CmpInst::Predicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse) |
Simplify comparison with true branch of select. More... | |
static Value * | simplifyCmpSelFalseCase (CmpInst::Predicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse) |
Simplify comparison with false branch of select. More... | |
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. More... | |
static bool | valueDominatesPHI (Value *V, PHINode *P, const DominatorTree *DT) |
Does the given value dominate the specified phi node? More... | |
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)". More... | |
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'. More... | |
static Value * | simplifyAssociativeBinOp (Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) |
Generic simplifications for associative binary operations. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static APInt | stripAndComputeConstantOffsets (const DataLayout &DL, Value *&V, bool AllowNonInbounds=false) |
Compute the base pointer and cumulative constant offsets for V. More... | |
static Constant * | computePointerDifference (const DataLayout &DL, Value *LHS, Value *RHS) |
Compute the constant difference between two pointer values. More... | |
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. More... | |
static Value * | simplifyMulInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a Mul, see if we can fold the result. More... | |
static Value * | simplifyDivRem (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q) |
Check for common or similar folds of integer division or integer remainder. More... | |
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. More... | |
static bool | isDivZero (Value *X, Value *Y, const SimplifyQuery &Q, unsigned MaxRecurse, bool IsSigned) |
Return true if we can simplify X / Y to 0. More... | |
static Value * | simplifyDiv (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
These are simplifications common to SDiv and UDiv. More... | |
static Value * | simplifyRem (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
These are simplifications common to SRem and URem. More... | |
static Value * | simplifySDivInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an SDiv, see if we can fold the result. More... | |
static Value * | simplifyUDivInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a UDiv, see if we can fold the result. More... | |
static Value * | simplifySRemInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an SRem, see if we can fold the result. More... | |
static Value * | simplifyURemInst (Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for a URem, see if we can fold the result. More... | |
static bool | isPoisonShift (Value *Amount, const SimplifyQuery &Q) |
Returns true if a shift by Amount always yields poison. More... | |
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. More... | |
static Value * | simplifyRightShift (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q, unsigned MaxRecurse) |
Given operands for an Shl, LShr or AShr, see if we can fold the result. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static Value * | simplifyAndOfICmpsWithSameOperands (ICmpInst *Op0, ICmpInst *Op1) |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped. More... | |
static Value * | simplifyOrOfICmpsWithSameOperands (ICmpInst *Op0, ICmpInst *Op1) |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped. More... | |
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. More... | |
static Value * | simplifyAndOrOfICmpsWithZero (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd) |
static Value * | simplifyAndOfICmpsWithAdd (ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ) |
static Value * | simplifyAndOrOfICmpsWithLimitConst (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd) |
Try to eliminate compares with signed or unsigned min/max constants. More... | |
static Value * | simplifyAndOrOfICmpsWithCtpop (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd) |
Try to simplify and/or of icmp with ctpop intrinsic. More... | |
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 TargetLibraryInfo *TLI, FCmpInst *LHS, FCmpInst *RHS, bool IsAnd) |
static Value * | simplifyAndOrOfCmps (const SimplifyQuery &Q, Value *Op0, Value *Op1, bool IsAnd) |
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)). More... | |
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". More... | |
static bool | isAllocDisjoint (const Value *V) |
Return true if the underlying object (storage) must be disjoint from storage returned by any noalias return call. More... | |
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. More... | |
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. More... | |
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. More... | |
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) |
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(). More... | |
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. More... | |
static Value * | simplifyICmpWithDominatingAssume (CmpInst::Predicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q) |
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. More... | |
static Value * | simplifyWithOpReplaced (Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, unsigned MaxRecurse) |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static Value * | simplifyExtractValueInst (Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &, unsigned) |
Given operands for an ExtractValueInst, see if we can fold the result. More... | |
static Value * | simplifyExtractElementInst (Value *Vec, Value *Idx, const SimplifyQuery &Q, unsigned) |
Given operands for an ExtractElementInst, see if we can fold the result. More... | |
static Value * | simplifyPHINode (PHINode *PN, ArrayRef< Value * > IncomingValues, const SimplifyQuery &Q) |
See if we can fold the given phi. If not, returns null. More... | |
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). More... | |
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. More... | |
static Constant * | propagateNaN (Constant *In) |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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 Value * | simplifyRelativeLoad (Constant *Ptr, Constant *Offset, const DataLayout &DL) |
static Value * | simplifyUnaryIntrinsic (Function *F, Value *Op0, const SimplifyQuery &Q) |
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). More... | |
static Value * | simplifyBinaryIntrinsic (Function *F, Value *Op0, Value *Op1, const SimplifyQuery &Q) |
static Value * | simplifyIntrinsic (CallBase *Call, const SimplifyQuery &Q) |
static Value * | tryConstantFoldCall (CallBase *Call, const SimplifyQuery &Q) |
static Value * | simplifyFreezeInst (Value *Op0, const SimplifyQuery &Q) |
Given operands for a Freeze, see if we can fold the result. More... | |
static Value * | simplifyLoadInst (LoadInst *LI, Value *PtrOp, const SimplifyQuery &Q) |
static Value * | simplifyInstructionWithOperands (Instruction *I, ArrayRef< Value * > NewOps, const SimplifyQuery &SQ, OptimizationRemarkEmitter *ORE) |
See if we can compute a simplified version of this instruction. More... | |
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. More... | |
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 &) |
const template SimplifyQuery | llvm::getBestSimplifyQuery (AnalysisManager< Function > &, Function &) |
#define DEBUG_TYPE "instsimplify" |
Definition at line 47 of file InstructionSimplify.cpp.
#define HANDLE_CAST_INST | ( | num, | |
opc, | |||
clas | |||
) | case Instruction::opc: |
anonymous enum |
Enumerator | |
---|---|
RecursionLimit |
Definition at line 49 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 724 of file InstructionSimplify.cpp.
References DL, llvm::ConstantInt::get(), llvm::Value::getContext(), llvm::ConstantVector::getSplat(), llvm::Value::getType(), LHS, RHS, and stripAndComputeConstantOffsets().
Referenced by simplifySubInst().
|
static |
Definition at line 2681 of file InstructionSimplify.cpp.
References llvm::all_of(), llvm::ICmpInst::compare(), llvm::SimplifyQuery::CxtI, DL, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::ObjectSizeOpts::EvalMode, F, llvm::ConstantInt::get(), getCompareTy(), llvm::getObjectSize(), llvm::ICmpInst::getSignedPredicate(), 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, llvm::SimplifyQuery::IIQ, isAllocDisjoint(), llvm::isAllocLikeFn(), llvm::ICmpInst::isEquality(), llvm::CmpInst::isFalseWhenEqual(), llvm::isKnownNonZero(), llvm::APInt::isNegative(), llvm::isNoAliasCall(), llvm::CmpInst::isTrueWhenEqual(), LHS, MI, llvm::ObjectSizeOpts::Min, llvm::ObjectSizeOpts::NullIsUnknownSize, llvm::NullPointerIsDefined(), llvm::PointerMayBeCaptured(), RHS, stripAndComputeConstantOffsets(), llvm::Value::stripPointerCasts(), llvm::SimplifyQuery::TLI, llvm::APInt::ult(), and llvm::InstrInfoQuery::UseInstrInfo.
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 238 of file InstructionSimplify.cpp.
References B, llvm::SimplifyQuery::getWithoutUndef(), llvm::Instruction::isCommutative(), S, and llvm::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 272 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 2572 of file InstructionSimplify.cpp.
References llvm::CmpInst::getSwappedPredicate(), LHS, RHS, and SI.
Referenced by simplifyICmpWithMinMax().
|
static |
Definition at line 5086 of file InstructionSimplify.cpp.
References llvm::ConstantFoldUnaryOpOperand(), and llvm::SimplifyQuery::DL.
Referenced by simplifyFNegInst().
|
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 4916 of file InstructionSimplify.cpp.
References llvm::Value::getType().
Referenced by 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 5759 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 simplifyBinaryIntrinsic().
|
static |
Definition at line 602 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 77 of file InstructionSimplify.cpp.
References Cond, llvm::tgtok::FalseVal, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::tgtok::TrueVal, X, and Y.
Referenced by simplifySelectInst().
Definition at line 2565 of file InstructionSimplify.cpp.
References llvm::CmpInst::makeCmpResultType().
Referenced by computePointerICmp(), simplifyFCmpInst(), simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithBinOpOnLHS(), simplifyICmpWithConstant(), simplifyICmpWithDominatingAssume(), 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 121 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getFalse().
Referenced by getKnownValueOnEdge(), reuseTableCompare(), simplifyAndOfICmpsWithAdd(), simplifyAndOfICmpsWithSameOperands(), simplifyAndOrOfICmpsWithConstants(), simplifyCmpSelFalseCase(), simplifyFCmpInst(), simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOpOnLHS(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), and simplifyUnsignedRangeCheck().
For a boolean type or a vector of boolean type, return true or a vector with every element true.
Definition at line 125 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getTrue().
Referenced by getKnownValueOnEdge(), reuseTableCompare(), simplifyAndOrOfICmpsWithConstants(), simplifyCmpSelTrueCase(), simplifyFCmpInst(), simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOpOnLHS(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), simplifyOrOfICmpsWithAdd(), simplifyOrOfICmpsWithSameOperands(), 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 182 of file InstructionSimplify.cpp.
References Cond, llvm::Constant::getAllOnesValue(), llvm::impliesPoison(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::simplifyAndInst(), llvm::simplifyOrInst(), and llvm::simplifyXorInst().
Referenced by threadCmpOverSelect().
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 2611 of file InstructionSimplify.cpp.
References llvm::NVPTX::PTXLdStInstCode::V2.
Referenced by computePointerICmp().
Return true if the underlying object (storage) must be disjoint from storage returned by any noalias return call.
Definition at line 2591 of file InstructionSimplify.cpp.
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 1040 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::ConstantInt::get(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULT, isICmpTrue(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), X, and Y.
Referenced by simplifyDiv(), and simplifyRem().
|
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 1031 of file InstructionSimplify.cpp.
References LHS, RHS, and llvm::simplifyICmpInst().
Referenced by isDivZero(), and simplifyBinaryIntrinsic().
|
static |
Definition at line 5582 of file InstructionSimplify.cpp.
References ceil, floor, round(), and trunc.
Referenced by simplifyUnaryIntrinsic().
|
static |
Returns true if a shift by Amount
always yields poison.
Definition at line 1246 of file InstructionSimplify.cpp.
References E, I, and llvm::SimplifyQuery::isUndefValue().
Referenced by simplifyShift().
|
static |
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
Definition at line 128 of file InstructionSimplify.cpp.
References llvm::CmpInst::getSwappedPredicate(), LHS, and RHS.
Referenced by simplifyCmpSelCase().
Definition at line 5113 of file InstructionSimplify.cpp.
References llvm::ConstantFP::getNaN(), and llvm::tgtok::In.
Referenced by simplifyBinaryIntrinsic(), and simplifyFPOp().
|
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 6505 of file InstructionSimplify.cpp.
References DL, I, llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert(), llvm::JumpTable::Simplified, llvm::simplifyInstruction(), and llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, 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 630 of file InstructionSimplify.cpp.
References llvm::MCID::Add, 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(), llvm::simplifyXorInst(), and Y.
Referenced by llvm::simplifyAddInst().
|
static |
Given operands for an And, see if we can fold the result.
If not, this returns null.
Definition at line 2056 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::KnownBits::countMaxActiveBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, expandCommutativeBinOp(), foldOrCommuteConstant(), llvm::APInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::APInt::intersects(), llvm::isCheckForZeroAndMulWithOverflow(), llvm::isImpliedCondition(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownToBeAPowerOfTwo(), llvm::APInt::isSubsetOf(), llvm::SimplifyQuery::isUndefValue(), lshr, 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_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::BitmaskEnumDetail::Mask(), llvm::PatternMatch::match(), llvm::Or, shl, simplifyAndOrOfCmps(), simplifyAssociativeBinOp(), simplifyLogicOfAddSub(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::Optional< T >::value_or(), X, and Y.
Referenced by llvm::simplifyAndInst().
|
static |
Definition at line 1841 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::IIQ, simplifyAndOfICmpsWithAdd(), simplifyAndOfICmpsWithSameOperands(), simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithCtpop(), simplifyAndOrOfICmpsWithLimitConst(), simplifyAndOrOfICmpsWithZero(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
|
static |
Definition at line 1713 of file InstructionSimplify.cpp.
References C1, getFalse(), llvm::User::getOperand(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, 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().
Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
Definition at line 1587 of file InstructionSimplify.cpp.
References B, getFalse(), llvm::CmpInst::getInversePredicate(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::CmpInst::isFalseWhenEqual(), llvm::CmpInst::isImpliedTrueByMatchingCmp(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by simplifyAndOfICmps().
|
static |
Definition at line 1994 of file InstructionSimplify.cpp.
References llvm::ConstantExpr::getCast(), simplifyAndOfICmps(), simplifyAndOrOfFCmps(), simplifyOrOfICmps(), and llvm::SimplifyQuery::TLI.
Referenced by simplifyAndInst(), and simplifyOrInst().
|
static |
Definition at line 1956 of file InstructionSimplify.cpp.
References llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_UNO, llvm::Value::getType(), llvm::isKnownNeverNaN(), LHS, 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 1639 of file InstructionSimplify.cpp.
References C1, 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().
Try to simplify and/or of icmp with ctpop intrinsic.
Definition at line 1821 of file InstructionSimplify.cpp.
References llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, 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 |
Try to eliminate compares with signed or unsigned min/max constants.
Definition at line 1761 of file InstructionSimplify.cpp.
References llvm::APInt::getBitWidth(), llvm::CmpInst::getInversePredicate(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::APInt::getSignedMinValue(), llvm::ICmpInst::getUnsignedPredicate(), llvm::APInt::getZero(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::APInt::isMaxValue(), llvm::APInt::isMinValue(), llvm::CmpInst::isSigned(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), std::swap(), and X.
Referenced by simplifyAndOfICmps(), and simplifyOrOfICmps().
Definition at line 1676 of file InstructionSimplify.cpp.
References llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), X, and Y.
Referenced by simplifyAndOfICmps(), and simplifyOrOfICmps().
|
static |
Given operands for an AShr, see if we can fold the result.
If not, this returns null.
Definition at line 1444 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 llvm::simplifyAShrInst().
|
static |
Generic simplifications for associative binary operations.
Returns the simpler value, or null if none was found.
Definition at line 290 of file InstructionSimplify.cpp.
References assert(), B, llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), LHS, RHS, llvm::simplifyBinOp(), and llvm::RISCVFenceField::W.
Referenced by simplifyAddInst(), simplifyAndInst(), simplifyMulInst(), simplifyOrInst(), and simplifyXorInst().
|
static |
Definition at line 5781 of file InstructionSimplify.cpp.
References llvm::abs(), llvm::BitWidth, C1, llvm::ICmpInst::compare(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, F, foldMinMaxSharedOp(), llvm::ConstantInt::get(), llvm::ConstantFP::get(), llvm::ConstantStruct::get(), llvm::Constant::getAllOnesValue(), llvm::getInverseMinMaxIntrinsic(), llvm::CmpInst::getNonStrictPredicate(), llvm::Constant::getNullValue(), llvm::MinMaxIntrinsic::getPredicate(), llvm::MinMaxIntrinsic::getSaturationPoint(), llvm::Value::getType(), llvm::SimplifyQuery::getWithoutUndef(), llvm::Instruction::hasNoInfs(), llvm::Instruction::hasNoNaNs(), isICmpTrue(), llvm::isImpliedByDomCondition(), llvm::SimplifyQuery::isUndefValue(), LLVM_FALLTHROUGH, llvm::M0(), llvm::M1(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowUndef(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_NaN(), llvm::PatternMatch::m_Negative(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), maximum, llvm::maxnum(), minimum, llvm::minnum(), powi(), propagateNaN(), RecursionLimit, simplifyRelativeLoad(), llvm::APIntOps::smax(), llvm::APIntOps::smin(), std::swap(), llvm::APIntOps::umax(), llvm::APIntOps::umin(), and X.
Referenced by simplifyIntrinsic().
|
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 5542 of file InstructionSimplify.cpp.
References LHS, RHS, llvm::simplifyBinOp(), llvm::simplifyFAddInst(), llvm::simplifyFDivInst(), llvm::simplifyFMulInst(), and llvm::simplifyFSubInst().
|
static |
Given operands for a BinaryOperator, see if we can fold the result.
If not, this returns null.
Definition at line 5495 of file InstructionSimplify.cpp.
References llvm::MCID::Add, LHS, llvm_unreachable, Mul, RHS, llvm::simplifyAddInst(), llvm::simplifyAndInst(), llvm::simplifyAShrInst(), llvm::simplifyFAddInst(), llvm::simplifyFDivInst(), llvm::simplifyFMulInst(), llvm::simplifyFRemInst(), llvm::simplifyFSubInst(), llvm::simplifyLShrInst(), llvm::simplifyMulInst(), llvm::simplifyOrInst(), llvm::simplifySDivInst(), llvm::simplifyShlInst(), llvm::simplifySRemInst(), llvm::simplifySubInst(), llvm::simplifyUDivInst(), llvm::simplifyURemInst(), and llvm::simplifyXorInst().
Referenced by llvm::simplifyBinOp().
|
static |
Definition at line 4874 of file InstructionSimplify.cpp.
References llvm::ConstantFoldCastOperand(), llvm::SimplifyQuery::DL, llvm::DataLayout::getIntPtrType(), llvm::CastInst::isEliminableCastPair(), and llvm::Type::isPtrOrPtrVectorTy().
Referenced by llvm::simplifyCastInst().
|
static |
Given operands for a CmpInst, see if we can fold the result.
Definition at line 5570 of file InstructionSimplify.cpp.
References llvm::CmpInst::isIntPredicate(), LHS, RHS, llvm::simplifyFCmpInst(), and llvm::simplifyICmpInst().
Referenced by llvm::simplifyCmpInst().
|
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 146 of file InstructionSimplify.cpp.
References Cond, isSameCompare(), LHS, RHS, and llvm::simplifyCmpInst().
Referenced by simplifyCmpSelFalseCase(), and simplifyCmpSelTrueCase().
|
static |
Simplify comparison with false branch of select.
Definition at line 172 of file InstructionSimplify.cpp.
References Cond, getFalse(), LHS, RHS, and simplifyCmpSelCase().
Referenced by threadCmpOverSelect().
|
static |
Simplify comparison with true branch of select.
Definition at line 163 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 1101 of file InstructionSimplify.cpp.
References C1, foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::ConstantInt::getValue(), isDivZero(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyDivRem(), threadBinOpOverPHI(), and threadBinOpOverSelect().
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 949 of file InstructionSimplify.cpp.
References llvm::ConstantInt::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), i, llvm::SimplifyQuery::IIQ, llvm::Type::isIntOrIntVectorTy(), llvm::Constant::isNullValue(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), Mul, 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 4786 of file InstructionSimplify.cpp.
References llvm::findScalarElement(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantExpr::getExtractElement(), llvm::getSplatValue(), llvm::Value::getType(), and llvm::SimplifyQuery::isUndefValue().
Referenced by llvm::simplifyExtractElementInst().
|
static |
Given operands for an ExtractValueInst, see if we can fold the result.
If not, this returns null.
Definition at line 4756 of file InstructionSimplify.cpp.
References llvm::ConstantFoldExtractValueInstruction(), llvm::min(), llvm::ArrayRef< T >::size(), and llvm::ArrayRef< T >::slice().
Referenced by llvm::simplifyExtractValueInst().
|
static |
Given operands for an FAdd, see if we can fold the result.
If not, this returns null.
Definition at line 5162 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::canIgnoreSNaN(), llvm::CannotBeNegativeZero(), llvm::canRoundingModeBe(), foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isDefaultFPEnvironment(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FSub(), 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(), llvm::TowardNegative, and X.
Referenced by llvm::simplifyFAddInst().
|
static |
Given operands for an FCmpInst, see if we can fold the result.
If not, this returns null.
Definition at line 3895 of file InstructionSimplify.cpp.
References assert(), llvm::CannotBeOrderedLessThanZero(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::DL, llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::ConstantInt::get(), llvm::PoisonValue::get(), getCompareTy(), getFalse(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::CmpInst::isFalseWhenEqual(), llvm::CmpInst::isFPPredicate(), llvm::isKnownNeverInfinity(), llvm::isKnownNeverNaN(), llvm::CmpInst::isOrdered(), llvm::CmpInst::isTrueWhenEqual(), llvm::SimplifyQuery::isUndefValue(), llvm::CmpInst::isUnordered(), LHS, llvm_unreachable, llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_NaN(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::maxnum(), llvm::FastMathFlags::noNaNs(), RHS, std::swap(), threadCmpOverPHI(), threadCmpOverSelect(), and llvm::SimplifyQuery::TLI.
Referenced by llvm::simplifyFCmpInst().
|
static |
Definition at line 5364 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), foldOrCommuteConstant(), llvm::ConstantFP::get(), llvm::Constant::getNullValue(), llvm::Value::getType(), 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::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPOp(), and X.
Referenced by llvm::simplifyFDivInst().
|
static |
Definition at line 5279 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isDefaultFPEnvironment(), 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(), simplifyFPOp(), and X.
Referenced by llvm::simplifyFMAFMul().
|
static |
Given the operands for an FMul, see if we can fold the result.
Definition at line 5319 of file InstructionSimplify.cpp.
References foldOrCommuteConstant(), llvm::isDefaultFPEnvironment(), and llvm::simplifyFMAFMul().
Referenced by llvm::simplifyFMulInst().
|
static |
Given the operand for an FNeg, see if we can fold the result.
If not, this returns null.
Definition at line 5095 of file InstructionSimplify.cpp.
References foldConstant(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.
Referenced by llvm::simplifyFNegInst().
|
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 5126 of file InstructionSimplify.cpp.
References llvm::any_of(), llvm::fp::ebStrict, llvm::PoisonValue::get(), llvm::Intrinsic::getType(), llvm::Value::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 5473 of file InstructionSimplify.cpp.
References llvm::simplifyFNegInst(), and llvm::simplifyUnOp().
Referenced by llvm::simplifyUnOp().
|
static |
Given operands for a Freeze, see if we can fold the result.
Definition at line 6284 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DT, and llvm::isGuaranteedNotToBeUndefOrPoison().
Referenced by llvm::simplifyFreezeInst().
|
static |
Definition at line 5419 of file InstructionSimplify.cpp.
References foldOrCommuteConstant(), llvm::ConstantFP::getNegativeZero(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isDefaultFPEnvironment(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), and simplifyFPOp().
Referenced by llvm::simplifyFRemInst().
|
static |
Given operands for an FSub, see if we can fold the result.
If not, this returns null.
Definition at line 5224 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::canIgnoreSNaN(), llvm::CannotBeNegativeZero(), llvm::canRoundingModeBe(), 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_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPOp(), llvm::TowardNegative, and X.
Referenced by llvm::simplifyFSubInst().
|
static |
Given operands for an GetElementPtrInst, see if we can fold the result.
If not, this returns null.
Definition at line 4541 of file InstructionSimplify.cpp.
References llvm::all_of(), llvm::any_of(), llvm::ArrayRef< T >::back(), llvm::ConstantFoldConstant(), llvm::SimplifyQuery::DL, llvm::ArrayRef< T >::drop_back(), llvm::ArrayRef< T >::empty(), llvm::ConstantInt::get(), llvm::VectorType::get(), llvm::PointerType::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::Type::getContext(), llvm::ConstantExpr::getGetElementPtr(), llvm::GetElementPtrInst::getIndexedType(), llvm::DataLayout::getIndexSizeInBits(), llvm::ConstantExpr::getIntToPtr(), llvm::Type::getPointerAddressSpace(), llvm::DataLayout::getPointerSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::Intrinsic::getType(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeSizeInBits(), llvm::getUnderlyingObject(), llvm::APInt::isOne(), llvm::Type::isOpaquePointerTy(), llvm::Type::isSized(), llvm::SimplifyQuery::isUndefValue(), llvm::APInt::isZero(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_ConstantInt(), 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, llvm::ArrayRef< T >::size(), and llvm::Value::stripAndAccumulateInBoundsConstantOffsets().
Referenced by llvm::simplifyGEPInst().
|
static |
Given operands for an ICmpInst, see if we can fold the result.
If not, this returns null.
Definition at line 3597 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), computePointerICmp(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantExpr::getCast(), getCompareTy(), llvm::getConstantRangeFromMetadata(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), getFalse(), llvm::ConstantExpr::getIntToPtr(), llvm::CmpInst::getInversePredicate(), llvm::InstrInfoQuery::getMetadata(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), getTrue(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), llvm::ICmpInst::getUnsignedPredicate(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::SimplifyQuery::IIQ, llvm::ICmpInst::isEquality(), llvm::CmpInst::isIntPredicate(), llvm::isKnownNonEqual(), llvm::Type::isPointerTy(), llvm::CmpInst::isTrueWhenEqual(), llvm::SimplifyQuery::isUndefValue(), LHS, llvm_unreachable, llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), RHS, llvm::simplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithConstant(), simplifyICmpWithDominatingAssume(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), std::swap(), threadCmpOverPHI(), threadCmpOverSelect(), llvm::SimplifyQuery::TLI, and llvm::InstrInfoQuery::UseInstrInfo.
Referenced by llvm::simplifyICmpInst().
|
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
Definition at line 2818 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, llvm::Optional< T >::value_or(), 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 3203 of file InstructionSimplify.cpp.
References llvm::MCID::Add, assert(), B, D, getCompareTy(), llvm::ConstantInt::getFalse(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::SimplifyQuery::IIQ, llvm::ICmpInst::isEquality(), llvm::InstrInfoQuery::isExact(), llvm::CmpInst::isSigned(), llvm::CmpInst::isUnsigned(), LHS, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowUndef(), 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, llvm::simplifyICmpInst(), simplifyICmpWithBinOpOnLHS(), trySimplifyICmpWithAdds(), and Y.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3027 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, C1, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::APInt::getBitWidth(), getCompareTy(), getFalse(), getTrue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::isKnownNonZero(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), LLVM_FALLTHROUGH, llvm_unreachable, llvm::PatternMatch::m_APInt(), 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_UDiv(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), RHS, and Y.
Referenced by simplifyICmpWithBinOp().
|
static |
Definition at line 2978 of file InstructionSimplify.cpp.
References llvm::computeConstantRange(), llvm::ConstantRange::contains(), llvm::ConstantInt::get(), getCompareTy(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::ConstantRange::inverse(), llvm::ConstantRange::isEmptySet(), llvm::ICmpInst::isEquality(), llvm::ConstantRange::isFullSet(), llvm::CmpInst::isSigned(), LHS, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APIntAllowUndef(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_UIToFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), RHS, llvm::APInt::srem(), llvm::APInt::urem(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3572 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::AssumptionCache::assumptionsFor(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::ConstantInt::get(), llvm::CallBase::getArgOperand(), getCompareTy(), llvm::Instruction::getParent(), llvm::isImpliedCondition(), llvm::isValidAssumeForContext(), LHS, 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 3387 of file InstructionSimplify.cpp.
References B, llvm::CmpInst::BAD_ICMP_PREDICATE, 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, llvm::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 2916 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, getCompareTy(), getFalse(), getTrue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::SimplifyQuery::IIQ, llvm::isKnownNonZero(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), LHS, llvm_unreachable, llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), RHS, and llvm::InstrInfoQuery::UseInstrInfo.
Referenced by simplifyICmpInst().
|
static |
Given operands for an InsertValueInst, see if we can fold the result.
If not, this returns null.
Definition at line 4686 of file InstructionSimplify.cpp.
References llvm::ConstantFoldInsertValueInstruction(), llvm::Value::getType(), and llvm::SimplifyQuery::isUndefValue().
Referenced by llvm::simplifyInsertValueInst().
|
static |
See if we can compute a simplified version of this instruction.
If not, this returns null.
If called on unreachable code, the above logic may report that the instruction simplified to itself. Make life easier for users by detecting that case here, returning a safe value instead.
Definition at line 6323 of file InstructionSimplify.cpp.
References llvm::MCID::Add, llvm::all_of(), llvm::MCID::Call, llvm::ConstantFoldInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::UndefValue::get(), llvm::PPC::getPredicate(), llvm::SimplifyQuery::getWithInstruction(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), I, llvm::SimplifyQuery::IIQ, llvm::InstrInfoQuery::isExact(), IV, llvm::SPII::Load, llvm::makeArrayRef(), Mul, llvm::MCID::Select, llvm::simplifyAddInst(), llvm::simplifyAndInst(), llvm::simplifyAShrInst(), llvm::simplifyCall(), llvm::simplifyCastInst(), llvm::simplifyExtractElementInst(), llvm::simplifyExtractValueInst(), llvm::simplifyFAddInst(), llvm::simplifyFCmpInst(), llvm::simplifyFDivInst(), llvm::simplifyFMulInst(), llvm::simplifyFNegInst(), llvm::simplifyFreezeInst(), llvm::simplifyFRemInst(), llvm::simplifyFSubInst(), llvm::simplifyGEPInst(), llvm::simplifyICmpInst(), llvm::simplifyInsertElementInst(), llvm::simplifyInsertValueInst(), simplifyLoadInst(), llvm::simplifyLShrInst(), llvm::simplifyMulInst(), llvm::simplifyOrInst(), simplifyPHINode(), llvm::simplifySDivInst(), llvm::simplifySelectInst(), llvm::simplifyShlInst(), llvm::simplifyShuffleVectorInst(), llvm::simplifySRemInst(), llvm::simplifySubInst(), llvm::simplifyUDivInst(), llvm::simplifyURemInst(), llvm::simplifyXorInst(), llvm::ArrayRef< T >::size(), llvm::SimplifyQuery::TLI, and llvm::transform().
Referenced by llvm::simplifyInstruction(), and llvm::simplifyInstructionWithOperands().
|
static |
Definition at line 6044 of file InstructionSimplify.cpp.
References llvm::BitWidth, llvm::fp::ebIgnore, F, llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::Constant::getAllOnesValue(), llvm::APInt::getBitWidth(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), 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(), llvm::NearestTiesToEven, simplifyBinaryIntrinsic(), llvm::simplifyFAddInst(), llvm::simplifyFDivInst(), llvm::simplifyFMulInst(), simplifyFPOp(), llvm::simplifyFRemInst(), llvm::simplifyFSubInst(), simplifyUnaryIntrinsic(), std::swap(), llvm::APInt::urem(), and X.
Referenced by llvm::simplifyCall(), and llvm::simplifyConstrainedFPCall().
|
static |
Definition at line 6296 of file InstructionSimplify.cpp.
References llvm::ConstantFoldLoadFromConstPtr(), llvm::SimplifyQuery::DL, llvm::DataLayout::getIndexTypeSizeInBits(), llvm::Value::getType(), llvm::getUnderlyingObject(), llvm::LoadInst::isVolatile(), and llvm::Value::stripAndAccumulateConstantOffsets().
Referenced by simplifyInstructionWithOperands().
|
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 2032 of file InstructionSimplify.cpp.
References assert(), C1, llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Instruction::isBitwiseLogicOp(), 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 1407 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::KnownBits::countMaxActiveBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, 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(), X, and Y.
Referenced by llvm::simplifyLShrInst().
|
static |
Given operands for a Mul, see if we can fold the result.
If not, this returns null.
Definition at line 885 of file InstructionSimplify.cpp.
References llvm::MCID::Add, 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(), Mul, llvm::simplifyAndInst(), simplifyAssociativeBinOp(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by llvm::simplifyMulInst().
|
static |
Given operands for an Or, see if we can fold the result.
If not, this returns null.
Definition at line 2335 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, B, C1, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, expandCommutativeBinOp(), foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), 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_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::MaskedValueIsZero(), llvm::PatternMatch::match(), N, simplifyAndOrOfCmps(), simplifyAssociativeBinOp(), simplifyLogicOfAddSub(), simplifyOrLogic(), threadBinOpOverPHI(), threadBinOpOverSelect(), llvm::Optional< T >::value_or(), X, and Y.
Referenced by llvm::simplifyOrInst().
Definition at line 2250 of file InstructionSimplify.cpp.
References assert(), B, llvm::Constant::getAllOnesValue(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NotForbidUndef(), 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 1922 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::IIQ, simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithCtpop(), simplifyAndOrOfICmpsWithLimitConst(), simplifyAndOrOfICmpsWithZero(), simplifyOrOfICmpsWithAdd(), simplifyOrOfICmpsWithSameOperands(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
|
static |
Definition at line 1875 of file InstructionSimplify.cpp.
References C1, llvm::User::getOperand(), getTrue(), llvm::Value::getType(), llvm::InstrInfoQuery::hasNoSignedWrap(), llvm::InstrInfoQuery::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, 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().
Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
Definition at line 1612 of file InstructionSimplify.cpp.
References B, llvm::CmpInst::getInversePredicate(), getTrue(), llvm::Value::getType(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::isImpliedTrueByMatchingCmp(), llvm::CmpInst::isTrueWhenEqual(), 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 4829 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::DT, llvm::UndefValue::get(), llvm::Value::getType(), llvm::SimplifyQuery::isUndefValue(), and valueDominatesPHI().
Referenced by simplifyInstructionWithOperands().
|
static |
Definition at line 5601 of file InstructionSimplify.cpp.
References llvm::ConstantFoldLoadFromConstPtr(), DL, llvm::ConstantInt::get(), llvm::ConstantExpr::getBitCast(), llvm::Value::getContext(), llvm::ConstantExpr::getGetElementPtr(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::Type::getInt8PtrTy(), llvm::User::getOperand(), llvm::Type::getPointerTo(), Int32Ty, and llvm::IsConstantOffsetFromGlobal().
Referenced by simplifyBinaryIntrinsic().
|
static |
These are simplifications common to SRem and URem.
Definition at line 1145 of file InstructionSimplify.cpp.
References foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, isDivZero(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyDivRem(), threadBinOpOverPHI(), threadBinOpOverSelect(), and llvm::InstrInfoQuery::UseInstrInfo.
Referenced by simplifySRemInst(), and simplifyURemInst().
|
static |
Given operands for an Shl, LShr or AShr, see if we can fold the result.
If not, this returns null.
Definition at line 1345 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, 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 1189 of file InstructionSimplify.cpp.
References llvm::Constant::getAllOnesValue(), llvm::Value::getType(), llvm::isKnownNegation(), and simplifyDiv().
Referenced by llvm::simplifySDivInst().
|
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 4232 of file InstructionSimplify.cpp.
References llvm::tgtok::FalseVal, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), llvm::tgtok::TrueVal, 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 4418 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), Cond, llvm::ConstantFoldSelectInstruction(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::tgtok::FalseVal, foldSelectWithBinaryOp(), llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::Value::getType(), i, llvm::isGuaranteedNotToBePoison(), llvm::isImpliedByDomCondition(), llvm::SimplifyQuery::isUndefValue(), 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(), simplifySelectWithFCmp(), simplifySelectWithICmpCond(), llvm::tgtok::TrueVal, X, and Y.
Referenced by llvm::simplifySelectInst().
|
static |
An alternative way to test if a bit is set or not uses sgt/slt instead of eq/ne.
Definition at line 4267 of file InstructionSimplify.cpp.
References llvm::decomposeBitTestICmp(), llvm::tgtok::FalseVal, llvm::CmpInst::ICMP_EQ, llvm::BitmaskEnumDetail::Mask(), simplifySelectBitTest(), llvm::tgtok::TrueVal, and X.
Referenced by simplifySelectWithICmpCond().
|
static |
Try to simplify a select instruction when its condition operand is a floating-point comparison.
Definition at line 4387 of file InstructionSimplify.cpp.
References Cond, llvm::SimplifyQuery::CxtI, F, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_UNE, 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 4281 of file InstructionSimplify.cpp.
References llvm::tgtok::FalseVal, llvm::SelectPatternResult::Flavor, llvm::getInverseMinMaxFlavor(), llvm::getMinMaxLimit(), llvm::getMinMaxPred(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::SelectPatternResult::isMinOrMax(), llvm::Type::isVectorTy(), 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_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::matchDecomposedSelectPattern(), simplifySelectBitTest(), simplifySelectWithFakeICmpEq(), llvm::simplifyWithOpReplaced(), std::swap(), llvm::tgtok::TrueVal, X, and Y.
Referenced by simplifySelectInst().
|
static |
Given operands for an Shl, LShr or AShr, see if we can fold the result.
If not, this returns null.
Definition at line 1275 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), llvm::computeKnownBits(), llvm::KnownBits::countMinTrailingZeros(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, 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 1374 of file InstructionSimplify.cpp.
References llvm::Constant::getNullValue(), 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_Value(), llvm::PatternMatch::match(), simplifyShift(), llvm::InstrInfoQuery::UseInstrInfo, and X.
Referenced by llvm::simplifyShlInst().
|
static |
Definition at line 4964 of file InstructionSimplify.cpp.
References llvm::all_of(), assert(), llvm::SmallVectorImpl< T >::assign(), llvm::ShuffleVectorInst::commuteShuffleMask(), foldIdentityShuffles(), llvm::ConstantVector::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::LinearPolySize< LeafTy >::getKnownMinValue(), llvm::ConstantExpr::getShuffleVector(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), i, llvm::is_contained(), llvm::is_splat(), llvm::LinearPolySize< LeafTy >::isScalable(), llvm::SimplifyQuery::isUndefValue(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_Value(), llvm::BitmaskEnumDetail::Mask(), llvm::PatternMatch::match(), std::swap(), and llvm::UndefMaskElem.
Referenced by llvm::simplifyShuffleVectorInst().
|
static |
Given operands for an SRem, see if we can fold the result.
If not, this returns null.
Definition at line 1215 of file InstructionSimplify.cpp.
References llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isKnownNegation(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), simplifyRem(), and X.
Referenced by llvm::simplifySRemInst().
|
static |
Given operands for a Sub, see if we can fold the result.
If not, this returns null.
Definition at line 746 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::MCID::Add, llvm::computeKnownBits(), computePointerDifference(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, foldOrCommuteConstant(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantExpr::getIntegerCast(), 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(), llvm::simplifyBinOp(), llvm::simplifyCastInst(), llvm::simplifyXorInst(), llvm::RISCVFenceField::W, X, Y, and llvm::KnownBits::Zero.
Referenced by llvm::simplifySubInst().
|
static |
Given operands for a UDiv, see if we can fold the result.
If not, this returns null.
Definition at line 1204 of file InstructionSimplify.cpp.
References simplifyDiv().
Referenced by llvm::simplifyUDivInst().
|
static |
Definition at line 5657 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::BitWidth, ceil, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, F, floor, llvm::APInt::getHighBitsSet(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Instruction::hasAllowReassoc(), isIdempotent(), llvm::isSplatValue(), llvm::log2(), 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::MaskedValueIsZero(), llvm::PatternMatch::match(), round(), llvm::SignBitMustBeZero(), llvm::SimplifyQuery::TLI, trunc, 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 5460 of file InstructionSimplify.cpp.
References llvm_unreachable, and llvm::simplifyFNegInst().
Referenced by llvm::simplifyUnOp().
|
static |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
Definition at line 1477 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, B, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::ConstantInt::getFalse(), getFalse(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), getTrue(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::isKnownNonZero(), llvm::CmpInst::isUnsigned(), 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 1236 of file InstructionSimplify.cpp.
References simplifyRem().
Referenced by llvm::simplifyURemInst().
|
static |
Definition at line 4108 of file InstructionSimplify.cpp.
References assert(), B, llvm::canCreatePoison(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldInstOperands(), llvm::ConstantFoldLoadFromConstPtr(), llvm::SimplifyQuery::DL, GEP, llvm::ConstantExpr::getBinOpIdentity(), I, llvm::is_contained(), llvm::PatternMatch::m_Zero(), llvm::makeArrayRef(), llvm::PatternMatch::match(), llvm::JumpTable::Simplified, llvm::simplifyBinOp(), llvm::simplifyCmpInst(), llvm::simplifyGEPInst(), llvm::simplifySelectInst(), llvm::SimplifyQuery::TLI, and llvm::transform().
Referenced by llvm::simplifyWithOpReplaced().
|
static |
Given operands for a Xor, see if we can fold the result.
If not, this returns null.
Definition at line 2492 of file InstructionSimplify.cpp.
References B, 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_NotForbidUndef(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifyAssociativeBinOp(), simplifyLogicOfAddSub(), X, and Y.
Referenced by llvm::simplifyXorInst().
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 711 of file InstructionSimplify.cpp.
References assert(), DL, llvm::Value::getType(), llvm::APInt::getZero(), llvm::Type::isPtrOrPtrVectorTy(), and llvm::Value::stripAndAccumulateConstantOffsets().
Referenced by computePointerDifference(), and computePointerICmp().
|
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 518 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::DT, llvm::PHINode::incoming_values(), LHS, RHS, llvm::simplifyBinOp(), and valueDominatesPHI().
Referenced by simplifyAndInst(), simplifyDiv(), simplifyMulInst(), simplifyOrInst(), simplifyRem(), 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 394 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::isUndefValue(), LHS, RHS, SI, llvm::JumpTable::Simplified, and llvm::simplifyBinOp().
Referenced by simplifyAndInst(), simplifyDiv(), simplifyMulInst(), simplifyOrInst(), simplifyRem(), 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 561 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::DT, llvm::numbers::e, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), llvm::SimplifyQuery::getWithInstruction(), LHS, RHS, llvm::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 472 of file InstructionSimplify.cpp.
References assert(), Cond, llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), handleOtherCmpSelSimplifications(), llvm::Type::isVectorTy(), LHS, RHS, SI, simplifyCmpSelFalseCase(), simplifyCmpSelTrueCase(), and std::swap().
Referenced by simplifyFCmpInst(), and simplifyICmpInst().
|
static |
Definition at line 6230 of file InstructionSimplify.cpp.
References Arg, llvm::canConstantFoldCallTo(), llvm::ConstantFoldCall(), F, llvm::SmallVectorImpl< T >::reserve(), and llvm::SimplifyQuery::TLI.
Referenced by llvm::simplifyCall(), and llvm::simplifyConstrainedFPCall().
|
static |
Definition at line 3178 of file InstructionSimplify.cpp.
References C1, llvm::CmpInst::ICMP_SLT, LHS, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_NSWAdd(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), RHS, llvm::APInt::slt(), std::swap(), and X.
Referenced by simplifyICmpWithBinOp().
|
static |
Does the given value dominate the specified phi node?
Definition at line 210 of file InstructionSimplify.cpp.
References llvm::DominatorTree::dominates(), I, and P.
Referenced by simplifyPHINode(), threadBinOpOverPHI(), and threadCmpOverPHI().