|
LLVM
7.0.0
|
#include "llvm/Analysis/InstructionSimplify.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/LoopAnalysisManager.h"#include "llvm/Analysis/MemoryBuiltins.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/GetElementPtrTypeIterator.h"#include "llvm/IR/GlobalAlias.h"#include "llvm/IR/Operator.h"#include "llvm/IR/PatternMatch.h"#include "llvm/IR/ValueHandle.h"#include "llvm/Support/KnownBits.h"#include <algorithm>#include "llvm/IR/Instruction.def"Go to the source code of this file.
Namespaces | |
| llvm | |
| Compute iterated dominance frontiers using a linear time algorithm. | |
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 * | 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 * | SimplifyFPBinOp (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, ArrayRef< Value * > Ops, const SimplifyQuery &Q, unsigned) |
| Given operands for an GetElementPtrInst, 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 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 *LHS, Value *RHS, Instruction::BinaryOps OpcodeToExpand, const SimplifyQuery &Q, unsigned MaxRecurse) |
| Simplify "A op (B op' C)" by distributing op over op', turning it into "(A op B) op' (A op C)". 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 Constant * | 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 (Value *Op0, Value *Op1, bool IsDiv) |
| 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 | isUndefShift (Value *Amount) |
Returns true if a shift by Amount always yields undef. More... | |
| static Value * | SimplifyShift (Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, 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) |
| 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) |
| static Value * | simplifyAndOfICmps (ICmpInst *Op0, ICmpInst *Op1) |
| static Value * | simplifyOrOfICmpsWithAdd (ICmpInst *Op0, ICmpInst *Op1) |
| static Value * | simplifyOrOfICmps (ICmpInst *Op0, ICmpInst *Op1) |
| static Value * | simplifyAndOrOfFCmps (FCmpInst *LHS, FCmpInst *RHS, bool IsAnd) |
| static Value * | simplifyAndOrOfCmps (Value *Op0, Value *Op1, bool IsAnd) |
| 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 Constant * | computePointerICmp (const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, CmpInst::Predicate Pred, AssumptionCache *AC, const Instruction *CxtI, Value *LHS, Value *RHS) |
| 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 void | setLimitsForBinOp (BinaryOperator &BO, APInt &Lower, APInt &Upper) |
| Many binary operators with a constant operand have an easy-to-compute range of outputs. More... | |
| static Value * | simplifyICmpWithConstant (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 * | 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 const Value * | SimplifyWithOpReplaced (Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, unsigned MaxRecurse) |
| See if V simplifies when its operand Op is replaced with RepOp. More... | |
| 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 * | 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 * | 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 &, unsigned) |
| Given operands for an ExtractElementInst, see if we can fold the result. More... | |
| static Value * | SimplifyPHINode (PHINode *PN, 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, Constant *Mask, Type *RetTy, const SimplifyQuery &Q, unsigned MaxRecurse) |
| static Constant * | propagateNaN (Constant *In) |
| static Constant * | simplifyFPBinop (Value *Op0, Value *Op1) |
| static Value * | SimplifyFAddInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse) |
| 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) |
| Given operands for an FSub, see if we can fold the result. More... | |
| static Value * | SimplifyFMulInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse) |
| 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) |
| static Value * | SimplifyFRemInst (Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned) |
| static bool | IsIdempotent (Intrinsic::ID ID) |
| static Value * | SimplifyRelativeLoad (Constant *Ptr, Constant *Offset, const DataLayout &DL) |
| static bool | maskIsAllZeroOrUndef (Value *Mask) |
| static Value * | simplifyUnaryIntrinsic (Function *F, Value *Op0, const SimplifyQuery &Q) |
| static Value * | simplifyBinaryIntrinsic (Function *F, Value *Op0, Value *Op1, const SimplifyQuery &Q) |
| template<typename IterTy > | |
| static Value * | simplifyIntrinsic (Function *F, IterTy ArgBegin, IterTy ArgEnd, const SimplifyQuery &Q) |
| template<typename IterTy > | |
| static Value * | SimplifyCall (ImmutableCallSite CS, Value *V, IterTy ArgBegin, IterTy ArgEnd, const SimplifyQuery &Q, unsigned MaxRecurse) |
| static bool | replaceAndRecursivelySimplifyImpl (Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC) |
| 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 &) |
| template const SimplifyQuery | llvm::getBestSimplifyQuery (AnalysisManager< Function > &, Function &) |
| #define DEBUG_TYPE "instsimplify" |
Definition at line 45 of file InstructionSimplify.cpp.
| #define HANDLE_CAST_INST | ( | num, | |
| opc, | |||
| clas | |||
| ) | case Instruction::opc: |
| anonymous enum |
| Enumerator | |
|---|---|
| RecursionLimit | |
Definition at line 47 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 694 of file InstructionSimplify.cpp.
References llvm::ConstantExpr::getSub(), and stripAndComputeConstantOffsets().
Referenced by SimplifySubInst().
|
static |
Definition at line 2142 of file InstructionSimplify.cpp.
References A, llvm::all_of(), llvm::dyn_cast(), llvm::ConstantInt::get(), llvm::ConstantExpr::getAdd(), GetCompareTy(), getFunction(), llvm::ConstantExpr::getICmp(), llvm::getObjectSize(), llvm::ICmpInst::getSignedPredicate(), llvm::Value::getType(), llvm::GetUnderlyingObjects(), llvm::ConstantInt::getValue(), 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::isAllocLikeFn(), llvm::CmpInst::isFalseWhenEqual(), llvm::isKnownNonZero(), llvm::APInt::isNegative(), llvm::isNoAliasCall(), llvm::Constant::isNullValue(), llvm::CmpInst::isTrueWhenEqual(), MI, llvm::ObjectSizeOpts::NullIsUnknownSize, llvm::NullPointerIsDefined(), llvm::PointerMayBeCaptured(), stripAndComputeConstantOffsets(), llvm::Value::stripPointerCasts(), and llvm::APInt::ult().
Referenced by SimplifyICmpInst().
|
static |
Simplify "A op (B op' C)" by distributing op over op', turning it into "(A op B) op' (A op C)".
Here "op" is given by Opcode and "op'" is given by OpcodeToExpand, while "A" corresponds to LHS and "B op' C" to RHS. Also performs the transform "(A op' B) op C" -> "(A op C) op' (B op C)". Returns the simplified value, or null if no simplification was performed.
Definition at line 167 of file InstructionSimplify.cpp.
References A, B, C, llvm::CallBase< InstTy >::getOperand(), llvm::Instruction::isCommutative(), llvm::RISCVFenceField::R, and llvm::SimplifyBinOp().
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 2096 of file InstructionSimplify.cpp.
References llvm::dyn_cast(), llvm::SelectInst::getCondition(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), and SI.
Referenced by simplifyICmpWithMinMax().
|
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 4180 of file InstructionSimplify.cpp.
References llvm::Value::getType(), and llvm::Type::getVectorNumElements().
Referenced by SimplifyShuffleVectorInst().
|
static |
Definition at line 556 of file InstructionSimplify.cpp.
References llvm::ConstantFoldBinaryOpOperands(), 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 68 of file InstructionSimplify.cpp.
References 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(), X, and Y.
Referenced by SimplifySelectInst().
Definition at line 2089 of file InstructionSimplify.cpp.
References llvm::Value::getType(), and llvm::CmpInst::makeCmpResultType().
Referenced by computePointerICmp(), SimplifyFCmpInst(), SimplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithConstant(), 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 112 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getFalse().
Referenced by simplifyAndOfICmpsWithAdd(), simplifyAndOfICmpsWithSameOperands(), simplifyAndOrOfICmpsWithConstants(), SimplifyFCmpInst(), SimplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), simplifyUnsignedRangeCheck(), and ThreadCmpOverSelect().
For a boolean type or a vector of boolean type, return true or a vector with every element true.
Definition at line 118 of file InstructionSimplify.cpp.
References llvm::ConstantInt::getTrue().
Referenced by simplifyAndOrOfICmpsWithConstants(), SimplifyFCmpInst(), SimplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), simplifyOrOfICmpsWithAdd(), simplifyOrOfICmpsWithSameOperands(), simplifyUnsignedRangeCheck(), and ThreadCmpOverSelect().
|
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 972 of file InstructionSimplify.cpp.
References llvm::APInt::abs(), C, llvm::ConstantInt::get(), llvm::Value::getType(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULT, isICmpTrue(), llvm::APInt::isMinSignedValue(), llvm::PatternMatch::m_APInt(), and llvm::PatternMatch::match().
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 963 of file InstructionSimplify.cpp.
References C, llvm::Constant::isAllOnesValue(), and llvm::SimplifyICmpInst().
Referenced by isDivZero().
|
static |
Definition at line 4614 of file InstructionSimplify.cpp.
References round().
Referenced by simplifyUnaryIntrinsic().
|
static |
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
Definition at line 123 of file InstructionSimplify.cpp.
References llvm::dyn_cast(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), and llvm::CmpInst::getSwappedPredicate().
Referenced by ThreadCmpOverSelect().
Returns true if a shift by Amount always yields undef.
Definition at line 1181 of file InstructionSimplify.cpp.
References C, llvm::dyn_cast(), E, llvm::Constant::getAggregateElement(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), and I.
Referenced by SimplifyShift().
Definition at line 4687 of file InstructionSimplify.cpp.
References llvm::dyn_cast(), E, I, and llvm::BitmaskEnumDetail::Mask().
Referenced by simplifyIntrinsic().
Definition at line 4310 of file InstructionSimplify.cpp.
References llvm::ConstantFP::getNaN(), llvm::Value::getType(), llvm::tgtok::In, and llvm::Constant::isNaN().
Referenced by simplifyFPBinop().
|
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.
This routine returns 'true' only when it simplifies something. The passed in simplified value does not count toward this.
Definition at line 5083 of file InstructionSimplify.cpp.
References llvm::Instruction::eraseFromParent(), llvm::Module::getDataLayout(), llvm::Instruction::getModule(), llvm::Instruction::getParent(), I, llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert(), llvm::Instruction::isEHPad(), llvm::Instruction::mayHaveSideEffects(), llvm::Value::replaceAllUsesWith(), llvm::JumpTable::Simplified, llvm::SimplifyInstruction(), llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size(), and llvm::Value::users().
Referenced by llvm::recursivelySimplifyInstruction(), and llvm::replaceAndRecursivelySimplify().
|
static |
Many binary operators with a constant operand have an easy-to-compute range of outputs.
This can be used to fold a comparison to always true or always false.
Definition at line 2466 of file InstructionSimplify.cpp.
References llvm::APInt::abs(), llvm::MCID::Add, llvm::APInt::ashr(), assert(), C, llvm::APInt::countLeadingOnes(), llvm::APInt::countLeadingZeros(), llvm::APInt::countTrailingZeros(), llvm::APInt::getAllOnesValue(), llvm::APInt::getBitWidth(), llvm::APInt::getMaxValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::APInt::isAllOnesValue(), llvm::Instruction::isExact(), llvm::APInt::isMinSignedValue(), llvm::APInt::isNegative(), llvm::APInt::isNullValue(), llvm::APInt::lshr(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::APInt::sdiv(), llvm::APInt::sgt(), llvm::APInt::shl(), std::swap(), llvm::APInt::udiv(), and llvm::APInt::ult().
Referenced by simplifyICmpWithConstant().
|
static |
Given operands for an Add, see if we can fold the result.
If not, this returns null.
i1 add -> xor.
Definition at line 572 of file InstructionSimplify.cpp.
References llvm::MCID::Add, C, foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownNegation(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Undef(), 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 1771 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, C, llvm::computeKnownBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, ExpandBinOp(), foldOrCommuteConstant(), llvm::APInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::APInt::intersects(), llvm::isKnownToBeAPowerOfTwo(), llvm::APInt::isSubsetOf(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::BitmaskEnumDetail::Mask(), llvm::PatternMatch::match(), simplifyAndOrOfCmps(), SimplifyAssociativeBinOp(), ThreadBinOpOverPHI(), ThreadBinOpOverSelect(), X, and Y.
Referenced by llvm::SimplifyAndInst().
Definition at line 1601 of file InstructionSimplify.cpp.
References simplifyAndOfICmpsWithAdd(), simplifyAndOfICmpsWithSameOperands(), simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithZero(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
Definition at line 1555 of file InstructionSimplify.cpp.
References getFalse(), llvm::User::getOperand(), llvm::Value::getType(), 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 1429 of file InstructionSimplify.cpp.
References A, 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().
Definition at line 1734 of file InstructionSimplify.cpp.
References C, llvm::dyn_cast(), llvm::ConstantExpr::getCast(), llvm::Value::getType(), simplifyAndOfICmps(), simplifyAndOrOfFCmps(), and simplifyOrOfICmps().
Referenced by SimplifyAndInst(), and SimplifyOrInst().
Definition at line 1697 of file InstructionSimplify.cpp.
References llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_UNO, llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), and llvm::isKnownNeverNaN().
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 1481 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().
Definition at line 1518 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 1355 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::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), SimplifyRightShift(), 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 225 of file InstructionSimplify.cpp.
References A, assert(), B, C, llvm::dyn_cast(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::CallBase< InstTy >::getOperand(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), llvm::SimplifyBinOp(), and llvm::RISCVFenceField::W.
Referenced by SimplifyAddInst(), SimplifyAndInst(), SimplifyMulInst(), SimplifyOrInst(), and SimplifyXorInst().
|
static |
Definition at line 4752 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::DL, llvm::ConstantFP::get(), llvm::UndefValue::get(), llvm::Function::getIntrinsicID(), llvm::Constant::getNullValue(), llvm::Function::getReturnType(), llvm::Value::getType(), llvm::PatternMatch::m_NaN(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::maxnum(), llvm::minnum(), and SimplifyRelativeLoad().
Referenced by simplifyIntrinsic().
|
static |
Given operands for a BinaryOperator, see if we can fold the result.
If not, this returns null.
Definition at line 4526 of file InstructionSimplify.cpp.
References llvm::MCID::Add, llvm_unreachable, 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 4856 of file InstructionSimplify.cpp.
References C, llvm::canConstantFoldCallTo(), llvm::ConstantFoldCall(), llvm::dyn_cast(), E, F(), llvm::UndefValue::get(), llvm::FunctionType::getReturnType(), llvm::Value::getType(), I, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::MipsISD::Ret, simplifyIntrinsic(), and llvm::SimplifyQuery::TLI.
Referenced by llvm::SimplifyCall().
|
static |
Definition at line 4138 of file InstructionSimplify.cpp.
References C, llvm::ConstantFoldCastOperand(), llvm::SimplifyQuery::DL, llvm::DataLayout::getIntPtrType(), llvm::Value::getType(), 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 4602 of file InstructionSimplify.cpp.
References llvm::CmpInst::isIntPredicate(), llvm::SimplifyFCmpInst(), and llvm::SimplifyICmpInst().
Referenced by llvm::SimplifyCmpInst().
|
static |
These are simplifications common to SDiv and UDiv.
Definition at line 1023 of file InstructionSimplify.cpp.
References C, foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::ConstantInt::getValue(), isDivZero(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_SDiv(), 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(), ThreadBinOpOverSelect(), llvm::APInt::umul_ov(), and X.
Referenced by SimplifySDivInst(), and SimplifyUDivInst().
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 906 of file InstructionSimplify.cpp.
References llvm::dyn_cast(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::Constant::getAggregateElement(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), llvm::Type::isIntOrIntVectorTy(), llvm::Constant::isNullValue(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), 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 4068 of file InstructionSimplify.cpp.
References llvm::ConstantFoldExtractElementInstruction(), llvm::findScalarElement(), llvm::UndefValue::get(), llvm::Value::getType(), llvm::Type::getVectorElementType(), and llvm::Type::getVectorNumElements().
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 4038 of file InstructionSimplify.cpp.
References llvm::ConstantFoldExtractValueInstruction(), llvm::dyn_cast(), 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 4334 of file InstructionSimplify.cpp.
References C, llvm::CannotBeNegativeZero(), foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPBinop(), and llvm::SimplifyQuery::TLI.
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 3472 of file InstructionSimplify.cpp.
References assert(), C, llvm::CannotBeOrderedLessThanZero(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::DL, llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::ConstantInt::get(), GetCompareTy(), getFalse(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::CmpInst::isFalseWhenEqual(), llvm::CmpInst::isFPPredicate(), llvm::APFloat::isInfinity(), llvm::APFloat::isNaN(), llvm::APFloat::isNegative(), llvm::CmpInst::isOrdered(), llvm::CmpInst::isTrueWhenEqual(), llvm::CmpInst::isUnordered(), llvm::APFloat::isZero(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_NaN(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), std::swap(), ThreadCmpOverPHI(), ThreadCmpOverSelect(), and llvm::SimplifyQuery::TLI.
Referenced by llvm::SimplifyFCmpInst().
|
static |
Definition at line 4447 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), C, foldOrCommuteConstant(), llvm::ConstantFP::get(), llvm::BinaryOperator::getFNegArgument(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::BinaryOperator::isFNeg(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_FPOne(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPBinop(), and X.
Referenced by llvm::SimplifyFDivInst().
|
static |
Given the operands for an FMul, see if we can fold the result.
Definition at line 4403 of file InstructionSimplify.cpp.
References llvm::FastMathFlags::allowReassoc(), C, foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_FPOne(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPBinop(), and X.
Referenced by llvm::SimplifyFMulInst().
|
static |
Given operands for a BinaryOperator, see if we can fold the result.
If not, this returns null. In contrast to SimplifyBinOp, try to use FastMathFlag when folding the result. In case we don't need FastMathFlags, simply fall to SimplifyBinOp.
Definition at line 4574 of file InstructionSimplify.cpp.
References llvm::SimplifyBinOp(), llvm::SimplifyFAddInst(), llvm::SimplifyFDivInst(), llvm::SimplifyFMulInst(), and llvm::SimplifyFSubInst().
Referenced by llvm::SimplifyFPBinOp().
Definition at line 4320 of file InstructionSimplify.cpp.
References llvm::ConstantFP::getNaN(), llvm::Value::getType(), llvm::PatternMatch::m_NaN(), llvm::PatternMatch::match(), and propagateNaN().
Referenced by SimplifyFAddInst(), SimplifyFDivInst(), SimplifyFMulInst(), SimplifyFRemInst(), and SimplifyFSubInst().
|
static |
Definition at line 4494 of file InstructionSimplify.cpp.
References C, foldOrCommuteConstant(), llvm::ConstantFP::getNegativeZero(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), and simplifyFPBinop().
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 4367 of file InstructionSimplify.cpp.
References C, llvm::CannotBeNegativeZero(), foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::FastMathFlags::noNaNs(), llvm::FastMathFlags::noSignedZeros(), simplifyFPBinop(), llvm::SimplifyQuery::TLI, 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 3861 of file InstructionSimplify.cpp.
References llvm::all_of(), AS, llvm::ArrayRef< T >::back(), C, llvm::ConstantFoldConstant(), llvm::SimplifyQuery::DL, llvm::ConstantInt::get(), llvm::VectorType::get(), llvm::PointerType::get(), llvm::UndefValue::get(), llvm::ConstantExpr::getGetElementPtr(), llvm::GetElementPtrInst::getIndexedType(), llvm::DataLayout::getIndexSizeInBits(), llvm::ConstantExpr::getIntToPtr(), llvm::Constant::getNullValue(), getType(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeSizeInBits(), llvm::Type::isSized(), 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::RISCVFenceField::R, llvm::ArrayRef< T >::size(), and llvm::ArrayRef< T >::slice().
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 3185 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, assert(), C, computePointerICmp(), llvm::ConstantFoldCompareInstOperands(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::ConstantInt::get(), llvm::ConstantExpr::getCast(), GetCompareTy(), llvm::getConstantRangeFromMetadata(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), getFalse(), llvm::ConstantExpr::getGetElementPtr(), llvm::ConstantExpr::getICmp(), llvm::ConstantExpr::getIntToPtr(), llvm::CmpInst::getInversePredicate(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::ICmpInst::getSignedPredicate(), 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::ICmpInst::isEquality(), llvm::CmpInst::isIntPredicate(), llvm::isKnownNonEqual(), llvm::Type::isPointerTy(), llvm::CmpInst::isTrueWhenEqual(), llvm_unreachable, llvm::ConstantRange::makeSatisfyingICmpRegion(), llvm::LLVMContext::MD_range, llvm::SimplifyICmpInst(), simplifyICmpOfBools(), simplifyICmpWithBinOp(), simplifyICmpWithConstant(), simplifyICmpWithMinMax(), simplifyICmpWithZero(), std::swap(), ThreadCmpOverPHI(), ThreadCmpOverSelect(), and llvm::SimplifyQuery::TLI.
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 2327 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::DL, GetCompareTy(), getFalse(), getTrue(), llvm::Value::getType(), llvm::Optional< T >::getValueOr(), 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(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Zero(), and llvm::PatternMatch::match().
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 2674 of file InstructionSimplify.cpp.
References A, llvm::SimplifyQuery::AC, llvm::MCID::Add, assert(), B, C, llvm::computeKnownBits(), llvm::SimplifyQuery::CxtI, D, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::dyn_cast(), GetCompareTy(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), getFalse(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::CallBase< InstTy >::getOperand(), llvm::ConstantInt::getTrue(), getTrue(), llvm::Value::getType(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::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_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::Instruction::isExact(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm::APInt::isOneValue(), llvm::APInt::isPowerOf2(), llvm::CmpInst::isSigned(), llvm::APInt::isSignMask(), llvm::CmpInst::isUnsigned(), LLVM_FALLTHROUGH, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::SimplifyICmpInst(), Y, and llvm::ARCCC::Z.
Referenced by SimplifyICmpInst().
|
static |
Definition at line 2620 of file InstructionSimplify.cpp.
References C, llvm::ConstantRange::contains(), llvm::APInt::getBitWidth(), GetCompareTy(), llvm::getConstantRangeFromMetadata(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), I, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::ConstantRange::intersectWith(), llvm::ConstantRange::inverse(), llvm::ConstantRange::isEmptySet(), llvm::ConstantRange::isFullSet(), llvm::LegalizeActions::Lower, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_UIToFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), llvm::LLVMContext::MD_range, setLimitsForBinOp(), llvm::Upper, and X.
Referenced by SimplifyICmpInst().
|
static |
Simplify integer comparisons where at least one operand of the compare matches an integer min/max idiom.
Definition at line 2981 of file InstructionSimplify.cpp.
References A, B, llvm::CmpInst::BAD_ICMP_PREDICATE, 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, llvm::PatternMatch::m_SMax(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_UMax(), llvm::PatternMatch::m_UMin(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), P, 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 2401 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::isKnownNonZero(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm_unreachable, llvm::PatternMatch::m_Zero(), and llvm::PatternMatch::match().
Referenced by SimplifyICmpInst().
|
static |
Given operands for an InsertValueInst, see if we can fold the result.
If not, this returns null.
Definition at line 3980 of file InstructionSimplify.cpp.
References llvm::ConstantFoldInsertValueInstruction(), llvm::Value::getType(), llvm::PatternMatch::m_Undef(), and llvm::PatternMatch::match().
Referenced by llvm::SimplifyInsertValueInst().
|
static |
Definition at line 4813 of file InstructionSimplify.cpp.
References llvm::APInt::getBitWidth(), llvm::Function::getIntrinsicID(), llvm::APInt::isNullValue(), llvm::PatternMatch::m_APInt(), maskIsAllZeroOrUndef(), llvm::PatternMatch::match(), simplifyBinaryIntrinsic(), simplifyUnaryIntrinsic(), and llvm::APInt::urem().
Referenced by SimplifyCall().
|
static |
Given operands for an LShr, see if we can fold the result.
If not, this returns null.
Definition at line 1317 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::computeKnownBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), 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 848 of file InstructionSimplify.cpp.
References llvm::MCID::Add, C, ExpandBinOp(), foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_IDiv(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::SimplifyAndInst(), SimplifyAssociativeBinOp(), ThreadBinOpOverPHI(), ThreadBinOpOverSelect(), 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 1909 of file InstructionSimplify.cpp.
References A, llvm::SimplifyQuery::AC, B, C, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, ExpandBinOp(), foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), llvm::Value::getType(), llvm::APInt::isMask(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::MaskedValueIsZero(), llvm::PatternMatch::match(), N, simplifyAndOrOfCmps(), SimplifyAssociativeBinOp(), ThreadBinOpOverPHI(), and ThreadBinOpOverSelect().
Referenced by llvm::SimplifyOrInst().
Definition at line 1672 of file InstructionSimplify.cpp.
References simplifyAndOrOfICmpsWithConstants(), simplifyAndOrOfICmpsWithZero(), simplifyOrOfICmpsWithAdd(), simplifyOrOfICmpsWithSameOperands(), simplifyUnsignedRangeCheck(), and X.
Referenced by simplifyAndOrOfCmps().
Definition at line 1626 of file InstructionSimplify.cpp.
References llvm::User::getOperand(), getTrue(), llvm::Value::getType(), 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 1454 of file InstructionSimplify.cpp.
References A, 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 4106 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::DT, llvm::UndefValue::get(), llvm::Value::getType(), llvm::PHINode::incoming_values(), and valueDominatesPHI().
Referenced by llvm::SCEVExpander::replaceCongruentIVs(), and llvm::SimplifyInstruction().
|
static |
Definition at line 4631 of file InstructionSimplify.cpp.
References C, llvm::ConstantFoldLoadFromConstPtr(), llvm::dyn_cast(), 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(), llvm::ConstantInt::getSExtValue(), Int32Ty, and llvm::IsConstantOffsetFromGlobal().
Referenced by simplifyBinaryIntrinsic().
|
static |
These are simplifications common to SRem and URem.
Definition at line 1081 of file InstructionSimplify.cpp.
References C, foldOrCommuteConstant(), llvm::Constant::getNullValue(), llvm::Value::getType(), 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(), and ThreadBinOpOverSelect().
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 1259 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::PatternMatch::m_Undef(), llvm::PatternMatch::match(), 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 1124 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 3711 of file InstructionSimplify.cpp.
References C, llvm::APInt::isPowerOf2(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), and llvm::PatternMatch::match().
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 3814 of file InstructionSimplify.cpp.
References llvm::ConstantFoldSelectInstruction(), foldSelectWithBinaryOp(), and simplifySelectWithICmpCond().
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 3746 of file InstructionSimplify.cpp.
References llvm::decomposeBitTestICmp(), llvm::CmpInst::ICMP_EQ, llvm::BitmaskEnumDetail::Mask(), simplifySelectBitTest(), and X.
Referenced by simplifySelectWithICmpCond().
|
static |
Try to simplify a select instruction when its condition operand is an integer comparison.
Definition at line 3760 of file InstructionSimplify.cpp.
References llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::ICmpInst::isEquality(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), simplifySelectBitTest(), simplifySelectWithFakeICmpEq(), SimplifyWithOpReplaced(), 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 1209 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, C, llvm::computeKnownBits(), llvm::KnownBits::countMinTrailingZeros(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, foldOrCommuteConstant(), llvm::UndefValue::get(), llvm::KnownBits::getBitWidth(), llvm::APInt::getLimitedValue(), llvm::Constant::getNullValue(), llvm::Value::getType(), isUndefShift(), llvm::Log2_32_Ceil(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::KnownBits::One, ThreadBinOpOverPHI(), ThreadBinOpOverSelect(), and X.
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 1286 of file InstructionSimplify.cpp.
References llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_Negative(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), SimplifyShift(), and X.
Referenced by llvm::SimplifyShlInst().
|
static |
Definition at line 4228 of file InstructionSimplify.cpp.
References assert(), llvm::ShuffleVectorInst::commuteShuffleMask(), llvm::ConstantFoldShuffleVectorInstruction(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::find(), foldIdentityShuffles(), llvm::UndefValue::get(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), llvm::SmallVectorBase::size(), and std::swap().
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 1150 of file InstructionSimplify.cpp.
References llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), 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 713 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::AC, llvm::MCID::Add, C, llvm::computeKnownBits(), computePointerDifference(), llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, foldOrCommuteConstant(), llvm::UndefValue::get(), llvm::ConstantExpr::getIntegerCast(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), Result, llvm::SimplifyBinOp(), llvm::SimplifyCastInst(), llvm::SimplifyXorInst(), llvm::RISCVFenceField::W, X, Y, and llvm::ARCCC::Z.
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 1139 of file InstructionSimplify.cpp.
References simplifyDiv().
Referenced by llvm::SimplifyUDivInst().
|
static |
Definition at line 4703 of file InstructionSimplify.cpp.
References llvm::SimplifyQuery::CxtI, llvm::Function::getIntrinsicID(), llvm::Instruction::hasAllowReassoc(), IsIdempotent(), llvm::log2(), llvm::PatternMatch::m_BitReverse(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::SignBitMustBeZero(), llvm::SimplifyQuery::TLI, and X.
Referenced by simplifyIntrinsic().
|
static |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
Definition at line 1386 of file InstructionSimplify.cpp.
References getFalse(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::CmpInst::isUnsigned(), llvm::PatternMatch::m_ICmp(), 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 a URem, see if we can fold the result.
If not, this returns null.
Definition at line 1171 of file InstructionSimplify.cpp.
References simplifyRem().
Referenced by llvm::SimplifyURemInst().
|
static |
See if V simplifies when its operand Op is replaced with RepOp.
Definition at line 3613 of file InstructionSimplify.cpp.
References B, C, llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldInstOperands(), llvm::ConstantFoldLoadFromConstPtr(), llvm::SimplifyQuery::DL, llvm::dyn_cast(), GEP, llvm::CallBase< InstTy >::getOperand(), I, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SimplifyBinOp(), llvm::SimplifyCmpInst(), llvm::SimplifyGEPInst(), llvm::SmallVectorBase::size(), llvm::SimplifyQuery::TLI, and llvm::transform().
Referenced by simplifySelectWithICmpCond().
|
static |
Given operands for a Xor, see if we can fold the result.
If not, this returns null.
Definition at line 2045 of file InstructionSimplify.cpp.
References C, foldOrCommuteConstant(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), and SimplifyAssociativeBinOp().
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 0 if V is not a pointer, and returns the constant '0' if there are no constant offsets applied.
This is very similar to GetPointerBaseWithConstantOffset except it doesn't follow non-inbounds geps. This allows it to remain usable for icmp ult/etc. folding.
Definition at line 651 of file InstructionSimplify.cpp.
References assert(), GEP, llvm::ConstantInt::get(), llvm::DataLayout::getIntPtrType(), llvm::APInt::getNullValue(), llvm::Operator::getOpcode(), llvm::ConstantVector::getSplat(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Type::isPtrOrPtrVectorTy(), and llvm::Type::isVectorTy().
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 479 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::DT, llvm::PHINode::incoming_values(), 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 325 of file InstructionSimplify.cpp.
References assert(), llvm::dyn_cast(), llvm::SelectInst::getFalseValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::SelectInst::getTrueValue(), llvm::Instruction::isCommutative(), 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 522 of file InstructionSimplify.cpp.
References assert(), llvm::SimplifyQuery::DT, llvm::CmpInst::getSwappedPredicate(), llvm::PHINode::incoming_values(), 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.
Definition at line 397 of file InstructionSimplify.cpp.
References assert(), llvm::Constant::getAllOnesValue(), llvm::SelectInst::getCondition(), getFalse(), llvm::SelectInst::getFalseValue(), llvm::CmpInst::getSwappedPredicate(), getTrue(), llvm::SelectInst::getTrueValue(), llvm::Value::getType(), isSameCompare(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), SI, llvm::SimplifyAndInst(), llvm::SimplifyCmpInst(), llvm::SimplifyOrInst(), llvm::SimplifyXorInst(), and std::swap().
Referenced by SimplifyFCmpInst(), and SimplifyICmpInst().
|
static |
Does the given value dominate the specified phi node?
Definition at line 137 of file InstructionSimplify.cpp.
References llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::Function::getEntryBlock(), llvm::Instruction::getFunction(), llvm::Instruction::getParent(), and I.
Referenced by SimplifyPHINode(), ThreadBinOpOverPHI(), and ThreadCmpOverPHI().
1.8.13