LLVM 17.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 <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, bool InBounds, 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 * | 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. | |
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 * | 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 * | 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) |
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 * | 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 * | 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. | |
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 * | 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). | |
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 * | simplifyBinaryIntrinsic (Function *F, Value *Op0, Value *Op1, const SimplifyQuery &Q) |
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 48 of file InstructionSimplify.cpp.
#define HANDLE_CAST_INST | ( | num, | |
opc, | |||
clas | |||
) | case Instruction::opc: |
anonymous enum |
Enumerator | |
---|---|
RecursionLimit |
Definition at line 50 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 727 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 2718 of file InstructionSimplify.cpp.
References A, llvm::all_of(), llvm::CaptureTracker::captured(), llvm::ICmpInst::compare(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, 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::NullIsUnknownSize, llvm::NullPointerIsDefined(), llvm::PointerMayBeCaptured(), RHS, stripAndComputeConstantOffsets(), llvm::Value::stripPointerCasts(), llvm::SimplifyQuery::TLI, llvm::CaptureTracker::tooManyUses(), 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 237 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 271 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 2609 of file InstructionSimplify.cpp.
References llvm::CmpInst::getSwappedPredicate(), LHS, RHS, and SI.
Referenced by simplifyICmpWithMinMax().
|
static |
Definition at line 5380 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldUnaryOpOperand(), and llvm::SimplifyQuery::DL.
Referenced by 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 5210 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 6150 of file InstructionSimplify.cpp.
References assert(), llvm::getInverseMinMaxIntrinsic(), llvm::M0(), and llvm::M1().
Referenced by 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 6125 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 605 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 82 of file InstructionSimplify.cpp.
References Cond, 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(), X, and Y.
Referenced by simplifySelectInst().
Definition at line 2602 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 126 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getFalse().
Referenced by simplifyAndOfICmpsWithAdd(), 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 130 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 187 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 2648 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 2628 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 1009 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::CallingConv::C, 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, 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 1000 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, LHS, RHS, and simplifyICmpInst().
Referenced by isDivZero(), and simplifyBinaryIntrinsic().
|
static |
Definition at line 5931 of file InstructionSimplify.cpp.
Referenced by simplifyUnaryIntrinsic().
|
static |
Returns true if a shift by Amount
always yields poison.
Definition at line 1286 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, E, 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 133 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 5409 of file InstructionSimplify.cpp.
References llvm::ConstantVector::get(), llvm::ConstantFP::get(), llvm::ConstantFP::getNaN(), llvm::Value::getType(), and llvm::Constant::isNaN().
Referenced by 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 5953 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 6901 of file InstructionSimplify.cpp.
References DL, I, Idx, llvm::SetVector< T, Vector, Set >::insert(), llvm::simplifyInstruction(), and llvm::SetVector< T, Vector, Set >::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 633 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 |
Given operands for an And, see if we can fold the result.
If not, this returns null.
Definition at line 2053 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::CallingConv::C, llvm::computeKnownBits(), llvm::KnownBits::countMaxActiveBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, expandCommutativeBinOp(), foldOrCommuteConstant(), llvm::ConstantInt::getFalse(), 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(), 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::PatternMatch::match(), llvm::Or, simplifyAndOrOfCmps(), simplifyAssociativeBinOp(), simplifyByDomEq(), simplifyLogicOfAddSub(), threadBinOpOverPHI(), threadBinOpOverSelect(), X, and Y.
Referenced by handleOtherCmpSelSimplifications(), simplifyBinOp(), simplifyInstructionWithOperands(), and simplifyMulInst().
|
static |
Definition at line 1841 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::IIQ, simplifyAndOfICmpsWithAdd(), simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithCtpop(), simplifyAndOrOfICmpsWithLimitConst(), simplifyAndOrOfICmpsWithZero(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
|
static |
Definition at line 1713 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 1991 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantExpr::getCast(), simplifyAndOfICmps(), simplifyAndOrOfFCmps(), and simplifyOrOfICmps().
Referenced by simplifyAndInst(), and simplifyOrInst().
|
static |
Definition at line 1946 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, DL, llvm::SimplifyQuery::DT, llvm::Value::getType(), llvm::isKnownNeverNaN(), LHS, RHS, and llvm::SimplifyQuery::TLI.
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 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 1821 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 |
Try to eliminate compares with signed or unsigned min/max constants.
Definition at line 1761 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::APInt::getBitWidth(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::APInt::getSignedMinValue(), llvm::ICmpInst::getUnsignedPredicate(), llvm::APInt::getZero(), llvm::ICmpInst::isEquality(), llvm::APInt::isMaxValue(), llvm::APInt::isMinValue(), 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::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 1495 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 289 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 |
Definition at line 6192 of file InstructionSimplify.cpp.
References llvm::BitWidth, llvm::CallingConv::C, llvm::ICmpInst::compare(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, F, llvm::fcAllFlags, foldMinimumMaximumSharedOp(), foldMinMaxSharedOp(), llvm::ConstantStruct::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantFP::get(), llvm::ConstantInt::get(), llvm::Constant::getAllOnesValue(), llvm::getInverseMinMaxIntrinsic(), llvm::Constant::getNullValue(), llvm::MinMaxIntrinsic::getPredicate(), llvm::MinMaxIntrinsic::getSaturationPoint(), llvm::Value::getType(), llvm::SimplifyQuery::getWithoutUndef(), llvm::Instruction::hasNoInfs(), llvm::Instruction::hasNoNaNs(), isICmpTrue(), llvm::SimplifyQuery::isUndefValue(), 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_ImmConstant(), 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(), propagateNaN(), RecursionLimit, simplifyRelativeLoad(), std::swap(), 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 5891 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 5840 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 751 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::ConstantInt::get(), 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 5168 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldCastOperand(), llvm::SimplifyQuery::DL, llvm::DataLayout::getIntPtrType(), llvm::CastInst::isEliminableCastPair(), and llvm::Type::isPtrOrPtrVectorTy().
Referenced by simplifyInstructionWithOperands(), and simplifySubInst().
|
static |
Given operands for a CmpInst, see if we can fold the result.
Definition at line 5919 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 151 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 177 of file InstructionSimplify.cpp.
References Cond, getFalse(), LHS, RHS, and simplifyCmpSelCase().
Referenced by threadCmpOverSelect().
|
static |
Definition at line 4376 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 168 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 1183 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::CallingConv::C, llvm::computeKnownBits(), llvm::KnownBits::countMaxTrailingZeros(), llvm::APInt::countr_zero(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, foldOrCommuteConstant(), llvm::PoisonValue::get(), llvm::Value::getType(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), and simplifyDivRem().
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 1075 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::PoisonValue::get(), llvm::ConstantInt::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 5078 of file InstructionSimplify.cpp.
References llvm::findScalarElement(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantExpr::getExtractElement(), llvm::getSplatValue(), llvm::Value::getType(), Idx, and llvm::SimplifyQuery::isUndefValue().
Referenced by simplifyInstructionWithOperands().
|
static |
Given operands for an ExtractValueInst, see if we can fold the result.
If not, this returns null.
Definition at line 5048 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 5484 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(), llvm::SimplifyQuery::TLI, 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 3993 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), llvm::CallingConv::C, llvm::CannotBeOrderedLessThanZero(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::PoisonValue::get(), llvm::ConstantInt::get(), getCompareTy(), getFalse(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::CmpInst::isFalseWhenEqual(), llvm::CmpInst::isFPPredicate(), llvm::isKnownNeverInfinity(), llvm::isKnownNeverInfOrNaN(), llvm::isKnownNeverNaN(), 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::FastMathFlags::noNaNs(), RetTy, RHS, std::swap(), threadCmpOverPHI(), threadCmpOverSelect(), and llvm::SimplifyQuery::TLI.
Referenced by simplifyCmpInst(), and simplifyInstructionWithOperands().
|
static |
Definition at line 5705 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::CallingConv::C, foldOrCommuteConstant(), llvm::PoisonValue::get(), llvm::ConstantFP::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 5616 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::FastMathFlags::allowReassoc(), llvm::CallingConv::C, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::Value::getType(), llvm::ConstantFP::getZero(), llvm::isDefaultFPEnvironment(), llvm::isKnownNeverInfOrNaN(), 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::SignBitMustBeZero(), simplifyFPOp(), std::swap(), llvm::SimplifyQuery::TLI, and X.
Referenced by simplifyFMulInst().
|
static |
Given the operands for an FMul, see if we can fold the result.
Definition at line 5660 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 5389 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 5442 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 5818 of file InstructionSimplify.cpp.
References simplifyFNegInst(), and simplifyUnOp().
|
static |
Given operands for a Freeze, see if we can fold the result.
Definition at line 6689 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DT, and llvm::isGuaranteedNotToBeUndefOrPoison().
|
static |
Definition at line 5764 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 5550 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(), llvm::SimplifyQuery::TLI, 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 4824 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::ConstantInt::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::isSized(), llvm::ConstantExpr::isSupportedGetElementPtr(), 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, 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 3687 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), llvm::CallingConv::C, computePointerICmp(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantInt::get(), llvm::Constant::getAllOnesValue(), llvm::ConstantInt::getBool(), llvm::ConstantExpr::getCast(), getCompareTy(), llvm::getConstantRangeFromMetadata(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), getFalse(), llvm::ConstantExpr::getICmp(), 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::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(), 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 2879 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 3275 of file InstructionSimplify.cpp.
References A, assert(), B, llvm::CallingConv::C, D, llvm::SimplifyQuery::DL, 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::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, simplifyICmpInst(), simplifyICmpWithBinOpOnLHS(), trySimplifyICmpWithAdds(), and Y.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3093 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::CallingConv::C, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, 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_APIntAllowUndef(), 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 3044 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::computeConstantRange(), llvm::ConstantRange::contains(), llvm::ConstantInt::get(), getCompareTy(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), 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::InstrInfoQuery::UseInstrInfo, and X.
Referenced by simplifyICmpInst().
|
static |
Definition at line 3662 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::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 3477 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 2982 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, getCompareTy(), getFalse(), getTrue(), 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 4973 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 6739 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::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 6458 of file InstructionSimplify.cpp.
References assert(), llvm::BitWidth, Callee, llvm::fp::ebIgnore, F, llvm::UndefValue::get(), llvm::ConstantInt::get(), llvm::APInt::getBitWidth(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), 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(), simplifyBinaryIntrinsic(), simplifyFAddInst(), simplifyFDivInst(), simplifyFMulInst(), simplifyFPOp(), simplifyFRemInst(), simplifyFSubInst(), simplifyUnaryIntrinsic(), std::swap(), llvm::APInt::urem(), and X.
Referenced by llvm::simplifyCall(), and llvm::simplifyConstrainedFPCall().
|
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 2029 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 1458 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 simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Given operands for a Mul, see if we can fold the result.
If not, this returns null.
Definition at line 927 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 2354 of file InstructionSimplify.cpp.
References A, llvm::SimplifyQuery::AC, B, llvm::CallingConv::C, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, 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_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::MaskedValueIsZero(), llvm::PatternMatch::match(), N, simplifyAndOrOfCmps(), simplifyAssociativeBinOp(), simplifyByDomEq(), simplifyLogicOfAddSub(), simplifyOrLogic(), threadBinOpOverPHI(), threadBinOpOverSelect(), X, and Y.
Referenced by handleOtherCmpSelSimplifications(), simplifyBinOp(), and simplifyInstructionWithOperands().
Definition at line 2261 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_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 1917 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::IIQ, simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithCtpop(), simplifyAndOrOfICmpsWithLimitConst(), simplifyAndOrOfICmpsWithZero(), simplifyOrOfICmpsWithAdd(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
|
static |
Definition at line 1870 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 5129 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 5969 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldLoadFromConstPtr(), DL, llvm::ConstantInt::get(), llvm::ConstantExpr::getBitCast(), llvm::ConstantExpr::getGetElementPtr(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::Type::getInt8PtrTy(), llvm::User::getOperand(), llvm::Type::getPointerTo(), Int32Ty, llvm::IsConstantOffsetFromGlobal(), llvm::Offset, and Ptr.
Referenced by simplifyBinaryIntrinsic().
|
static |
These are simplifications common to SRem and URem.
Definition at line 1206 of file InstructionSimplify.cpp.
References llvm::CallingConv::C, foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::IIQ, llvm::PatternMatch::m_NSWShl(), 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 1387 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 1227 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 4343 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 4638 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), llvm::CallingConv::C, Cond, llvm::ConstantFoldSelectInstruction(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, foldSelectWithBinaryOp(), llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), 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 4450 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 4607 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 4482 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 4464 of file InstructionSimplify.cpp.
References 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 1317 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), llvm::CallingConv::C, 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 1417 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 5258 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 1255 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 785 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::CallingConv::C, 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(), 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 1243 of file InstructionSimplify.cpp.
References simplifyDiv().
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Definition at line 6025 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::BitWidth, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, F, llvm::ConstantInt::get(), llvm::APInt::getHighBitsSet(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Instruction::hasAllowReassoc(), 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(), llvm::SignBitMustBeZero(), llvm::SimplifyQuery::TLI, 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 5805 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 1528 of file InstructionSimplify.cpp.
References A, llvm::SimplifyQuery::AC, B, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, 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 1276 of file InstructionSimplify.cpp.
References simplifyRem().
Referenced by simplifyBinOp(), and simplifyInstructionWithOperands().
|
static |
Definition at line 4211 of file InstructionSimplify.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::canCreatePoison(), llvm::ConstantFoldInstOperands(), llvm::SimplifyQuery::DL, GEP, llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), llvm::Constant::getNullValue(), I, llvm::impliesPoison(), llvm::is_contained(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), simplifyInstructionWithOperands(), llvm::SmallVectorBase< Size_T >::size(), llvm::SimplifyQuery::TLI, and llvm::transform().
Referenced by simplifySelectWithICmpEq().
|
static |
Given operands for a Xor, see if we can fold the result.
If not, this returns null.
Definition at line 2526 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_NotForbidUndef(), 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 714 of file InstructionSimplify.cpp.
References assert(), DL, llvm::APInt::getZero(), and llvm::Offset.
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 517 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 393 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::isUndefValue(), LHS, RHS, SI, 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 564 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 471 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 6630 of file InstructionSimplify.cpp.
References Arg, llvm::CallingConv::C, Callee, 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 3250 of file InstructionSimplify.cpp.
References llvm::CmpInst::ICMP_SLT, llvm::APInt::isNonNegative(), llvm::APInt::isNonPositive(), 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 215 of file InstructionSimplify.cpp.
References llvm::DominatorTree::dominates(), I, and P.
Referenced by simplifyPHINode(), threadBinOpOverPHI(), and threadCmpOverPHI().