LLVM 20.0.0git
|
#include "Transforms/InstCombine/InstCombineInternal.h"
Additional Inherited Members | |
Public Types inherited from llvm::InstCombiner | |
using | BuilderTy = IRBuilder< TargetFolder, IRBuilderCallbackInserter > |
An IRBuilder that automatically inserts new instructions into the worklist. | |
Static Public Member Functions inherited from llvm::InstCombiner | |
static Value * | peekThroughBitcast (Value *V, bool OneUseOnly=false) |
Return the source operand of a potentially bitcasted value while optionally checking if it has one use. | |
static unsigned | getComplexity (Value *V) |
Assign a complexity or rank value to LLVM Values. | |
static bool | isCanonicalPredicate (CmpInst::Predicate Pred) |
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms. | |
static Constant * | AddOne (Constant *C) |
Add one to a Constant. | |
static Constant * | SubOne (Constant *C) |
Subtract one from a Constant. | |
static std::optional< std::pair< CmpInst::Predicate, Constant * > > | getFlippedStrictnessPredicateAndConstant (CmpInst::Predicate Pred, Constant *C) |
static bool | shouldAvoidAbsorbingNotIntoSelect (const SelectInst &SI) |
static Constant * | getSafeVectorConstantForBinop (BinaryOperator::BinaryOps Opcode, Constant *In, bool IsRHSConstant) |
Some binary operators require special handling to avoid poison and undefined behavior. | |
Public Attributes inherited from llvm::InstCombiner | |
uint64_t | MaxArraySizeForCombine = 0 |
Maximum size of array considered when transforming. | |
BuilderTy & | Builder |
Protected Attributes inherited from llvm::InstCombiner | |
InstructionWorklist & | Worklist |
A worklist of the instructions that need to be simplified. | |
const bool | MinimizeSize |
AAResults * | AA |
AssumptionCache & | AC |
TargetLibraryInfo & | TLI |
DominatorTree & | DT |
const DataLayout & | DL |
SimplifyQuery | SQ |
OptimizationRemarkEmitter & | ORE |
BlockFrequencyInfo * | BFI |
BranchProbabilityInfo * | BPI |
ProfileSummaryInfo * | PSI |
DomConditionCache | DC |
LoopInfo * | LI |
bool | MadeIRChange = false |
SmallDenseSet< std::pair< BasicBlock *, BasicBlock * >, 8 > | DeadEdges |
Edges that are known to never be taken. | |
SmallDenseMap< BasicBlock *, SmallVector< BasicBlock * >, 8 > | PredOrder |
Order of predecessors to canonicalize phi nodes towards. | |
Definition at line 60 of file InstCombineInternal.h.
|
inline |
Definition at line 64 of file InstCombineInternal.h.
|
virtualdefault |
void InstCombinerImpl::addDeadEdge | ( | BasicBlock * | From, |
BasicBlock * | To, | ||
SmallVectorImpl< BasicBlock * > & | Worklist | ||
) |
Definition at line 3573 of file InstructionCombining.cpp.
References llvm::InstCombiner::addToWorklist(), llvm::InstCombiner::DeadEdges, From, llvm::PoisonValue::get(), llvm::InstCombiner::MadeIRChange, llvm::BasicBlock::phis(), llvm::InstCombiner::replaceUse(), and llvm::InstCombiner::Worklist.
Referenced by handlePotentiallyDeadSuccessors(), and handleUnreachableFrom().
Instruction * InstCombinerImpl::canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract | ( | BinaryOperator & | I | ) |
Definition at line 1307 of file InstCombineAddSub.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::CastInst::CreateTruncOrBitCast(), llvm::Value::getName(), I, llvm::CmpInst::ICMP_EQ, llvm::IRBuilderBase::Insert(), llvm::isSignBitCheck(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SExtOrSelf(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_TruncOrSelf(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::PatternMatch::match(), Select, std::swap(), and X.
Referenced by visitAdd(), visitOr(), and visitSub().
If we have a comparison with a non-canonical predicate, if we can update all the users, invert the predicate and adjust all the users.
Definition at line 6938 of file InstCombineCompares.cpp.
References llvm::InstCombiner::canFreelyInvertAllUsersOf(), freelyInvertAllUsersOf(), llvm::CmpInst::getInversePredicate(), I, and llvm::InstCombiner::isCanonicalPredicate().
Referenced by visitICmpInst().
LoadInst * InstCombinerImpl::combineLoadToNewType | ( | LoadInst & | LI, |
Type * | NewTy, | ||
const Twine & | Suffix = "" |
||
) |
Helper to combine a load to a new type.
This just does the work of combining a load to a new type. It handles metadata, etc., and returns the new instruction. The NewTy
should be the loaded value type. This will convert it to a pointer, cast the operand to that pointer type, load it, etc.
Note that this will create all of the instructions with whatever insert point the InstCombinerImpl
currently is using.
Definition at line 560 of file InstCombineLoadStoreAlloca.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::copyMetadataForLoad(), llvm::IRBuilderBase::CreateAlignedLoad(), isSupportedAtomicType(), llvm::InstCombiner::LI, and llvm::LoadInst::setAtomic().
Referenced by combineLoadToOperationType(), and unpackLoadToAggregate().
Instruction * InstCombinerImpl::commonCastTransforms | ( | CastInst & | CI | ) |
Implement the transforms common to all CastInst visitors.
Definition at line 154 of file InstCombineCasts.cpp.
References llvm::InstCombiner::Builder, llvm::ConstantFoldCastOperand(), llvm::CastInst::Create(), llvm::IRBuilderBase::CreateCast(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, foldOpIntoPhi(), FoldOpIntoSelect(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::CastInst::getSrcTy(), llvm::Value::getType(), llvm::Type::isIntegerTy(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::replaceAllDbgUsesWith(), llvm::InstCombiner::replaceInstUsesWith(), and X.
Referenced by visitAddrSpaceCast(), visitBitCast(), visitFPExt(), visitFPToSI(), visitFPToUI(), visitFPTrunc(), visitIntToPtr(), visitPtrToInt(), visitSExt(), visitSIToFP(), visitTrunc(), visitUIToFP(), and visitZExt().
Instruction * InstCombinerImpl::commonIDivTransforms | ( | BinaryOperator & | I | ) |
This function implements the transforms common to both integer division instructions (udiv and sdiv).
It is called by the visitors to those integer division instructions. Common integer divide transforms
Definition at line 1165 of file InstCombineMulDivRem.cpp.
References A, assert(), B, llvm::InstCombiner::Builder, llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpULT(), llvm::IRBuilderBase::CreateShl(), foldBinOpIntoSelectOrPhi(), foldBinopWithPhiOperands(), foldIDivShl(), FoldOpIntoSelect(), llvm::APInt::getBitWidth(), llvm::APInt::getOneBitSet(), llvm::APInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), hasNoUnsignedWrap(), I, llvm::APInt::isAllOnes(), llvm::isGuaranteedNotToBeUndef(), llvm::Type::isIntOrIntVectorTy(), isMultiple(), llvm::APInt::isZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_NSWAddLike(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Mul, multiplyOverflows(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::Instruction::setIsExact(), SimplifyDemandedInstructionBits(), simplifyDivRemOfSelectWithZeroOp(), simplifyValueKnownNonZero(), llvm::APInt::udiv(), llvm::APInt::ule(), llvm::APInt::ult(), X, and Y.
Referenced by visitSDiv(), and visitUDiv().
Instruction * InstCombinerImpl::commonIRemTransforms | ( | BinaryOperator & | I | ) |
This function implements the transforms common to both integer remainder instructions (urem and srem).
It is called by the visitors to those integer remainder instructions. Common integer remainder transforms
Definition at line 2110 of file InstCombineMulDivRem.cpp.
References foldBinopWithPhiOperands(), foldOpIntoPhi(), FoldOpIntoSelect(), I, llvm::APInt::isMinSignedValue(), llvm::APInt::isMinValue(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), SimplifyDemandedInstructionBits(), simplifyDivRemOfSelectWithZeroOp(), simplifyIRemMulShl(), and simplifyValueKnownNonZero().
Referenced by visitSRem(), and visitURem().
Instruction * InstCombinerImpl::commonShiftTransforms | ( | BinaryOperator & | I | ) |
Definition at line 405 of file InstCombineShifts.cpp.
References A, llvm::InstCombiner::AC, assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::BinaryOperator::Create(), llvm::CastInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateZExt(), foldBinopWithPhiOperands(), FoldOpIntoSelect(), FoldShiftByConstant(), foldShiftOfShiftedBinOp(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), I, llvm::APInt::isNegative(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), reassociateShiftAmtsOfTwoSameDirectionShifts(), llvm::InstCombiner::replaceOperand(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::Instruction::setIsExact(), SimplifyDemandedInstructionBits(), llvm::InstCombiner::SQ, and Y.
Referenced by visitAShr(), visitLShr(), and visitShl().
|
inline |
Definition at line 200 of file InstCombineInternal.h.
References llvm::computeKnownFPClass(), and llvm::Depth.
Referenced by foldSelectIntoOp(), and SimplifyDemandedUseFPClass().
|
inline |
Definition at line 209 of file InstCombineInternal.h.
References llvm::computeKnownFPClass(), and llvm::Depth.
OverflowResult InstCombinerImpl::computeOverflow | ( | Instruction::BinaryOps | BinaryOp, |
bool | IsSigned, | ||
Value * | LHS, | ||
Value * | RHS, | ||
Instruction * | CxtI | ||
) | const |
Definition at line 6118 of file InstCombineCompares.cpp.
References llvm::InstCombiner::computeOverflowForSignedAdd(), llvm::InstCombiner::computeOverflowForSignedMul(), llvm::InstCombiner::computeOverflowForSignedSub(), llvm::InstCombiner::computeOverflowForUnsignedAdd(), llvm::InstCombiner::computeOverflowForUnsignedMul(), llvm::InstCombiner::computeOverflowForUnsignedSub(), LHS, llvm_unreachable, and RHS.
Referenced by foldICmpBinOpEqualityWithConstant(), and visitCallInst().
std::optional< std::pair< Intrinsic::ID, SmallVector< Value *, 3 > > > InstCombinerImpl::convertOrOfShiftsToFunnelShift | ( | Instruction & | Or | ) |
Definition at line 2858 of file InstCombineAndOrXor.cpp.
References assert(), llvm::InstCombiner::computeKnownBits(), llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::SmallVectorBase< Size_T >::empty(), llvm::ConstantExpr::getAdd(), llvm::KnownBits::getMaxValue(), llvm::Instruction::getOpcode(), llvm::Value::getType(), High, llvm::CmpInst::ICMP_ULT, llvm::isPowerOf2_32(), llvm::InstCombiner::LI, llvm::Low, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LogicalShift(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::Constant::mergeUndefsWith(), llvm::Or, std::swap(), llvm::APInt::uge(), llvm::APInt::ugt(), llvm::APInt::ule(), llvm::APInt::ult(), llvm::Value::users(), X, and Y.
Referenced by matchFunnelShift(), and SimplifyDemandedUseBits().
|
inline |
Create and insert the idiom we use to indicate a block is unreachable without having to rewrite the CFG from within InstCombine.
Definition at line 458 of file InstCombineInternal.h.
References Align, llvm::Value::getContext(), llvm::ilist_node_impl< OptionsT >::getIterator(), and SI().
Referenced by visitCallInst(), visitFree(), and visitLoadInst().
bool InstCombinerImpl::dominatesAllUses | ( | const Instruction * | DI, |
const Instruction * | UI, | ||
const BasicBlock * | DB | ||
) | const |
True when DB dominates all uses of DI except UI.
Check that one use is in the same block as the definition and all other uses are in blocks dominated by a given block.
UI must be in the same block as DI. The routine checks that the DI parent and DB are different.
DI | Definition |
UI | Use |
DB | Block that must dominate all uses of DI outside the parent block |
UI
is the only use of DI
in the parent block and all other uses of DI
are in blocks dominated by DB
. Definition at line 6391 of file InstCombineCompares.cpp.
References assert(), llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), and llvm::Value::users().
Referenced by replacedSelectWithOperand().
|
inlineoverridevirtual |
Combiner aware instruction erasure.
When dealing with an instruction that has side effects or produces a void value, we can't rely on DCE to delete the instruction. Instead, visit methods should return the value returned by this function.
Implements llvm::InstCombiner.
Definition at line 471 of file InstCombineInternal.h.
References assert(), llvm::dbgs(), I, LLVM_DEBUG, and llvm::salvageDebugInfo().
Referenced by combineLoadToOperationType(), foldAllocaCmp(), foldIntegerTypedPHI(), foldMultiplicationOverflowCheck(), foldOpIntoPhi(), handleUnreachableFrom(), mergeStoreIntoSuccessor(), processUGT_ADDCST_ADD(), removeInstructionsBeforeUnreachable(), removeTriviallyEmptyRange(), run(), visitAllocaInst(), visitAllocSite(), visitCallInst(), visitFenceInst(), visitFree(), visitICmpInst(), and visitStoreInst().
Given an expression that CanEvaluateTruncated or CanEvaluateSExtd returns true for, actually insert the code to evaluate the expression.
Definition at line 30 of file InstCombineCasts.cpp.
References llvm::PHINode::addIncoming(), llvm::CallingConv::C, llvm::ConstantFoldIntegerCast(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::CastInst::Create(), llvm::PHINode::Create(), llvm::SelectInst::Create(), llvm::CastInst::CreateIntegerCast(), llvm::InstCombiner::DL, EvaluateInDifferentType(), llvm::VectorType::get(), llvm::Intrinsic::getDeclaration(), llvm::Function::getFunctionType(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), I, II, llvm::InstCombiner::InsertNewInstWith(), isSigned(), LHS, llvm_unreachable, RHS, and llvm::Value::takeName().
Referenced by EvaluateInDifferentType(), visitSExt(), visitTrunc(), and visitZExt().
bool llvm::InstCombinerImpl::fmulByZeroIsZero | ( | Value * | MulVal, |
FastMathFlags | FMF, | ||
const Instruction * | CtxI | ||
) | const |
Check if fmul MulVal
, +0.0 will yield +0.0 (or signed zero is ignorable).
Instruction * InstCombinerImpl::foldAddWithConstant | ( | BinaryOperator & | Add | ) |
Definition at line 856 of file InstCombineAddSub.cpp.
References llvm::Add, llvm::InstCombiner::AddOne(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::InstCombiner::computeKnownBits(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateIsNotNeg(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateShl(), foldBinOpIntoSelectOrPhi(), llvm::ConstantExpr::getAdd(), llvm::APInt::getHighBitsSet(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), llvm::isKnownNonZero(), llvm::APInt::isMask(), llvm::APInt::isMinSignedValue(), llvm::APInt::isPowerOf2(), llvm::APInt::isSignMask(), llvm::APInt::logBase2(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_DisjointOr(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZExt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::APInt::sext(), llvm::InstCombiner::SQ, llvm::InstCombiner::SubOne(), X, Y, and llvm::KnownBits::Zero.
Referenced by visitAdd().
Instruction * InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse | ( | InsertValueInst & | OrigIVI | ) |
Look for chain of insertvalue's that fully define an aggregate, and trace back the values inserted, see if they are all were extractvalue'd from the same source aggregate from the exact same element indexes.
If they were, just reuse the source aggregate. This potentially deals with PHI indirections.
When analyzing the value that was inserted into an aggregate, we did not manage to find defining extractvalue
instruction to analyze.
When analyzing the value that was inserted into an aggregate, we did manage to find defining extractvalue
instruction[s], and everything matched perfectly - aggregate type, element insertion/extraction index.
When analyzing the value that was inserted into an aggregate, we did manage to find defining extractvalue
instruction, but there was a mismatch: either the source type from which the extraction was didn't match the aggregate type into which the insertion was, or the extraction/insertion channels mismatched, or different elements had different source aggregates.
Definition at line 868 of file InstCombineVectorOps.cpp.
References llvm::Type::ArrayTyID, assert(), llvm::Depth, llvm::Value::DoPHITranslation(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::enumerate(), llvm::ArrayRef< T >::front(), llvm::Type::getArrayNumElements(), llvm::BasicBlock::getParent(), llvm::Type::getStructNumElements(), llvm::Value::getType(), llvm::Type::getTypeID(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::is_contained(), IV, llvm_unreachable, llvm::pred_empty(), llvm::predecessors(), llvm::InstCombiner::replaceInstUsesWith(), llvm::ArrayRef< T >::size(), llvm::SmallVectorBase< Size_T >::size(), and llvm::Type::StructTyID.
Referenced by visitInsertValueInst().
bool InstCombinerImpl::foldAllocaCmp | ( | AllocaInst * | Alloca | ) |
The value of the map is a bit mask of which icmp operands the alloca is used in.
Definition at line 834 of file InstCombineCompares.cpp.
References eraseInstFromFunction(), llvm::getUnderlyingObject(), llvm::CmpInst::ICMP_NE, llvm::MapVector< KeyT, ValueT, MapType, VectorType >::insert(), llvm_unreachable, Operands, llvm::PointerMayBeCaptured(), and llvm::InstCombiner::replaceInstUsesWith().
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldBinOpIntoSelectOrPhi | ( | BinaryOperator & | I | ) |
This is a convenience wrapper function for the above two functions.
Definition at line 1987 of file InstructionCombining.cpp.
References foldOpIntoPhi(), FoldOpIntoSelect(), and I.
Referenced by commonIDivTransforms(), foldAddWithConstant(), FoldShiftByConstant(), visitAnd(), visitFAdd(), visitFMul(), visitMul(), visitOr(), and visitXor().
Instruction * InstCombinerImpl::foldBinOpOfSelectAndCastOfSelectCondition | ( | BinaryOperator & | I | ) |
Tries to simplify binops of select and cast of the select condition.
(Binop (cast C), (select C, T, F)) -> (select C, C0, C1)
Definition at line 1023 of file InstructionCombining.cpp.
References A, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::Constant::getAllOnesValue(), llvm::Constant::getIntegerValue(), llvm::Constant::getNullValue(), I, LHS, llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), and RHS.
Referenced by visitAdd(), visitMul(), and visitSub().
Instruction * InstCombinerImpl::foldBinOpShiftWithShift | ( | BinaryOperator & | I | ) |
Definition at line 876 of file InstructionCombining.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::ConstantFoldBinaryOpOperands(), llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateNot(), llvm::InstCombiner::DL, I, llvm::Instruction::isBitwiseLogicOp(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shift(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
Referenced by visitAdd(), visitAnd(), visitOr(), and visitXor().
Instruction * InstCombinerImpl::foldBinopWithPhiOperands | ( | BinaryOperator & | BO | ) |
For a binary operator with 2 phi operands, try to hoist the binary operation before the phi.
This can result in fewer instructions in patterns where at least one set of phi operands simplifies. Example: BB3: binop (phi [X, BB1], [C1, BB2]), (phi [Y, BB1], [C2, BB2]) --> BB1: BO = binop X, Y BB3: phi [BO, BB1], [(binop C1, C2), BB2]
Definition at line 1876 of file InstructionCombining.cpp.
References llvm::PHINode::addIncoming(), llvm::all_of(), assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::PHINode::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, llvm::ConstantExpr::getBinOpIdentity(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, llvm::isGuaranteedToTransferExecutionToSuccessor(), llvm::DominatorTree::isReachableFromEntry(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorBase< Size_T >::size(), and llvm::zip().
Referenced by commonIDivTransforms(), commonIRemTransforms(), commonShiftTransforms(), visitAdd(), visitAnd(), visitFAdd(), visitFDiv(), visitFMul(), visitFRem(), visitFSub(), visitMul(), visitOr(), visitSub(), and visitXor().
Instruction * InstCombinerImpl::foldCmpLoadFromIndexedGlobal | ( | LoadInst * | LI, |
GetElementPtrInst * | GEP, | ||
GlobalVariable * | GV, | ||
CmpInst & | ICI, | ||
ConstantInt * | AndCst = nullptr |
||
) |
This is called when we see this pattern: cmp pred (load (gep GV, ...)), cmpcst where GV is a global variable with a constant initializer.
Try to simplify this into some simple computation that does not need the load. For example we can optimize "icmp eq (load (gep "foo", 0, i)), 0" into "icmp eq i, 3".
If AndCst is non-null, then the loaded value is masked with that constant before doing the comparison. This handles cases like "A[i]&4 == 0".
TrueRangeEnd/FalseRangeEnd - In conjunction with First*Element, these define a state machine that triggers for ranges of values that the index is true or false for. This triggers on things like "abbbbc"[i] == 'b'. This is -2 when undefined, -3 when overdefined, and otherwise the last index in the range (inclusive). We use -2 for undefined here because we use relative comparisons and don't want 0-1 to match -1.
Definition at line 111 of file InstCombineCompares.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldExtractValueInstruction(), llvm::countr_zero(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpNE(), llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateTrunc(), llvm::InstCombiner::DL, llvm::SmallVectorBase< Size_T >::empty(), End, GEP, llvm::Constant::getAllOnesValue(), llvm::IRBuilderBase::getFalse(), llvm::DataLayout::getIndexType(), llvm::GlobalVariable::getInitializer(), llvm::Type::getIntegerBitWidth(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::DataLayout::getSmallestLegalIntType(), llvm::IRBuilderBase::getTrue(), getType(), llvm::DataLayout::getTypeAllocSize(), llvm::GlobalValue::getValueType(), llvm::GlobalVariable::hasDefinitiveInitializer(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, Idx, llvm::GlobalVariable::isConstant(), llvm::InstCombiner::LI, llvm::InstCombiner::MaxArraySizeForCombine, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), and llvm::InstCombiner::TLI.
Referenced by foldICmpAndConstant(), foldICmpInstWithConstantNotInt(), and visitFCmpInst().
Instruction * InstCombinerImpl::foldFCmpIntToFPConst | ( | FCmpInst & | I, |
Instruction * | LHSI, | ||
Constant * | RHSC | ||
) |
Fold fcmp ([us]itofp x, cst) if possible.
Definition at line 7663 of file InstCombineCompares.cpp.
References assert(), llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::ConstantInt::getFalse(), llvm::Type::getFPMantissaWidth(), llvm::APFloat::getLargest(), llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), I, 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::APFloatBase::IEK_Inf, llvm_unreachable, llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::match(), P, llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::APFloatBase::rmNearestTiesToEven, llvm::APFloatBase::rmTowardZero, llvm::APFloat::roundToIntegral(), llvm::SMax, llvm::SMin, llvm::UMax, and llvm::UMin.
Referenced by visitFCmpInst().
Instruction * InstCombinerImpl::foldFMulReassoc | ( | BinaryOperator & | I | ) |
Definition at line 675 of file InstCombineMulDivRem.cpp.
References llvm::FastMathFlags::allowReassoc(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateFAddFMF(), llvm::BinaryOperator::CreateFAddFMF(), llvm::BinaryOperator::CreateFDivFMF(), llvm::IRBuilderBase::CreateFMul(), llvm::IRBuilderBase::CreateFMulFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::BinaryOperator::CreateFSubFMF(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::InstCombiner::DL, foldPowiReassoc(), llvm::Instruction::getFastMathFlags(), llvm::Value::hasNUses(), llvm::Value::hasOneUse(), I, llvm::Constant::isNormalFP(), llvm::PatternMatch::m_AllowReassoc(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FAdd(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_Sqrt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::setFastMathFlags(), X, and Y.
Referenced by visitFMul().
Instruction * InstCombinerImpl::foldFreezeIntoRecurrence | ( | FreezeInst & | I, |
PHINode * | PN | ||
) |
Definition at line 4485 of file InstructionCombining.cpp.
References llvm::append_range(), llvm::InstCombiner::Builder, llvm::canCreateUndefOrPoison(), llvm::IRBuilderBase::CreateFreeze(), llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::PHINode::getIncomingBlock(), llvm::Value::getName(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), I, llvm::PHINode::incoming_values(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceUse(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallPtrSetImplBase::size(), and llvm::InstCombiner::Worklist.
Referenced by visitFreeze().
Instruction * InstCombinerImpl::foldGEPICmp | ( | GEPOperator * | GEPLHS, |
Value * | RHS, | ||
ICmpInst::Predicate | Cond, | ||
Instruction & | I | ||
) |
Fold comparisons between a GEP instruction and something else.
At this point we know that the GEP is on the LHS of the comparison.
Definition at line 674 of file InstCombineCompares.cpp.
References llvm::sampleprof::Base, llvm::InstCombiner::Builder, Cond, llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateVectorSplat(), llvm::InstCombiner::DL, llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::Constant::getNullValue(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Type::getPointerAddressSpace(), llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(), llvm::GEPOperator::getPointerOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::ICmpInst::getSignedPredicate(), llvm::GEPOperator::getSourceElementType(), llvm::Value::getType(), llvm::GEPOperator::hasAllConstantIndices(), llvm::Value::hasOneUse(), I, llvm::CmpInst::isEquality(), llvm::ICmpInst::isEquality(), llvm::GEPOperator::isInBounds(), llvm::CmpInst::isSigned(), llvm::CmpInst::isTrueWhenEqual(), llvm::Type::isVectorTy(), llvm::CmpInst::makeCmpResultType(), llvm::NullPointerIsDefined(), llvm::Offset, llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::Value::stripPointerCasts(), and transformToIndexedCompare().
Referenced by foldICmpCommutative().
Instruction * InstCombinerImpl::foldICmpAddConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Add, | ||
const APInt & | C | ||
) |
Fold icmp (add X, Y), C.
Definition at line 3021 of file InstCombineCompares.cpp.
References llvm::Add, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ICmpInst::compare(), llvm::computeConstantRange(), Cond, llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), createLogicFromTable(), llvm::ConstantExpr::getNeg(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm::ICmpInst::getSignedPredicate(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::APInt::isAllOnes(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownNonZero(), llvm::APInt::isPowerOf2(), llvm::CmpInst::isUnsigned(), llvm::Lower, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::SMax, llvm::SMin, llvm::InstCombiner::SQ, llvm::ConstantRange::subtract(), llvm::Upper, X, and Y.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpAddOpConst | ( | Value * | X, |
const APInt & | C, | ||
ICmpInst::Predicate | Pred | ||
) |
Fold "icmp pred (X+C), X".
Definition at line 912 of file InstCombineCompares.cpp.
References assert(), llvm::CallingConv::C, llvm::APInt::getMaxValue(), llvm::APInt::getSignedMaxValue(), 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::SMax, and X.
Referenced by foldICmpCommutative().
Instruction * InstCombinerImpl::foldICmpAndConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | And, | ||
const APInt & | C | ||
) |
Fold icmp (and X, Y), C.
Definition at line 1874 of file InstCombineCompares.cpp.
References A, llvm::And, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateLShr(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateXor(), foldCmpLoadFromIndexedGlobal(), foldICmpAndConstConst(), GEP, llvm::Constant::getNullValue(), llvm::APInt::getSignedMinValue(), llvm::Value::getType(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::APInt::intersects(), llvm::isSignBitCheck(), llvm::APInt::isZero(), llvm::InstCombiner::LI, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::SubOne(), X, and Y.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpAndConstConst | ( | ICmpInst & | Cmp, |
BinaryOperator * | And, | ||
const APInt & | C1 | ||
) |
Fold icmp (and X, C2), C1.
Definition at line 1744 of file InstCombineCompares.cpp.
References A, llvm::And, B, llvm::APFloat::bitcastToAPInt(), llvm::InstCombiner::Builder, llvm::InstCombiner::computeKnownBits(), llvm::KnownBits::countMinLeadingZeros(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::createIsFPClass(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateShl(), llvm::fcAllFlags, llvm::fcInf, llvm::fcNan, foldICmpAndShift(), llvm::APInt::getBitWidth(), llvm::Type::getFltSemantics(), llvm::APInt::getHighBitsSet(), llvm::APFloat::getInf(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, llvm::Type::isIEEELikeFPTy(), llvm::APInt::isNegatedPowerOf2(), llvm::APInt::isNegative(), llvm::APInt::isSignMask(), llvm::APInt::isZero(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Or, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), X, and llvm::APInt::zext().
Referenced by foldICmpAndConstant().
Instruction * InstCombinerImpl::foldICmpAndShift | ( | ICmpInst & | Cmp, |
BinaryOperator * | And, | ||
const APInt & | C1, | ||
const APInt & | C2 | ||
) |
Fold icmp (and (sh X, Y), C2), C1.
Definition at line 1657 of file InstCombineCompares.cpp.
References llvm::And, llvm::APInt::ashr(), assert(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateShl(), llvm::ConstantInt::getFalse(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ConstantInt::getTrue(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::Instruction::isArithmeticShift(), llvm::APInt::isNegative(), llvm::APInt::isOne(), llvm::Instruction::isShift(), llvm::APInt::isZero(), llvm::APInt::lshr(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), and llvm::APInt::shl().
Referenced by foldICmpAndConstConst().
Instruction * InstCombinerImpl::foldICmpBinOp | ( | ICmpInst & | I, |
const SimplifyQuery & | SQ | ||
) |
Try to fold icmp (binop), X or icmp X, (binop).
TODO: A large part of this logic is duplicated in InstSimplify's simplifyICmpWithBinOp(). We should be able to share that and avoid the code duplication.
Definition at line 4956 of file InstCombineCompares.cpp.
References A, llvm::APInt::abs(), assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::InstCombiner::computeKnownBits(), llvm::KnownBits::countMaxTrailingZeros(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateSub(), D, foldICmpAndXX(), foldICmpOrXX(), foldICmpWithTruncSignExtendedVal(), foldICmpXNegX(), foldICmpXorXX(), foldMultiplicationOverflowCheck(), foldShiftIntoShiftInAnotherHandOfAndInICmp(), llvm::Constant::getAllOnesValue(), llvm::ConstantInt::getFalse(), llvm::CmpInst::getFlippedStrictnessPredicate(), llvm::Constant::getIntegerValue(), llvm::APInt::getLowBitsSet(), llvm::ConstantExpr::getNeg(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ICmpInst::getSignedPredicate(), llvm::ConstantExpr::getSub(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::ICmpInst::getUnsignedPredicate(), llvm::SimplifyQuery::getWithInstruction(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), I, 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::isKnownNonZero(), llvm::APInt::isNegative(), llvm::CmpInst::isSigned(), llvm::CmpInst::isUnsigned(), llvm::APInt::isZero(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AddLike(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LowBitMask(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NonNegative(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::KnownBits::One, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::SQ, llvm::APInt::uge(), llvm::APInt::ule(), X, and Y.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpBinOpEqualityWithConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | BO, | ||
const APInt & | C | ||
) |
Fold an icmp equality instruction with binary operator LHS and constant RHS: icmp eq/ne BO, C.
Definition at line 3468 of file InstCombineCompares.cpp.
References llvm::And, llvm::InstCombiner::Builder, llvm::CallingConv::C, computeOverflow(), Cond, llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateMul(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateURem(), llvm::Value::getName(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::ConstantExpr::getXor(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::Instruction::isExact(), llvm::isKnownNonZero(), llvm::APInt::isPowerOf2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_NUWAdd(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::NeverOverflows, llvm::Or, llvm::Other, RHS, llvm::APInt::sgt(), llvm::InstCombiner::SQ, and llvm::Value::takeName().
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpBinOpWithConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | BO, | ||
const APInt & | C | ||
) |
Fold an icmp with BinaryOp and constant operand: icmp Pred BO, C.
Definition at line 3847 of file InstCombineCompares.cpp.
References llvm::CallingConv::C, foldICmpAddConstant(), foldICmpAndConstant(), foldICmpBinOpEqualityWithConstant(), foldICmpDivConstant(), foldICmpMulConstant(), foldICmpOrConstant(), foldICmpShlConstant(), foldICmpShrConstant(), foldICmpSRemConstant(), foldICmpSubConstant(), foldICmpUDivConstant(), foldICmpXorConstant(), llvm::BinaryOperator::getOpcode(), and I.
Referenced by foldICmpInstWithConstant().
Instruction * InstCombinerImpl::foldICmpBitCast | ( | ICmpInst & | Cmp | ) |
Definition at line 3267 of file InstCombineCompares.cpp.
References llvm::all_equal(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APFloat::classify(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateExtractElement(), llvm::IRBuilderBase::createIsFPClass(), llvm::fcInf, llvm::fcZero, llvm::VectorType::get(), llvm::Constant::getAllOnesValue(), llvm::Type::getFltSemantics(), llvm::InstCombiner::getFreelyInverted(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getIntNTy(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::Type::isIEEELikeFPTy(), llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::Type::isPPC_FP128Ty(), llvm::isSignBitCheck(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_FPTrunc(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_SIToFP(), llvm::PatternMatch::m_UIToFP(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), and X.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpCommutative | ( | ICmpInst::Predicate | Pred, |
Value * | Op0, | ||
Value * | Op1, | ||
ICmpInst & | CxtI | ||
) |
Definition at line 7247 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateICmpSGT(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateICmpUGT(), llvm::IRBuilderBase::CreateICmpULT(), foldGEPICmp(), foldICmpAddOpConst(), foldICmpWithLowBitMaskedVal(), foldICmpWithMinMax(), foldSelectICmp(), GEP, llvm::Constant::getAllOnesValue(), llvm::ConstantInt::getFalse(), llvm::Constant::getNullValue(), llvm::APInt::getSignedMinValue(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), 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::CmpInst::isUnsigned(), llvm_unreachable, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_CheckedInt(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::SMin, llvm::InstCombiner::SQ, and X.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpDivConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Div, | ||
const APInt & | C | ||
) |
Fold icmp ({su}div X, Y), C.
Definition at line 2704 of file InstCombineCompares.cpp.
References addWithOverflow(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateICmp(), llvm::APInt::getBitWidth(), llvm::IRBuilderBase::getFalse(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::CmpInst::getSwappedPredicate(), llvm::IRBuilderBase::getTrue(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, insertRangeTest(), llvm::APInt::isAllOnes(), llvm::Instruction::isExact(), llvm::APInt::isNegative(), llvm::APInt::isOne(), llvm::APInt::isStrictlyPositive(), llvm::APInt::isZero(), llvm_unreachable, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::APInt::negate(), llvm::InstCombiner::replaceInstUsesWith(), llvm::APInt::sdiv(), subWithOverflow(), llvm::APInt::udiv(), X, and Y.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpEqIntrinsicWithConstant | ( | ICmpInst & | ICI, |
IntrinsicInst * | II, | ||
const APInt & | C | ||
) |
Fold an equality icmp with LLVM intrinsic and constant operand.
Definition at line 3661 of file InstCombineCompares.cpp.
References llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateOr(), llvm::Constant::getAllOnesValue(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, II, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), and llvm::Or.
Referenced by foldICmpIntrinsicWithConstant().
Instruction * InstCombinerImpl::foldICmpEquality | ( | ICmpInst & | Cmp | ) |
Definition at line 5631 of file InstCombineCompares.cpp.
References A, llvm::Add, llvm::And, B, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::countr_one(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateXor(), D, foldICmpIntrinsicWithIntrinsic(), llvm::APInt::getBitWidth(), llvm::ConstantInt::getBitWidth(), llvm::IRBuilderBase::getInt(), llvm::CmpInst::getInversePredicate(), llvm::APInt::getLimitedValue(), llvm::ConstantInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::ConstantExpr::getNot(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LowBitMask(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Unless(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), NC, X, llvm::Xor, Y, and llvm::APInt::zext().
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpInstWithConstant | ( | ICmpInst & | Cmp | ) |
Try to fold integer comparisons with a constant operand: icmp Pred X, C where X is some kind of instruction.
Definition at line 3421 of file InstCombineCompares.cpp.
References llvm::CallingConv::C, foldICmpBinOpWithConstant(), foldICmpInstWithConstantAllowPoison(), foldICmpIntrinsicWithConstant(), foldICmpSelectConstant(), foldICmpTruncConstant(), llvm::Value::hasOneUse(), I, II, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpInstWithConstantAllowPoison | ( | ICmpInst & | Cmp, |
const APInt & | C | ||
) |
Try to fold integer comparisons with a constant operand: icmp Pred X, C where X is some kind of instruction and C is AllowPoison.
TODO: Move more folds which allow poison to this function.
Definition at line 3825 of file InstCombineCompares.cpp.
References llvm::CallingConv::C, and II.
Referenced by foldICmpInstWithConstant().
Instruction * InstCombinerImpl::foldICmpInstWithConstantNotInt | ( | ICmpInst & | Cmp | ) |
Handle icmp with constant (but not simple integer constant) RHS.
Definition at line 4154 of file InstCombineCompares.cpp.
References llvm::InstCombiner::DL, foldCmpLoadFromIndexedGlobal(), foldOpIntoPhi(), GEP, llvm::DataLayout::getIntPtrType(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), I, and llvm::Constant::isNullValue().
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpIntrinsicWithConstant | ( | ICmpInst & | ICI, |
IntrinsicInst * | II, | ||
const APInt & | C | ||
) |
Fold an icmp with LLVM intrinsic and constant operand: icmp Pred II, C.
Definition at line 4046 of file InstCombineCompares.cpp.
References llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::CmpInst::Create(), llvm::IRBuilderBase::CreateAnd(), foldCtpopPow2Test(), foldICmpEqIntrinsicWithConstant(), foldICmpOfCmpIntrinsicWithConstant(), foldICmpUSubSatOrUAddSatWithConstant(), llvm::Constant::getAllOnesValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::SimplifyQuery::getWithInstruction(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, II, llvm::CmpInst::isSigned(), llvm::InstCombiner::SQ, and X.
Referenced by foldICmpInstWithConstant(), and foldICmpWithTrunc().
Instruction * InstCombinerImpl::foldICmpMulConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Mul, | ||
const APInt & | C | ||
) |
Fold icmp (mul X, Y), C.
Definition at line 2140 of file InstCombineCompares.cpp.
References assert(), llvm::CallingConv::C, llvm::APInt::DOWN, llvm::Constant::getNullValue(), llvm::CmpInst::getSwappedPredicate(), 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::APInt::isAllOnes(), llvm::APInt::isNegative(), llvm::CmpInst::isSigned(), isSignTest(), llvm::CmpInst::isUnsigned(), llvm::APInt::isZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::Mul, llvm::APIntOps::RoundingSDiv(), llvm::APIntOps::RoundingUDiv(), llvm::APInt::UP, and X.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpOrConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Or, | ||
const APInt & | C | ||
) |
Fold icmp (or X, Y), C.
Definition at line 2039 of file InstCombineCompares.cpp.
References llvm::And, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateXor(), foldICmpOrXorSubChain(), llvm::CmpInst::getFlippedStrictnessPredicate(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::isSignBitCheck(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Signum(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Or, P, llvm::InstCombiner::replaceInstUsesWith(), llvm::APInt::sge(), llvm::APInt::sgt(), and X.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpSelectConstant | ( | ICmpInst & | Cmp, |
SelectInst * | Select, | ||
ConstantInt * | C | ||
) |
Definition at line 3219 of file InstCombineCompares.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ICmpInst::compare(), Cond, llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::getFalse(), llvm::ConstantInt::getValue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, matchThreeWayIntCompare(), llvm::InstCombiner::replaceInstUsesWith(), and Select.
Referenced by foldICmpInstWithConstant().
Instruction * InstCombinerImpl::foldICmpShlConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Shl, | ||
const APInt & | C | ||
) |
Fold icmp (shl X, Y), C.
Definition at line 2275 of file InstCombineCompares.cpp.
References llvm::And, llvm::APInt::ashr(), assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::countr_zero(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateTrunc(), foldICmpShlConstConst(), foldICmpShlOne(), llvm::Type::getContext(), llvm::InstCombiner::getFlippedStrictnessPredicateAndConstant(), llvm::APInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::APInt::getOneBitSet(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Type::getWithNewBitWidth(), llvm::APInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::isSignBitCheck(), llvm::CmpInst::isStrictPredicate(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::APInt::trunc(), llvm::APInt::uge(), and X.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpShlConstConst | ( | ICmpInst & | I, |
Value * | ShAmt, | ||
const APInt & | C1, | ||
const APInt & | C2 | ||
) |
Handle "(icmp eq/ne (shl AP2, A), AP1)" -> (icmp eq/ne A, TrailingZeros(AP1) - TrailingZeros(AP2)).
Definition at line 1021 of file InstCombineCompares.cpp.
References A, assert(), llvm::APInt::countr_zero(), llvm::APInt::getBitWidth(), llvm::CmpInst::getInversePredicate(), llvm::Constant::getNullValue(), I, llvm::APInt::isZero(), LHS, llvm::InstCombiner::replaceInstUsesWith(), RHS, and llvm::APInt::shl().
Referenced by foldICmpShlConstant().
Instruction * InstCombinerImpl::foldICmpShrConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Shr, | ||
const APInt & | C | ||
) |
Fold icmp ({al}shr X, Y), C.
Definition at line 2456 of file InstCombineCompares.cpp.
References llvm::And, llvm::APInt::ashr(), assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::countl_zero(), llvm::countl_zero(), llvm::IRBuilderBase::CreateAnd(), foldICmpShrConstConst(), llvm::Constant::getAllOnesValue(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLimitedValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::Instruction::isExact(), llvm::APInt::isNegative(), llvm::APInt::isPowerOf2(), llvm::isSignBitCheck(), llvm::APInt::lshr(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::APInt::uge(), and X.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpShrConstConst | ( | ICmpInst & | I, |
Value * | ShAmt, | ||
const APInt & | C1, | ||
const APInt & | C2 | ||
) |
Handle "(icmp eq/ne (ashr/lshr AP2, A), AP1)" -> (icmp eq/ne A, Log2(AP2/AP1)) -> (icmp eq/ne A, Log2(AP2) - Log2(AP1)).
Definition at line 962 of file InstCombineCompares.cpp.
References A, llvm::APInt::ashr(), assert(), llvm::APInt::countl_one(), llvm::APInt::countl_zero(), llvm::CmpInst::getInversePredicate(), llvm::Constant::getNullValue(), I, llvm::APInt::isAllOnes(), llvm::APInt::isNegative(), llvm::APInt::isPowerOf2(), llvm::APInt::isZero(), LHS, llvm::APInt::logBase2(), llvm::APInt::lshr(), llvm::InstCombiner::replaceInstUsesWith(), RHS, and llvm::APInt::sgt().
Referenced by foldICmpShrConstant().
Instruction * InstCombinerImpl::foldICmpSRemConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | UDiv, | ||
const APInt & | C | ||
) |
Definition at line 2620 of file InstCombineCompares.cpp.
References llvm::And, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateAnd(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignMask(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::PatternMatch::m_Power2(), and llvm::PatternMatch::match().
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpSubConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Sub, | ||
const APInt & | C | ||
) |
Fold icmp (sub X, Y), C.
Definition at line 2886 of file InstCombineCompares.cpp.
References llvm::Add, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateOr(), llvm::User::getOperand(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::match(), llvm::none_of(), subWithOverflow(), llvm::Value::users(), X, and Y.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpTruncConstant | ( | ICmpInst & | Cmp, |
TruncInst * | Trunc, | ||
const APInt & | C | ||
) |
Fold icmp (trunc X), C.
Definition at line 1410 of file InstCombineCompares.cpp.
References llvm::And, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::InstCombiner::computeKnownBits(), llvm::IRBuilderBase::CreateAnd(), llvm::Constant::getAllOnesValue(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::APInt::getZExtValue(), llvm::TruncInst::hasNoSignedWrap(), llvm::TruncInst::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::isSignBitCheck(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Signum(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::KnownBits::One, X, Y, and llvm::KnownBits::Zero.
Referenced by foldICmpInstWithConstant().
Instruction * InstCombinerImpl::foldICmpTruncWithTruncOrExt | ( | ICmpInst & | Cmp, |
const SimplifyQuery & | Q | ||
) |
Fold icmp (trunc nuw/nsw X), (trunc nuw/nsw Y).
Fold icmp (trunc nuw/nsw X), (zext/sext Y).
Definition at line 1497 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateIntCast(), llvm::Type::getScalarSizeInBits(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_NSWTrunc(), llvm::PatternMatch::m_NUWTrunc(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::TruncInst::NoSignedWrap, llvm::TruncInst::NoUnsignedWrap, std::swap(), X, and Y.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpUDivConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | UDiv, | ||
const APInt & | C | ||
) |
Fold icmp (udiv X, Y), C.
Definition at line 2671 of file InstCombineCompares.cpp.
References assert(), llvm::CallingConv::C, llvm::User::getOperand(), llvm::Value::getType(), llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::APInt::udiv(), X, and Y.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpUsingBoolRange | ( | ICmpInst & | I | ) |
If one operand of an icmp is effectively a bool (value range of {0,1}), then try to reduce patterns based on that limit.
Definition at line 6754 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::BinaryOperator::Create(), llvm::CmpInst::Create(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateIsNull(), llvm::ConstantInt::getBool(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::ConstantInt::getSigned(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), X, and Y.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpUsingKnownBits | ( | ICmpInst & | Cmp | ) |
Try to fold the comparison based on range information we can get by checking whether bits are known to be zero or one in the inputs.
Definition at line 6494 of file InstCombineCompares.cpp.
References A, assert(), B, llvm::BitWidth, llvm::APInt::ceilLogBase2(), llvm::KnownBits::countMinTrailingZeros(), llvm::APInt::countr_zero(), llvm::InstCombiner::DL, llvm::SelectPatternResult::Flavor, llvm::APInt::getActiveBits(), llvm::APInt::getAllOnes(), llvm::ConstantInt::getBool(), llvm::KnownBits::getConstant(), getDemandedBitsLHSMask(), llvm::ConstantInt::getFalse(), llvm::Constant::getIntegerValue(), llvm::CmpInst::getInversePredicate(), llvm::KnownBits::getMaxValue(), llvm::KnownBits::getMinValue(), llvm::Constant::getNullValue(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::KnownBits::getSignedMaxValue(), llvm::KnownBits::getSignedMinValue(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::SimplifyQuery::getWithoutDomCondCache(), I, 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::KnownBits::isConstant(), llvm::Type::isIntOrIntVectorTy(), llvm::SelectPatternResult::isMinOrMax(), llvm::APInt::isNegative(), llvm::APInt::isPowerOf2(), llvm::KnownBits::isZero(), LHS, llvm_unreachable, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_MaxOrMin(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), llvm::KnownBits::One, llvm::InstCombiner::replaceInstUsesWith(), SimplifyDemandedBits(), llvm::APInt::sle(), llvm::APInt::slt(), llvm::InstCombiner::SQ, llvm::APInt::ule(), llvm::APInt::ult(), X, and llvm::KnownBits::Zero.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpWithCastOp | ( | ICmpInst & | ICmp | ) |
Handle icmp (cast x), (cast or constant).
Definition at line 6053 of file InstCombineCompares.cpp.
References llvm::InstCombiner::DL, foldICmpWithTrunc(), foldICmpWithZextOrSext(), llvm::Type::getIntegerBitWidth(), llvm::ConstantExpr::getIntToPtr(), llvm::User::getOperand(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::CmpInst::getPredicate(), and llvm::Value::getType().
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpWithConstant | ( | ICmpInst & | Cmp | ) |
Fold icmp Pred X, C.
TODO: This code structure does not make sense. The saturating add fold should be moved to some other helper and extended as noted below (it is also possible that code has been made unnecessary - do we canonicalize IR to overflow/saturating intrinsics or not?).
Definition at line 1284 of file InstCombineCompares.cpp.
References A, llvm::PHINode::addIncoming(), llvm::all_of(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldCompareInstOperands(), llvm::IRBuilderBase::CreatePHI(), llvm::InstCombiner::DL, llvm::CmpInst::ICMP_UGT, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), processUGT_ADDCST_ADD(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), tryFoldInstWithCtpopWithNot(), and llvm::zip().
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpWithDominatingICmp | ( | ICmpInst & | Cmp | ) |
Canonicalize icmp instructions based on dominating conditions.
Definition at line 1334 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::DomConditionCache::conditionsFor(), llvm::InstCombiner::DC, llvm::ConstantRange::difference(), llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::IRBuilderBase::getFalse(), llvm::IRBuilderBase::getInt(), llvm::CmpInst::getInversePredicate(), llvm::ConstantRange::getSingleElement(), llvm::IRBuilderBase::getTrue(), hasBranchUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::ConstantRange::intersectWith(), llvm::ConstantRange::isEmptySet(), llvm::isSignBitCheck(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_MaxOrMin(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), X, and Y.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpWithMinMax | ( | Instruction & | I, |
MinMaxIntrinsic * | MinMax, | ||
Value * | Z, | ||
ICmpInst::Predicate | Pred | ||
) |
Fold icmp Pred min|max(X, Y), Z.
Definition at line 5437 of file InstCombineCompares.cpp.
References llvm::CmpInst::Create(), llvm::ConstantInt::getBool(), llvm::ConstantInt::getFalse(), llvm::CmpInst::getFlippedSignednessPredicate(), llvm::CmpInst::getInversePredicate(), llvm::CmpInst::getNonStrictPredicate(), llvm::CmpInst::getStrictPredicate(), llvm::ConstantInt::getTrue(), llvm::SimplifyQuery::getWithInstruction(), I, 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::isKnownNonNegative(), llvm::CmpInst::isSigned(), llvm::CmpInst::isUnsigned(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::simplifyICmpInst(), llvm::InstCombiner::SQ, std::swap(), X, and Y.
Referenced by foldICmpCommutative().
Instruction * InstCombinerImpl::foldICmpWithTrunc | ( | ICmpInst & | Cmp | ) |
Definition at line 5880 of file InstCombineCompares.cpp.
References llvm::And, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateAnd(), llvm::decomposeBitTestICmp(), foldICmpIntrinsicWithConstant(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, II, llvm::Log2_32(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.
Referenced by foldICmpWithCastOp().
Instruction * InstCombinerImpl::foldICmpWithZero | ( | ICmpInst & | Cmp | ) |
Definition at line 1202 of file InstCombineCompares.cpp.
References A, B, llvm::InstCombiner::computeKnownBits(), llvm::KnownBits::countMaxPopulation(), llvm::KnownBits::countMaxTrailingZeros(), llvm::KnownBits::countMinPopulation(), foldIRemByPowerOfTwoToBitTest(), llvm::SimplifyQuery::getWithInstruction(), llvm::CmpInst::ICMP_SGT, llvm::ICmpInst::isEquality(), llvm::isKnownNonZero(), llvm::isKnownPositive(), llvm::APInt::isZero(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_URem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::KnownBits::One, llvm::InstCombiner::SQ, X, and Y.
Referenced by visitICmpInst().
Instruction * InstCombinerImpl::foldICmpWithZextOrSext | ( | ICmpInst & | ICmp | ) |
Definition at line 5940 of file InstCombineCompares.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateCast(), llvm::IRBuilderBase::CreateOr(), llvm::Constant::getAllOnesValue(), getLosslessTrunc(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Type::getScalarSizeInBits(), llvm::ICmpInst::getUnsignedPredicate(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::CmpInst::isSigned(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), X, and Y.
Referenced by foldICmpWithCastOp().
Instruction * InstCombinerImpl::foldICmpXorConstant | ( | ICmpInst & | Cmp, |
BinaryOperator * | Xor, | ||
const APInt & | C | ||
) |
Fold icmp (xor X, Y), C.
Definition at line 1556 of file InstCombineCompares.cpp.
References llvm::CallingConv::C, foldICmpXorShiftConst(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), I, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::APInt::isMaxSignedValue(), llvm::APInt::isNegative(), llvm::isSignBitCheck(), llvm::APInt::isSignMask(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), X, llvm::Xor, and Y.
Referenced by foldICmpBinOpWithConstant().
Instruction * InstCombinerImpl::foldICmpXorShiftConst | ( | ICmpInst & | Cmp, |
BinaryOperator * | Xor, | ||
const APInt & | C | ||
) |
For power-of-2 C: ((X s>> ShiftC) ^ X) u< C --> (X + C) u< (C << 1) ((X s>> ShiftC) ^ X) u> (C - 1) --> (X + C) u> ((C << 1) - 1)
Definition at line 1628 of file InstCombineCompares.cpp.
References llvm::Add, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateAdd(), llvm::APInt::getLimitedValue(), llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::APInt::isMinSignedValue(), llvm::APInt::isPowerOf2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and llvm::Xor.
Referenced by foldICmpXorConstant().
If an integer typed PHI has only one use which is an IntToPtr operation, replace the PHI with an existing pointer typed PHI if it exists.
Otherwise insert a new pointer typed PHI and replace the original one.
Definition at line 106 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::all_of(), llvm::any_of(), assert(), llvm::PHINode::blocks(), llvm::PHINode::Create(), llvm::CastInst::CreateBitOrPointerCast(), llvm::InstCombiner::DL, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::SmallVectorImpl< T >::emplace_back(), llvm::BasicBlock::end(), eraseInstFromFunction(), llvm::BasicBlock::getFirstInsertionPt(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getParent(), llvm::DataLayout::getPointerSizeInBits(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), llvm::Value::hasOneUse(), if(), llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), llvm::Type::isIntegerTy(), MaxNumPhis, Ptr, llvm::InstCombiner::replaceInstUsesWith(), llvm::SmallVectorBase< Size_T >::size(), llvm::Instruction::user_back(), llvm::Value::users(), and llvm::zip().
Referenced by visitPHINode().
Instruction * InstCombinerImpl::foldIRemByPowerOfTwoToBitTest | ( | ICmpInst & | I | ) |
If we have: icmp eq/ne (urem/srem x, y), 0 iff y is a power-of-two, we can replace this with a bit test: icmp eq/ne (and x, (add y, -1)), 0.
Definition at line 1152 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::CmpInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::Constant::getAllOnesValue(), I, llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_IRem(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::Masked, llvm::PatternMatch::match(), X, and Y.
Referenced by foldICmpWithZero().
Instruction * InstCombinerImpl::foldItoFPtoI | ( | CastInst & | FI | ) |
fpto{s/u}i({u/s}itofp(X)) --> X or zext(X) or sext(X) or trunc(X) This is safe if the intermediate type has enough bits in its mantissa to accurately represent all values of X.
For example, this won't work with i64 -> float -> i64.
Definition at line 1914 of file InstCombineCasts.cpp.
References assert(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), isKnownExactCastIntToFP(), llvm::InstCombiner::replaceInstUsesWith(), and X.
Referenced by visitFPToSI(), and visitFPToUI().
Fold (-1 u/ x) u< y ((x * y) ?/ x) != y to @llvm.
?mul.with.overflow(x, y) plus extraction of overflow bit Note that the comparison is commutative, while inverted (u>=, ==) predicate will mean that we are looking for the opposite answer.
Definition at line 4729 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateExtractValue(), llvm::IRBuilderBase::CreateNot(), eraseInstFromFunction(), F, llvm::Intrinsic::getDeclaration(), llvm::Instruction::getOpcode(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_IDiv(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Mul, llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), X, and Y.
Referenced by foldICmpBinOp().
Instruction * InstCombinerImpl::foldOpIntoPhi | ( | Instruction & | I, |
PHINode * | PN | ||
) |
Given a binary operator, cast instruction, or select which has a PHI node as operand #0, see if we can fold the instruction into the PHI (which is only possible if all operands to the PHI are constants).
Definition at line 1770 of file InstructionCombining.cpp.
References llvm::PHINode::addIncoming(), llvm::PHINode::Create(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, eraseInstFromFunction(), llvm::Instruction::getDebugLoc(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::PHINode::getNumIncomingValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::hasOneUse(), I, llvm::InstCombiner::InsertNewInstBefore(), llvm::isPotentiallyReachable(), llvm::DominatorTree::isReachableFromEntry(), llvm::BranchInst::isUnconditional(), llvm::InstCombiner::LI, llvm::make_early_inc_range(), llvm::User::operands(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::replaceAllDbgUsesWith(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setDebugLoc(), simplifyInstructionWithPHI(), llvm::InstCombiner::SQ, llvm::Value::takeName(), and llvm::Value::users().
Referenced by commonCastTransforms(), commonIRemTransforms(), foldBinOpIntoSelectOrPhi(), foldICmpInstWithConstantNotInt(), visitExtractValueInst(), visitFCmpInst(), visitFreeze(), and visitSub().
Instruction * InstCombinerImpl::FoldOpIntoSelect | ( | Instruction & | Op, |
SelectInst * | SI, | ||
bool | FoldWithMultiUse = false |
||
) |
Given an instruction with a select as one operand and a constant as the other operand, try to fold the binary operator into the select arguments.
This also works for Cast instructions, which obviously do not have a second operand.
Definition at line 1685 of file InstructionCombining.cpp.
References constantFoldOperationIntoSelectOperand(), llvm::SelectInst::Create(), and foldOperationIntoSelectOperand().
Referenced by commonCastTransforms(), commonIDivTransforms(), commonIRemTransforms(), commonShiftTransforms(), foldBinOpIntoSelectOrPhi(), visitCallInst(), visitExtractElementInst(), visitExtractValueInst(), visitFCmpInst(), visitFDiv(), visitFSub(), and visitSub().
Instruction * InstCombinerImpl::foldPHIArgBinOpIntoPHI | ( | PHINode & | PN | ) |
If we have something like phi [add (a,b), add(a,c)] and if a/b/c and the adds all have a single user, turn this into a phi and a single binop.
Definition at line 411 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::Instruction::andIRFlags(), assert(), llvm::PHINode::blocks(), llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::CmpInst::Create(), llvm::PHINode::Create(), llvm::drop_begin(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::BinaryOperator::getOpcode(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), I, llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), PHIArgMergedDebugLoc(), and llvm::zip().
Referenced by foldPHIArgOpIntoPHI().
Instruction * InstCombinerImpl::foldPHIArgExtractValueInstructionIntoPHI | ( | PHINode & | PN | ) |
If we have something like phi [extractvalue(a,0), extractvalue(b,0)], turn this into a phi[a,b] and a single extractvalue.
Definition at line 375 of file InstCombinePHI.cpp.
References llvm::PHINode::blocks(), llvm::PHINode::Create(), llvm::ExtractValueInst::Create(), llvm::drop_begin(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), I, llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), PHIArgMergedDebugLoc(), and llvm::zip().
Referenced by foldPHIArgOpIntoPHI().
Instruction * InstCombinerImpl::foldPHIArgGEPIntoPHI | ( | PHINode & | PN | ) |
Definition at line 506 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::GEPNoWrapFlags::all(), llvm::sampleprof::Base, llvm::PHINode::blocks(), llvm::GetElementPtrInst::Create(), llvm::PHINode::Create(), llvm::drop_begin(), GEP, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::GetElementPtrInst::getSourceElementType(), llvm::Value::getType(), I, llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), llvm::User::op_begin(), llvm::User::op_end(), PHIArgMergedDebugLoc(), llvm::SmallVectorBase< Size_T >::size(), and llvm::zip().
Referenced by foldPHIArgOpIntoPHI().
Instruction * InstCombinerImpl::foldPHIArgInsertValueInstructionIntoPHI | ( | PHINode & | PN | ) |
If we have something like phi [insertvalue(a,b,0), insertvalue(c,d,0)], turn this into a phi[a,c] and phi[b,d] and a single insertvalue.
Definition at line 335 of file InstCombinePHI.cpp.
References llvm::PHINode::blocks(), llvm::PHINode::Create(), llvm::InsertValueInst::Create(), llvm::drop_begin(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), I, llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), PHIArgMergedDebugLoc(), and llvm::zip().
Referenced by foldPHIArgOpIntoPHI().
Instruction * InstCombinerImpl::foldPHIArgIntToPtrToPHI | ( | PHINode & | PN | ) |
Definition at line 311 of file InstCombinePHI.cpp.
References llvm::all_of(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::InstCombiner::replaceOperand(), and llvm::Value::users().
Referenced by visitPHINode().
Instruction * InstCombinerImpl::foldPHIArgLoadIntoPHI | ( | PHINode & | PN | ) |
Definition at line 668 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::PHINode::blocks(), llvm::combineMetadata(), llvm::PHINode::Create(), llvm::drop_begin(), llvm::LoadInst::getAlign(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getMetadata(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::LoadInst::getPointerAddressSpace(), llvm::Value::getType(), llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), llvm::Instruction::isAtomic(), isSafeAndProfitableToSinkLoad(), llvm::Value::isSwiftError(), llvm::LoadInst::isVolatile(), llvm::InstCombiner::LI, PHIArgMergedDebugLoc(), llvm::Instruction::setMetadata(), llvm::User::setOperand(), and llvm::zip().
Referenced by foldPHIArgOpIntoPHI().
Instruction * InstCombinerImpl::foldPHIArgOpIntoPHI | ( | PHINode & | PN | ) |
Try to rotate an operation below a PHI node, using PHI nodes for its operands.
If all operands to a PHI node are the same "unary" operator and they all are only used by the PHI, PHI together their inputs, and do the operation once, to the result of the PHI.
Definition at line 866 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::PHINode::blocks(), llvm::BinaryOperator::Create(), llvm::CastInst::Create(), llvm::CmpInst::Create(), llvm::PHINode::Create(), llvm::drop_begin(), foldPHIArgBinOpIntoPHI(), foldPHIArgExtractValueInstructionIntoPHI(), foldPHIArgGEPIntoPHI(), foldPHIArgInsertValueInstructionIntoPHI(), foldPHIArgLoadIntoPHI(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::CmpInst::getOpcode(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), I, llvm::PHINode::incoming_values(), llvm::InstCombiner::InsertNewInstBefore(), llvm::Type::isIntegerTy(), PHIArgMergedDebugLoc(), and llvm::zip().
Referenced by visitPHINode().
Instruction * InstCombinerImpl::foldPHIArgZextsIntoPHI | ( | PHINode & | Phi | ) |
TODO: This function could handle other cast types, but then it might require special-casing a cast from the 'i1' type.
See the comment in FoldPHIArgOpIntoPHI() about pessimizing illegal integer types.
Definition at line 792 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::CallingConv::C, llvm::PHINode::Create(), llvm::CastInst::CreateZExtOrBitCast(), getLosslessUnsignedTrunc(), I, llvm::InstCombiner::InsertNewInstBefore(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by visitPHINode().
Instruction * InstCombinerImpl::foldPowiReassoc | ( | BinaryOperator & | I | ) |
Definition at line 604 of file InstCombineMulDivRem.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateAdd(), llvm::BinaryOperator::CreateFDivFMF(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::Constant::getAllOnesValue(), llvm::Value::getType(), I, llvm::PatternMatch::m_AllowReassoc(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), X, and Y.
Referenced by foldFMulReassoc(), and visitFDiv().
Instruction * llvm::InstCombinerImpl::foldSelectExtConst | ( | SelectInst & | Sel | ) |
Instruction * InstCombinerImpl::foldSelectICmp | ( | ICmpInst::Predicate | Pred, |
SelectInst * | SI, | ||
Value * | RHS, | ||
const ICmpInst & | I | ||
) |
Definition at line 4189 of file InstCombineCompares.cpp.
References llvm::InstCombiner::Builder, llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateICmp(), llvm::InstCombiner::DL, I, llvm::isImpliedCondition(), llvm::ConstantInt::isZero(), replacedSelectWithOperand(), RHS, llvm::simplifyICmpInst(), and llvm::InstCombiner::SQ.
Referenced by foldICmpCommutative().
Instruction * llvm::InstCombinerImpl::foldSelectInstWithICmp | ( | SelectInst & | SI, |
ICmpInst * | ICI | ||
) |
Instruction * InstCombinerImpl::foldSelectIntoOp | ( | SelectInst & | SI, |
Value * | TrueVal, | ||
Value * | FalseVal | ||
) |
Try to fold the select into one of the operands to allow further optimization.
Definition at line 508 of file InstCombineSelect.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, computeKnownFPClass(), llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateSelect(), llvm::fcNan, llvm::ConstantExpr::getBinOpIdentity(), getSelectFoldableOperands(), llvm::isKnownNeverNaN(), isSelect01(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::FastMathFlags::noSignedZeros(), and llvm::Value::takeName().
Instruction * llvm::InstCombinerImpl::foldSelectOfBools | ( | SelectInst & | SI | ) |
Instruction * InstCombinerImpl::foldSelectOpOp | ( | SelectInst & | SI, |
Instruction * | TI, | ||
Instruction * | FI | ||
) |
We have (select c, TI, FI), and we know that TI and FI have the same opcode.
Definition at line 269 of file InstCombineSelect.cpp.
References llvm::Instruction::andIRFlags(), assert(), llvm::InstCombiner::Builder, Cond, llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::CastInst::Create(), llvm::GetElementPtrInst::Create(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateSelect(), llvm::FPMathOperator::getFastMathFlags(), llvm::Instruction::getFastMathFlags(), llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), llvm::HexagonInstrInfo::getType(), llvm::Value::hasOneUse(), llvm::Instruction::isCast(), llvm::Instruction::isCommutative(), llvm::ICmpInst::isEquality(), llvm::isGuaranteedNotToBePoison(), llvm::Instruction::isSameOperationAs(), llvm::Type::isVectorTy(), llvm_unreachable, llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_MaxOrMin(), llvm::PatternMatch::m_SMax(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_UMax(), llvm::PatternMatch::m_UMin(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setFastMathFlags(), TII, X, and Y.
Instruction * InstCombinerImpl::foldSelectShuffle | ( | ShuffleVectorInst & | Shuf | ) |
Try to fold shuffles that are the equivalent of a vector select.
Definition at line 2247 of file InstCombineVectorOps.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::ShuffleVectorInst::commute(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::InstCombiner::DL, foldSelectShuffleOfSelectShuffle(), foldSelectShuffleWith1Binop(), getAlternateBinop(), llvm::ShuffleVectorInst::getMaskValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::InstCombiner::getSafeVectorConstantForBinop(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ConstantExpr::getShuffleVector(), llvm::InstCombiner::getSimplifyQuery(), llvm::ShuffleVectorInst::getType(), llvm::Value::hasOneUse(), I, llvm::is_contained(), llvm::Instruction::isIntDivRem(), llvm::ShuffleVectorInst::isSelect(), llvm::Instruction::isShift(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, llvm::InstCombiner::replaceInstUsesWith(), X, and Y.
Referenced by visitShuffleVectorInst().
Instruction * llvm::InstCombinerImpl::foldSelectToCmp | ( | SelectInst & | SI | ) |
Instruction * llvm::InstCombinerImpl::foldSelectValueEquivalence | ( | SelectInst & | SI, |
ICmpInst & | ICI | ||
) |
Instruction * InstCombinerImpl::FoldShiftByConstant | ( | Value * | Op0, |
Constant * | Op1, | ||
BinaryOperator & | I | ||
) |
Definition at line 782 of file InstCombineShifts.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, canEvaluateShifted(), canShiftBinOpWithConstantRHS(), Cond, llvm::BinaryOperator::Create(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateICmp(), llvm::dbgs(), llvm::InstCombiner::DL, foldBinOpIntoSelectOrPhi(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), getShiftedValue(), llvm::APInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLE, llvm::Instruction::isExact(), llvm::APInt::isMinSignedValue(), llvm::APInt::isNegative(), llvm::APInt::isZero(), LLVM_DEBUG, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Value::takeName(), llvm::APInt::uge(), and X.
Referenced by commonShiftTransforms().
Instruction * InstCombinerImpl::foldSignBitTest | ( | ICmpInst & | I | ) |
Fold equality-comparison between zero and any (maybe truncated) right-shift by one-less-than-bitwidth into a sign test on the original value.
Definition at line 1171 of file InstCombineCompares.cpp.
References llvm::CallingConv::C, llvm::CmpInst::Create(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLT, llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_TruncOrSelf(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), reassociateShiftAmtsOfTwoSameDirectionShifts(), llvm::InstCombiner::SQ, and X.
Referenced by visitICmpInst().
Instruction * llvm::InstCombinerImpl::foldSPFofSPF | ( | Instruction * | Inner, |
SelectPatternFlavor | SPF1, | ||
Value * | A, | ||
Value * | B, | ||
Instruction & | Outer, | ||
SelectPatternFlavor | SPF2, | ||
Value * | C | ||
) |
Instruction * InstCombinerImpl::foldSquareSumFP | ( | BinaryOperator & | I | ) |
Definition at line 1063 of file InstCombineAddSub.cpp.
References A, assert(), B, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateFAddFMF(), llvm::BinaryOperator::CreateFMulFMF(), I, and llvm::PatternMatch::m_SpecificFP().
Referenced by visitFAdd().
Instruction * InstCombinerImpl::foldSquareSumInt | ( | BinaryOperator & | I | ) |
Definition at line 1052 of file InstCombineAddSub.cpp.
References A, B, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateAdd(), I, and llvm::PatternMatch::m_SpecificInt().
Referenced by visitAdd().
Value * InstCombinerImpl::foldUsingDistributiveLaws | ( | BinaryOperator & | I | ) |
Tries to simplify binary operations which some other binary operation distributes over.
This tries to simplify binary operations which some other binary operation distributes over either by factorizing out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is a win).
It does this by either by factorizing out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is a win). Returns the simplified value, or null if it didn't simplify.
Returns the simplified value, or null if it didn't simplify.
Definition at line 1125 of file InstructionCombining.cpp.
References A, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateBinOp(), llvm::ConstantExpr::getBinOpIdentity(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::SimplifyQuery::getWithInstruction(), llvm::SimplifyQuery::getWithoutUndef(), I, leftDistributesOverRight(), LHS, RHS, rightDistributesOverLeft(), llvm::simplifyBinOp(), SimplifySelectsFeedingBinaryOp(), llvm::InstCombiner::SQ, and tryFactorizationFolds().
Referenced by visitAdd(), visitAnd(), visitMul(), visitOr(), visitSub(), and visitXor().
Instruction * InstCombinerImpl::foldVariableSignZeroExtensionOfVariableHighBitExtract | ( | BinaryOperator & | OldAShr | ) |
Definition at line 1614 of file InstCombineShifts.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::CastInst::CreateTruncOrBitCast(), llvm::BinaryOperator::getOpcode(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::IRBuilderBase::Insert(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_TruncOrSelf(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), and X.
Referenced by visitAShr().
Instruction * InstCombinerImpl::foldVectorBinop | ( | BinaryOperator & | Inst | ) |
Canonicalize the position of binops relative to shufflevector.
Definition at line 2011 of file InstructionCombining.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::InstCombiner::DL, F, llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::InstCombiner::getSafeVectorConstantForBinop(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::Value::hasNUses(), llvm::Value::hasOneUse(), I, llvm::is_contained(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), llvm::Instruction::isIntDivRem(), llvm::isSafeToSpeculativelyExecute(), llvm::Instruction::isShift(), llvm::isSplatValue(), LHS, llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VecReverse(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, RHS, llvm::ArrayRef< T >::size(), std::swap(), X, and Y.
Referenced by visitAdd(), visitAnd(), visitAShr(), visitFAdd(), visitFDiv(), visitFMul(), visitFRem(), visitFSub(), visitLShr(), visitMul(), visitOr(), visitSDiv(), visitShl(), visitSRem(), visitSub(), visitUDiv(), visitURem(), and visitXor().
Instruction * llvm::InstCombinerImpl::foldVectorSelect | ( | SelectInst & | Sel | ) |
Freely adapt every user of V as-if V was changed to !V.
WARNING: only if canFreelyInvertAllUsersOf() said this can be done.
Definition at line 1361 of file InstructionCombining.cpp.
References llvm::InstCombiner::addToWorklist(), assert(), llvm::InstCombiner::BPI, getOpcode(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), I, llvm_unreachable, llvm::make_early_inc_range(), llvm::InstCombiner::replaceInstUsesWith(), llvm::BranchProbabilityInfo::swapSuccEdgesProbabilities(), and llvm::BranchInst::swapSuccessors().
Referenced by canonicalizeICmpPredicate(), freelyInvert(), sinkNotIntoLogicalOp(), and sinkNotIntoOtherHandOfLogicalOp().
bool InstCombinerImpl::freezeOtherUses | ( | FreezeInst & | FI | ) |
Definition at line 4553 of file InstructionCombining.cpp.
References llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::Function::getEntryBlock(), llvm::BasicBlock::getFirstNonPHIOrDbgOrAlloca(), llvm::Instruction::getFunction(), llvm::User::getOperand(), and llvm::Instruction::moveBefore().
Referenced by visitFreeze().
Definition at line 235 of file InstCombineInternal.h.
References C.
Referenced by foldLogicCastConstant(), and visitCallInst().
|
inline |
Definition at line 222 of file InstCombineInternal.h.
References C, llvm::ConstantFoldCastOperand(), and DL.
Referenced by foldICmpWithZextOrSext().
Definition at line 231 of file InstCombineInternal.h.
References C.
Referenced by foldLogicCastConstant(), foldPHIArgZextsIntoPHI(), narrowUDivURem(), and visitCallInst().
void InstCombinerImpl::handlePotentiallyDeadBlocks | ( | SmallVectorImpl< BasicBlock * > & | Worklist | ) |
Definition at line 3622 of file InstructionCombining.cpp.
References llvm::all_of(), llvm::InstCombiner::DeadEdges, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::BasicBlock::front(), handleUnreachableFrom(), llvm::predecessors(), and llvm::InstCombiner::Worklist.
Referenced by handlePotentiallyDeadSuccessors(), and visitStoreInst().
void InstCombinerImpl::handlePotentiallyDeadSuccessors | ( | BasicBlock * | BB, |
BasicBlock * | LiveSucc | ||
) |
Definition at line 3635 of file InstructionCombining.cpp.
References addDeadEdge(), handlePotentiallyDeadBlocks(), llvm::successors(), and llvm::InstCombiner::Worklist.
Referenced by visitBranchInst(), and visitSwitchInst().
void InstCombinerImpl::handleUnreachableFrom | ( | Instruction * | I, |
SmallVectorImpl< BasicBlock * > & | Worklist | ||
) |
Definition at line 3592 of file InstructionCombining.cpp.
References addDeadEdge(), llvm::InstCombiner::addToWorklist(), eraseInstFromFunction(), llvm::PoisonValue::get(), llvm::ilist_node_impl< OptionsT >::getReverseIterator(), llvm::BasicBlock::getTerminator(), llvm::handleUnreachableTerminator(), I, llvm::InstCombiner::MadeIRChange, llvm::make_early_inc_range(), llvm::make_range(), llvm::InstCombiner::replaceInstUsesWith(), llvm::successors(), and llvm::InstCombiner::Worklist.
Referenced by handlePotentiallyDeadBlocks(), and visitStoreInst().
Value * InstCombinerImpl::insertRangeTest | ( | Value * | V, |
const APInt & | Lo, | ||
const APInt & | Hi, | ||
bool | isSigned, | ||
bool | Inside | ||
) |
Emit a computation of: (V >= Lo && V < Hi) if Inside is true, otherwise (V < Lo || V >= Hi).
This method expects that Lo < Hi. IsSigned indicates whether to treat V, Lo, and Hi as signed or not.
Definition at line 52 of file InstCombineAndOrXor.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateSub(), llvm::ICmpInst::getSignedPredicate(), llvm::Hi, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULT, isSigned(), and llvm::Lo.
Referenced by foldICmpDivConstant().
Instruction * InstCombinerImpl::matchBSwapOrBitReverse | ( | Instruction & | I, |
bool | MatchBSwaps, | ||
bool | MatchBitReversals | ||
) |
Given an initial instruction, check to see if it is the root of a bswap/bitreverse idiom.
If so, return the equivalent bswap/bitreverse intrinsic.
Definition at line 2842 of file InstCombineAndOrXor.cpp.
References I, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::InstructionWorklist::push(), llvm::recognizeBSwapOrBitReverseIdiom(), llvm::Instruction::removeFromParent(), and llvm::InstCombiner::Worklist.
Referenced by visitCallInst(), and visitOr().
bool InstCombinerImpl::matchThreeWayIntCompare | ( | SelectInst * | SI, |
Value *& | LHS, | ||
Value *& | RHS, | ||
ConstantInt *& | Less, | ||
ConstantInt *& | Equal, | ||
ConstantInt *& | Greater | ||
) |
Match a select chain which produces one of three values based on whether the LHS is less than, equal to, or greater than RHS respectively.
Return true if we matched a three way compare idiom. The LHS, RHS, Less, Equal and Greater values are saved in the matching process and returned to the caller.
Definition at line 3165 of file InstCombineCompares.cpp.
References assert(), llvm::InstCombiner::getFlippedStrictnessPredicateAndConstant(), llvm::CmpInst::getSwappedPredicate(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::ICmpInst::isEquality(), llvm::Less, LHS, llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), RHS, and std::swap().
Referenced by foldICmpSelectConstant().
Try to transform: if () { *P = v1; } else { *P = v2 } or: *P = v1; if () { *P = v2; } into a phi node with a store in the successor.
Definition at line 1486 of file InstCombineLoadStoreAlloca.cpp.
References llvm::PHINode::addIncoming(), llvm::BasicBlock::begin(), llvm::InstCombiner::Builder, llvm::PHINode::Create(), llvm::IRBuilderBase::CreateBitOrPointerCast(), llvm::InstCombiner::DL, eraseInstFromFunction(), llvm::Instruction::getAAMetadata(), llvm::Instruction::getDebugLoc(), llvm::BasicBlock::getFirstInsertionPt(), llvm::DILocation::getMergedLocation(), llvm::BranchInst::getSuccessor(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::StoreInst::getValueOperand(), llvm::BasicBlock::hasNPredecessors(), I, llvm::InstCombiner::InsertNewInstBefore(), llvm::CastInst::isBitOrNoopPointerCastable(), llvm::BranchInst::isUnconditional(), llvm::AAMDNodes::merge(), llvm::Instruction::mergeDIAssignID(), llvm::pred_begin(), llvm::Instruction::setAAMetadata(), llvm::Instruction::setDebugLoc(), and llvm::IRBuilderBase::SetInsertPoint().
Referenced by visitUnconditionalBranchInst().
Value * InstCombinerImpl::OptimizePointerDifference | ( | Value * | LHS, |
Value * | RHS, | ||
Type * | Ty, | ||
bool | IsNUW | ||
) |
Optimize pointer differences into the same array into a size.
Consider: &A[10] - &A[0]: we should compile this to "10". LHS/RHS are the pointer operands to the ptrtoint instructions for the LHS/RHS of the subtract.
Definition at line 2007 of file InstCombineAddSub.cpp.
References llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateSub(), I, llvm::GEPOperator::isInBounds(), LHS, llvm::Offset, RHS, llvm::Value::stripPointerCasts(), and std::swap().
Referenced by visitSub().
void InstCombinerImpl::PHIArgMergedDebugLoc | ( | Instruction * | Inst, |
PHINode & | PN | ||
) |
Helper function for FoldPHIArgXIntoPHI() to set debug location for the folded operation.
The PHI arguments will be folded into a single operation with a PHI node as input.
The debug location of the single operation will be the merged locations of the original PHI node arguments.
Definition at line 43 of file InstCombinePHI.cpp.
References llvm::Instruction::applyMergedLocation(), assert(), llvm::drop_begin(), llvm::Instruction::getDebugLoc(), llvm::PHINode::getIncomingValue(), I, llvm::PHINode::incoming_values(), and llvm::Instruction::setDebugLoc().
Referenced by foldPHIArgBinOpIntoPHI(), foldPHIArgExtractValueInstructionIntoPHI(), foldPHIArgGEPIntoPHI(), foldPHIArgInsertValueInstructionIntoPHI(), foldPHIArgLoadIntoPHI(), and foldPHIArgOpIntoPHI().
bool InstCombinerImpl::prepareWorklist | ( | Function & | F, |
ReversePostOrderTraversal< BasicBlock * > & | RPOT | ||
) |
Perform early cleanup and prepare the InstCombine worklist.
Populate the IC worklist from a function, by walking it in reverse post-order and adding all reachable code to the worklist.
This has a couple of tricks to make the code faster and more powerful. In particular, we constant fold and DCE instructions as we go, to avoid adding them to the worklist (this significantly speeds up instcombine on code where many instructions are dead or constant). Additionally, if we find a branch whose condition is a known constant, we only visit the reachable successors.
Definition at line 5237 of file InstructionCombining.cpp.
References llvm::all_of(), AliasScopeTracker::analyse(), llvm::CallingConv::C, Cond, llvm::ConstantFoldConstant(), llvm::ConstantFoldInstruction(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::InstCombiner::DeadEdges, llvm::InstCombiner::DL, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, F, llvm::PoisonValue::get(), llvm::BasicBlock::getTerminator(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::BranchInst::isConditional(), llvm::BasicBlock::isEntryBlock(), llvm::isInstructionTriviallyDead(), AliasScopeTracker::isNoAliasScopeDeclDead(), LLVM_DEBUG, llvm::InstCombiner::MadeIRChange, llvm::make_early_inc_range(), llvm::predecessors(), llvm::InstructionWorklist::push(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::removeAllNonTerminatorAndEHPadInstructions(), llvm::InstructionWorklist::reserve(), llvm::reverse(), llvm::salvageDebugInfo(), llvm::SmallVectorBase< Size_T >::size(), llvm::successors(), llvm::InstCombiner::TLI, and llvm::InstCombiner::Worklist.
Referenced by combineInstructionsOverFunction().
Value * InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating | ( | FreezeInst & | FI | ) |
Definition at line 4425 of file InstructionCombining.cpp.
References llvm::InstCombiner::Builder, llvm::canCreateUndefOrPoison(), llvm::IRBuilderBase::CreateFreeze(), llvm::Value::getName(), llvm::User::getOperand(), llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::InstCombiner::replaceUse(), and llvm::IRBuilderBase::SetInsertPoint().
Referenced by visitFreeze().
Value * InstCombinerImpl::reassociateShiftAmtsOfTwoSameDirectionShifts | ( | BinaryOperator * | Sh0, |
const SimplifyQuery & | SQ, | ||
bool | AnalyzeForSignBitExtraction = false |
||
) |
Definition at line 58 of file InstCombineShifts.cpp.
References assert(), llvm::InstCombiner::Builder, canTryToConstantAddTwoShiftAmounts(), llvm::ConstantFoldCastOperand(), llvm::BinaryOperator::Create(), llvm::CastInst::Create(), llvm::SimplifyQuery::DL, llvm::BinaryOperator::getOpcode(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_ULT, llvm::IRBuilderBase::Insert(), llvm::Instruction::isExact(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shift(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::PatternMatch::match(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::Instruction::setIsExact(), llvm::simplifyAddInst(), llvm::InstCombiner::SQ, and X.
Referenced by commonShiftTransforms(), and foldSignBitTest().
bool InstCombinerImpl::removeInstructionsBeforeUnreachable | ( | Instruction & | I | ) |
Definition at line 3512 of file InstructionCombining.cpp.
References eraseInstFromFunction(), llvm::PoisonValue::get(), I, llvm::isGuaranteedToTransferExecutionToSuccessor(), and llvm::InstCombiner::replaceInstUsesWith().
Referenced by visitStoreInst(), and visitUnreachableInst().
bool InstCombinerImpl::replacedSelectWithOperand | ( | SelectInst * | SI, |
const ICmpInst * | Icmp, | ||
const unsigned | SIOpd | ||
) |
Try to replace select with select operand SIOpd in SI-ICmp sequence.
True when a select result is replaced by one of its operands in select-icmp sequence.
This will eventually result in the elimination of the select.
SI | Select instruction |
Icmp | Compare instruction |
SIOpd | Operand that replaces the select |
Notes:
Example:
entry: %4 = select i1 %3, C* %0, C* null %5 = icmp eq C* %4, null br i1 %5, label %9, label %7 ... ; <label>:7 ; preds = entry %8 = getelementptr inbounds C* %4, i64 0, i32 0 ...
can be transformed to
%5 = icmp eq C* %0, null %6 = select i1 %3, i1 %5, i1 true br i1 %6, label %9, label %7 ... ; <label>:7 ; preds = entry %8 = getelementptr inbounds C* %0, i64 0, i32 0 // replace by %0!
Similar when the first operand of the select is a constant or/and the compare is for not equal rather than equal.
NOTE: The function is only called when the select and compare constants are equal, the optimization can work only for EQ predicates. This is not a major restriction since a NE compare should be 'normalized' to an equal compare, which usually happens in the combiner and test case select-cmp-br.ll checks for it.
Definition at line 6466 of file InstCombineCompares.cpp.
References assert(), dominatesAllUses(), llvm::CmpInst::getPredicate(), llvm::BasicBlock::getSinglePredecessor(), llvm::CmpInst::ICMP_EQ, and isChainSelectCmpBranch().
Referenced by foldSelectICmp().
bool llvm::InstCombinerImpl::replaceInInstruction | ( | Value * | V, |
Value * | Old, | ||
Value * | New, | ||
unsigned | Depth = 0 |
||
) |
bool InstCombinerImpl::run | ( | ) |
Run the combiner over the entire worklist until it is empty.
Definition at line 5002 of file InstructionCombining.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CollectMetadataToCopy(), llvm::dbgs(), llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, EnableCodeSinking, eraseInstFromFunction(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getFirstNonPHIIt(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::getUniquePredecessor(), I, llvm::User::isDroppable(), llvm::InstructionWorklist::isEmpty(), llvm::isInstructionTriviallyDead(), llvm::DominatorTree::isReachableFromEntry(), LLVM_DEBUG, llvm::InstCombiner::MadeIRChange, MaxSinkNumUsers, llvm::InstructionWorklist::popDeferred(), llvm::InstructionWorklist::push(), llvm::InstructionWorklist::pushUsersToWorkList(), llvm::InstructionWorklist::removeOne(), llvm::IRBuilderBase::SetInsertPoint(), llvm::DebugCounter::shouldExecute(), llvm::succ_empty(), llvm::InstCombiner::TLI, tryToSinkInstruction(), llvm::InstVisitor< InstCombinerImpl, Instruction * >::visit(), llvm::InstCombiner::Worklist, and llvm::InstructionWorklist::zap().
Referenced by combineInstructionsOverFunction().
Value * InstCombinerImpl::SimplifyAddWithRemainder | ( | BinaryOperator & | I | ) |
Tries to simplify add operations using the definition of remainder.
The definition of remainder is X % C = X - (X / C ) * C. The add expression X % C0 + (( X / C0 ) % C1) * C0 can be simplified to X % (C0 * C1)
Definition at line 1150 of file InstCombineAddSub.cpp.
References llvm::InstCombiner::AC, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateMul(), llvm::IRBuilderBase::CreateSRem(), llvm::IRBuilderBase::CreateURem(), llvm::InstCombiner::DT, llvm::Value::hasOneUse(), I, llvm::isGuaranteedNotToBeUndef(), llvm::APInt::isZero(), LHS, llvm::PatternMatch::m_IRem(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), MatchDiv(), MatchMul(), MatchRem(), MulWillOverflow(), RHS, std::swap(), and X.
Referenced by visitAdd(), and visitOr().
Instruction * InstCombinerImpl::SimplifyAnyMemSet | ( | AnyMemSetInst * | MI | ) |
Definition at line 217 of file InstCombineCalls.cpp.
References llvm::InstCombiner::AA, llvm::InstCombiner::AC, assert(), llvm::InstCombiner::Builder, llvm::Instruction::copyMetadata(), llvm::IRBuilderBase::CreateStore(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, llvm::for_each(), llvm::at::getAssignmentMarkers(), llvm::at::getDVRAssignmentMarkers(), llvm::getKnownAlignment(), llvm::ConstantInt::getLimitedValue(), llvm::AAResults::getModRefInfoMask(), llvm::Constant::getNullValue(), llvm::APInt::getSplat(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::is_contained(), llvm::Type::isIntegerTy(), llvm::isModSet(), llvm::isPowerOf2_32(), MI, llvm::StoreInst::setAlignment(), llvm::StoreInst::setOrdering(), and llvm::Unordered.
Referenced by visitCallInst().
Instruction * InstCombinerImpl::SimplifyAnyMemTransfer | ( | AnyMemTransferInst * | MI | ) |
Definition at line 115 of file InstCombineCalls.cpp.
References llvm::InstCombiner::AA, llvm::InstCombiner::AC, assert(), llvm::InstCombiner::Builder, llvm::Instruction::copyMetadata(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::CreateStore(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, llvm::IntegerType::get(), llvm::getKnownAlignment(), llvm::ConstantInt::getLimitedValue(), llvm::AAResults::getModRefInfoMask(), llvm::Constant::getNullValue(), llvm::Value::getType(), hasUndefSource(), llvm::isModSet(), MI, llvm::Instruction::setAAMetadata(), llvm::StoreInst::setAlignment(), llvm::Instruction::setMetadata(), llvm::StoreInst::setOrdering(), llvm::StoreInst::setVolatile(), Size, and llvm::Unordered.
Referenced by visitCallInst().
bool InstCombinerImpl::SimplifyAssociativeOrCommutative | ( | BinaryOperator & | I | ) |
Performs a few simplifications for operators which are associative or commutative.
This performs a few simplifications for operators that are associative or commutative:
Commutative operators:
Associative operators:
Associative and commutative operators:
Definition at line 420 of file InstructionCombining.cpp.
References A, B, llvm::CallingConv::C, ClearSubclassDataAfterReassociation(), llvm::ConstantFoldBinaryOpOperands(), llvm::BinaryOperator::Create(), llvm::BinaryOperator::CreateNUW(), llvm::InstCombiner::DL, llvm::InstCombiner::getComplexity(), llvm::Instruction::getFastMathFlags(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::SimplifyQuery::getWithInstruction(), hasNoSignedWrap(), hasNoUnsignedWrap(), I, llvm::InstCombiner::InsertNewInstWith(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), maintainNoSignedWrap(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), llvm::Instruction::setFastMathFlags(), simplifyAssocCastAssoc(), llvm::simplifyBinOp(), llvm::InstCombiner::SQ, and llvm::Value::takeName().
Referenced by visitAdd(), visitAnd(), visitFAdd(), visitFMul(), visitMul(), visitOr(), and visitXor().
Instruction * InstCombinerImpl::simplifyBinOpSplats | ( | ShuffleVectorInst & | SVI | ) |
Definition at line 2764 of file InstCombineVectorOps.cpp.
References llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateBinOp(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::Value::hasOneUse(), llvm::isSafeToSpeculativelyExecute(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
Referenced by visitShuffleVectorInst().
|
overridevirtual |
This form of SimplifyDemandedBits simplifies the specified instruction operand if possible, updating it in place.
It returns true if it made any change and false otherwise.
Implements llvm::InstCombiner.
Definition at line 89 of file InstCombineSimplifyDemanded.cpp.
References llvm::computeKnownBits(), llvm::Depth, llvm::UndefValue::get(), llvm::Value::hasOneUse(), I, llvm::APInt::isZero(), llvm::MaxAnalysisRecursionDepth, llvm::InstCombiner::replaceUse(), llvm::KnownBits::resetAll(), llvm::salvageDebugInfo(), SimplifyDemandedUseBits(), and SimplifyMultipleUseDemandedBits().
Referenced by foldICmpUsingKnownBits(), SimplifyDemandedUseBits(), and visitCallInst().
|
inline |
Definition at line 506 of file InstCombiner.h.
|
virtual |
Implements llvm::InstCombiner.
bool InstCombinerImpl::SimplifyDemandedFPClass | ( | Instruction * | I, |
unsigned | Op, | ||
FPClassTest | DemandedMask, | ||
KnownFPClass & | Known, | ||
unsigned | Depth = 0 |
||
) |
Definition at line 2051 of file InstCombineSimplifyDemanded.cpp.
References llvm::Depth, I, llvm::InstCombiner::replaceUse(), llvm::salvageDebugInfo(), and SimplifyDemandedUseFPClass().
Referenced by SimplifyDemandedUseFPClass().
bool InstCombinerImpl::SimplifyDemandedInstructionBits | ( | Instruction & | Inst | ) |
Tries to simplify operands to an integer instruction based on its demanded bits.
Inst is an integer instruction that SimplifyDemandedBits knows about.
See if the instruction has any properties that allow us to simplify its operands.
Definition at line 81 of file InstCombineSimplifyDemanded.cpp.
References llvm::InstCombiner::DL, getBitWidth(), llvm::Value::getType(), and SimplifyDemandedInstructionBits().
Referenced by commonIDivTransforms(), commonIRemTransforms(), commonShiftTransforms(), SimplifyDemandedInstructionBits(), visitAnd(), visitCallInst(), visitOr(), visitTrunc(), and visitXor().
bool InstCombinerImpl::SimplifyDemandedInstructionBits | ( | Instruction & | Inst, |
KnownBits & | Known | ||
) |
Inst is an integer instruction that SimplifyDemandedBits knows about.
See if the instruction has any properties that allow us to simplify its operands.
Definition at line 68 of file InstCombineSimplifyDemanded.cpp.
References llvm::APInt::getAllOnes(), llvm::KnownBits::getBitWidth(), llvm::SimplifyQuery::getWithInstruction(), llvm::InstCombiner::replaceInstUsesWith(), SimplifyDemandedUseBits(), and llvm::InstCombiner::SQ.
Value * InstCombinerImpl::SimplifyDemandedUseBits | ( | Instruction * | I, |
const APInt & | DemandedMask, | ||
KnownBits & | Known, | ||
unsigned | Depth, | ||
const SimplifyQuery & | Q | ||
) |
Attempts to replace I with a simpler value based on the demanded bits.
This function attempts to replace V with a simpler value based on the demanded bits.
When this function is called, it is known that only the bits set in DemandedMask of the result of V are ever used downstream. Consequently, depending on the mask and V, it may be possible to replace V with a constant or one of its operands. In such cases, this function does the replacement and returns true. In all other cases, it returns false after analyzing the expression and setting KnownOne and known to be one in the expression. Known.Zero contains all the bits that are known to be zero in the expression. These are provided to potentially allow the caller (which might recursively be SimplifyDemandedBits itself) to simplify the expression. Known.One and Known.Zero always follow the invariant that: Known.One & Known.Zero == 0. That is, a bit can't be both 1 and 0. The bits in Known.One and Known.Zero are accurate even for bits not in DemandedMask. Note also that the bitwidth of V, DemandedMask, Known.Zero and Known.One must all be the same.
This returns null if it did not change anything and it permits no simplification. This returns V itself if it did some simplification of V's operands based on the information about what bits are demanded. This returns some other non-null value if it found out that V is equal to another value in the context where the specified bits are demanded, but not for all users.
Definition at line 157 of file InstCombineSimplifyDemanded.cpp.
References llvm::APInt::abs(), llvm::KnownBits::add(), llvm::adjustKnownBitsForSelectArm(), llvm::alignDown(), llvm::analyzeKnownBitsFromAndXorOr(), llvm::And, llvm::KnownBits::anyextOrTrunc(), llvm::KnownBits::ashr(), assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APInt::clearLowBits(), llvm::computeKnownBits(), llvm::InstCombiner::computeKnownBits(), llvm::InstCombiner::ComputeNumSignBits(), llvm::ConstantFoldBinaryOpOperands(), convertOrOfShiftsToFunnelShift(), llvm::APInt::countl_zero(), llvm::countr_one(), llvm::APInt::countr_zero(), llvm::CallInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateGEP(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateSExt(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::IRBuilderBase::CreateXor(), llvm::SimplifyQuery::CxtI, llvm::Depth, llvm::InstCombiner::DL, llvm::errs(), GEP, llvm::APInt::getActiveBits(), llvm::Constant::getAllOnesValue(), llvm::APInt::getBitWidth(), llvm::KnownBits::getBitWidth(), llvm::Intrinsic::getDeclaration(), llvm::APInt::getHighBitsSet(), llvm::DataLayout::getIndexType(), llvm::Constant::getIntegerValue(), llvm::APInt::getLimitedValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignMask(), llvm::ConstantInt::getValue(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), llvm::haveNoCommonBitsSet(), I, II, llvm::InstCombiner::InsertNewInstWith(), llvm::APInt::intersects(), llvm::KnownBits::intersectWith(), llvm::APInt::isAllOnes(), llvm::Type::isIntOrIntVectorTy(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm::APInt::isOne(), llvm::APInt::isPowerOf2(), llvm::APInt::isSubsetOf(), LHS, llvm::Log2(), llvm::APInt::lshr(), llvm::APInt::lshrInPlace(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PtrAdd(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::KnownBits::makeConstant(), llvm::KnownBits::makeNonNegative(), llvm::PatternMatch::match(), llvm::MaxAnalysisRecursionDepth, llvm::KnownBits::One, llvm::Or, RA, llvm::InstCombiner::replaceOperand(), RHS, llvm::APInt::setBit(), llvm::APInt::setHighBits(), llvm::IRBuilderBase::SetInsertPoint(), llvm::Instruction::setIsExact(), llvm::APInt::setLowBits(), llvm::APInt::setSignBit(), llvm::KnownBits::sext(), llvm::KnownBits::shl(), llvm::APInt::shl(), ShrinkDemandedConstant(), SimplifyDemandedBits(), simplifyShrShlDemandedBits(), llvm::KnownBits::sub(), llvm::Value::takeName(), llvm::InstCombiner::targetSimplifyDemandedUseBitsIntrinsic(), llvm::APInt::trunc(), llvm::KnownBits::udiv(), llvm::APInt::ult(), llvm::APInt::urem(), VerifyKnownBits, X, llvm::Xor, Y, llvm::KnownBits::Zero, llvm::KnownBits::zextOrTrunc(), and llvm::APInt::zextOrTrunc().
Referenced by SimplifyDemandedBits(), and SimplifyDemandedInstructionBits().
Value * InstCombinerImpl::SimplifyDemandedUseFPClass | ( | Value * | V, |
FPClassTest | DemandedMask, | ||
KnownFPClass & | Known, | ||
unsigned | Depth, | ||
Instruction * | CxtI | ||
) |
Attempts to replace V with a simpler value based on the demanded floating-point classes.
Definition at line 1950 of file InstCombineSimplifyDemanded.cpp.
References assert(), computeKnownFPClass(), llvm::KnownFPClass::copysign(), llvm::Depth, llvm::KnownFPClass::fabs(), llvm::fcAllFlags, llvm::fcNegative, llvm::fcNone, llvm::fcPositive, llvm::KnownFPClass::fneg(), llvm::fneg(), llvm::PoisonValue::get(), getFPClassConstant(), llvm::CallBase::getIntrinsicID(), llvm::ConstantFP::getZero(), I, llvm::inverse_fabs(), llvm::KnownFPClass::isKnownNever(), llvm::KnownFPClass::KnownFPClasses, llvm::MaxAnalysisRecursionDepth, SimplifyDemandedFPClass(), and llvm::unknown_sign().
Referenced by SimplifyDemandedFPClass(), and visitReturnInst().
|
overridevirtual |
The specified value produces a vector with any number of elements.
This method analyzes which elements of the operand are poison and returns that information in PoisonElts.
DemandedElts contains the set of elements that are actually used by the caller, and by default (AllowMultipleUsers equals false) the value is simplified only if it has a single caller. If AllowMultipleUsers is set to true, DemandedElts refers to the union of sets of elements that are used by all callers.
If the information about demanded elements can be used to simplify the operation, the operation is simplified, then the resultant value is returned. This returns null if no change was made.
Implements llvm::InstCombiner.
Definition at line 1390 of file InstCombineSimplifyDemanded.cpp.
References llvm::all_of(), assert(), llvm::CallingConv::C, llvm::APInt::clearAllBits(), llvm::APInt::clearBit(), llvm::InsertElementInst::Create(), llvm::Depth, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, GEP, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::APInt::getAllOnes(), llvm::SelectInst::getCondition(), llvm::Type::getInt64Ty(), llvm::Value::getName(), getNumElements(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, Idx, II, llvm::InstCombiner::InsertNewInstWith(), llvm::APInt::isAllOnes(), llvm::Constant::isAllOnesValue(), llvm::Instruction::isCommutative(), llvm::Instruction::isIntDivRem(), llvm::Constant::isNullValue(), llvm::Constant::isOneValue(), llvm::Instruction::isShift(), llvm::Type::isVectorTy(), llvm::APInt::isZero(), llvm_unreachable, llvm::APInt::lshr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_ExtractElt(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Poison, llvm::PoisonMaskElem, llvm::APInt::popcount(), llvm::InstructionWorklist::push(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceOperand(), llvm::APInt::setBit(), SimplifyDemandedVectorElts(), llvm::InstCombiner::targetSimplifyDemandedVectorEltsIntrinsic(), llvm::Value::users(), llvm::InstCombiner::Worklist, X, Y, and llvm::APInt::zextOrTrunc().
Referenced by SimplifyDemandedVectorElts(), visitCallInst(), visitExtractElementInst(), visitGetElementPtrInst(), visitInsertElementInst(), and visitShuffleVectorInst().
bool InstCombinerImpl::simplifyDivRemOfSelectWithZeroOp | ( | BinaryOperator & | I | ) |
Fold a divide or remainder with a select instruction divisor when one of the select operands is zero.
In that case, we can use the other select operand because div/rem by zero is undefined.
Definition at line 985 of file InstCombineMulDivRem.cpp.
References llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::isGuaranteedToTransferExecutionToSuccessor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::InstructionWorklist::push(), llvm::InstCombiner::replaceOperand(), llvm::InstCombiner::replaceUse(), and llvm::InstCombiner::Worklist.
Referenced by commonIDivTransforms(), and commonIRemTransforms().
Value * InstCombinerImpl::SimplifyMultipleUseDemandedBits | ( | Instruction * | I, |
const APInt & | DemandedMask, | ||
KnownBits & | Known, | ||
unsigned | Depth, | ||
const SimplifyQuery & | Q | ||
) |
Helper routine of SimplifyDemandedUseBits.
It computes KnownZero/KnownOne bits. It also tries to handle simplifications that can be done based on DemandedMask, but without modifying the Instruction.
It computes Known bits. It also tries to handle simplifications that can be done based on DemandedMask, but without modifying the Instruction.
Definition at line 1139 of file InstCombineSimplifyDemanded.cpp.
References llvm::KnownBits::add(), llvm::analyzeKnownBitsFromAndXorOr(), llvm::BitWidth, llvm::computeKnownBits(), llvm::computeKnownBitsFromContext(), llvm::APInt::countl_zero(), llvm::Depth, llvm::APInt::getBitWidth(), llvm::Constant::getIntegerValue(), llvm::APInt::getLowBitsSet(), llvm::APInt::getZExtValue(), I, llvm::APInt::isSubsetOf(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::KnownBits::One, llvm::KnownBits::sub(), llvm::APInt::ult(), X, and llvm::KnownBits::Zero.
Referenced by SimplifyDemandedBits().
Try to fold a signed range checked with lower bound 0 to an unsigned icmp.
Example: (icmp sge x, 0) & (icmp slt x, n) --> icmp ult x, n If Inverted
is true then the check is for the inverted range, e.g. (icmp slt x, 0) | (icmp sgt x, n) --> icmp ugt x, n
Definition at line 671 of file InstCombineAndOrXor.cpp.
References llvm::InstCombiner::Builder, llvm::InstCombiner::computeKnownBits(), llvm::IRBuilderBase::CreateICmp(), llvm::CmpInst::getInversePredicate(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ConstantInt::isMinusOne(), llvm::KnownBits::isNonNegative(), and llvm::ConstantInt::isZero().
Value * InstCombinerImpl::SimplifySelectsFeedingBinaryOp | ( | BinaryOperator & | I, |
Value * | LHS, | ||
Value * | RHS | ||
) |
Definition at line 1281 of file InstructionCombining.cpp.
References A, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, Cond, llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateSub(), D, F, llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), I, LHS, llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), N, RHS, llvm::IRBuilderBase::setFastMathFlags(), llvm::simplifyBinOp(), and llvm::InstCombiner::SQ.
Referenced by foldUsingDistributiveLaws(), visitFAdd(), visitFMul(), and visitFSub().
Value * InstCombinerImpl::simplifyShrShlDemandedBits | ( | Instruction * | Shr, |
const APInt & | ShrOp1, | ||
Instruction * | Shl, | ||
const APInt & | ShlOp1, | ||
const APInt & | DemandedMask, | ||
KnownBits & | Known | ||
) |
Helper routine of SimplifyDemandedUseBits.
It tries to simplify demanded bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
It tries to simplify "E1 = (X lsr C1) << C2", where the C1 and C2 are constant, into "E2 = X << (C2 - C1)" or "E2 = X >> (C1 - C2)", depending on the sign of "C2-C1".
Suppose E1 and E2 are generally different in bits S={bm, bm+1, ..., bn}, without considering the specific value X is holding. This transformation is legal iff one of following conditions is hold: 1) All the bit in S are 0, in this case E1 == E2. 2) We don't care those bits in S, per the input DemandedMask. 3) Combination of 1) and 2). Some bits in S are 0, and we don't care the rest bits.
Currently we only test condition 2).
As with SimplifyDemandedUseBits, it returns NULL if the simplification was not successful.
Definition at line 1315 of file InstCombineSimplifyDemanded.cpp.
References llvm::APInt::ashr(), llvm::BitWidth, llvm::APInt::clearAllBits(), llvm::APInt::getAllOnes(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::APInt::getZExtValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::InstCombiner::InsertNewInstWith(), llvm::APInt::lshr(), llvm::KnownBits::One, llvm::APInt::setLowBits(), llvm::APInt::uge(), and llvm::KnownBits::Zero.
Referenced by SimplifyDemandedUseBits().
bool InstCombinerImpl::sinkNotIntoLogicalOp | ( | Instruction & | I | ) |
Definition at line 4369 of file InstCombineAndOrXor.cpp.
References llvm::InstCombiner::Builder, canFreelyInvert(), llvm::InstCombiner::canFreelyInvertAllUsersOf(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateLogicalOp(), freelyInvert(), freelyInvertAllUsersOf(), I, llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), and llvm::IRBuilderBase::SetInsertPoint().
bool InstCombinerImpl::sinkNotIntoOtherHandOfLogicalOp | ( | Instruction & | I | ) |
Definition at line 4415 of file InstCombineAndOrXor.cpp.
References llvm::InstCombiner::Builder, canFreelyInvert(), llvm::InstCombiner::canFreelyInvertAllUsersOf(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateLogicalOp(), freelyInvert(), freelyInvertAllUsersOf(), I, llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOp(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), and llvm::IRBuilderBase::SetInsertPoint().
Referenced by visitAnd(), and visitOr().
Instruction * InstCombinerImpl::SliceUpIllegalIntegerPHI | ( | PHINode & | FirstPhi | ) |
This is an integer PHI and we know that it has an illegal type: see if it is only used by trunc or trunc(lshr) operations.
If so, we split the PHI into the various pieces being extracted. This sort of thing is introduced when SROA promotes an aggregate to large integer values.
TODO: The user of the trunc may be an bitcast to float/double/vector or an inttoptr. We should produce new PHIs in the right type.
Definition at line 1101 of file InstCombinePHI.cpp.
References llvm::PHINode::addIncoming(), llvm::array_pod_sort(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::PHINode::blocks(), llvm::InstCombiner::Builder, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::PHINode::Create(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateTrunc(), llvm::dbgs(), llvm::drop_begin(), llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::find(), llvm::PoisonValue::get(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, II, llvm::PHINode::incoming_values(), llvm::SmallPtrSetImpl< PtrType >::insert(), LLVM_DEBUG, llvm::Offset, PHI, Poison, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorBase< Size_T >::size(), llvm::Instruction::user_back(), llvm::Value::users(), and llvm::zip().
Value * InstCombinerImpl::tryFactorizationFolds | ( | BinaryOperator & | I | ) |
This tries to simplify binary operations by factorizing out common terms (e.
g. "(A*B)+(A*C)" -> "A*(B+C)").
Definition at line 1082 of file InstructionCombining.cpp.
References A, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, D, getBinOpsForFactorization(), getIdentityValue(), I, LHS, RHS, llvm::InstCombiner::SQ, and tryFactorization().
Referenced by foldUsingDistributiveLaws().
Instruction * InstCombinerImpl::tryFoldInstWithCtpopWithNot | ( | Instruction * | I | ) |
Definition at line 771 of file InstructionCombining.cpp.
References assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldCompareInstOperands(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateSub(), llvm::InstCombiner::DL, llvm::ConstantExpr::getAdd(), llvm::InstCombiner::getFreelyInverted(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), I, llvm::CmpInst::ICMP_UGT, llvm::InstCombiner::isFreeToInvert(), isSigned(), llvm_unreachable, llvm::PatternMatch::m_DisjointOr(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::InstCombiner::replaceInstUsesWith().
Referenced by foldICmpWithConstant(), visitAdd(), visitOr(), and visitSub().
bool InstCombinerImpl::tryToSinkInstruction | ( | Instruction * | I, |
BasicBlock * | DestBlock | ||
) |
Try to move the specified instruction from its current block into the beginning of DestBlock, which can only happen if it's safe to move the instruction past all of the instructions between it and the end of its block.
FIXME: We could remove droppable uses that are not dominated by the new position.
Definition at line 4726 of file InstructionCombining.cpp.
References llvm::InstructionWorklist::add(), llvm::SmallVectorBase< Size_T >::empty(), llvm::findDbgUsers(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::getUniquePredecessor(), I, SoleWriteToDeadLocal(), llvm::InstCombiner::TLI, tryToSinkInstructionDbgValues(), tryToSinkInstructionDbgVariableRecords(), and llvm::InstCombiner::Worklist.
Referenced by run().
void InstCombinerImpl::tryToSinkInstructionDbgValues | ( | Instruction * | I, |
BasicBlock::iterator | InsertPos, | ||
BasicBlock * | SrcBlock, | ||
BasicBlock * | DestBlock, | ||
SmallVectorImpl< DbgVariableIntrinsic * > & | DbgUsers | ||
) |
Definition at line 4815 of file InstructionCombining.cpp.
References A, B, llvm::dbgs(), I, llvm::SmallSet< T, N, C >::insert(), LLVM_DEBUG, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::reverse(), llvm::salvageDebugInfoForDbgValues(), and llvm::sort().
Referenced by tryToSinkInstruction().
void InstCombinerImpl::tryToSinkInstructionDbgVariableRecords | ( | Instruction * | I, |
BasicBlock::iterator | InsertPos, | ||
BasicBlock * | SrcBlock, | ||
BasicBlock * | DestBlock, | ||
SmallVectorImpl< DbgVariableRecord * > & | DPUsers | ||
) |
Definition at line 4874 of file InstructionCombining.cpp.
References A, assert(), B, llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::dbgs(), llvm::DbgVariableRecord::Declare, llvm::SmallVectorImpl< T >::emplace_back(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::SmallVectorBase< Size_T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::filterDbgVars(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), I, llvm::SmallSet< T, N, C >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), LLVM_DEBUG, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::reverse(), llvm::salvageDebugInfoForDbgValues(), llvm::SmallVectorBase< Size_T >::size(), and llvm::stable_sort().
Referenced by tryToSinkInstruction().
Instruction * InstCombinerImpl::visitAdd | ( | BinaryOperator & | I | ) |
Definition at line 1486 of file InstCombineAddSub.cpp.
References A, llvm::Add, llvm::InstCombiner::AddOne(), llvm::AllOnes, assert(), B, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(), canonicalizeLowbitMask(), checkForNegativeOperand(), combineAddSubWithShlAddSub(), llvm::InstCombiner::ComputeNumSignBits(), Cond, llvm::APInt::countl_zero(), llvm::APInt::countr_zero(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateXor(), llvm::IRBuilderBase::CreateZExt(), llvm::IRBuilderBase::CreateZExtOrTrunc(), factorizeMathWithShlOps(), foldAddToAshr(), foldAddWithConstant(), foldBinOpOfSelectAndCastOfSelectCondition(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBoxMultiply(), foldNoWrapAdd(), foldSquareSumInt(), foldToUnsignedSaturatedAdd(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::ConstantExpr::getAdd(), llvm::Constant::getAllOnesValue(), llvm::APInt::getBitWidth(), llvm::IRBuilderBase::getFalse(), llvm::InstCombiner::getFreelyInverted(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::ConstantInt::getSigned(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), llvm::haveNoCommonBitsSet(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_UGT, llvm::InstCombiner::isFreeToInvert(), llvm::Type::isIntOrIntVectorTy(), llvm::APInt::isPowerOf2(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificICmp(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_TruncOrSelf(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), RHS, llvm::simplifyAddInst(), SimplifyAddWithRemainder(), SimplifyAssociativeOrCommutative(), llvm::InstCombiner::SQ, llvm::InstCombiner::SubOne(), tryFoldInstWithCtpopWithNot(), and X.
Instruction * InstCombinerImpl::visitAddrSpaceCast | ( | AddrSpaceCastInst & | CI | ) |
Definition at line 2837 of file InstCombineCasts.cpp.
References commonCastTransforms().
Instruction * InstCombinerImpl::visitAllocaInst | ( | AllocaInst & | AI | ) |
Definition at line 459 of file InstCombineLoadStoreAlloca.cpp.
References llvm::InstCombiner::AA, llvm::InstCombiner::AC, llvm::dbgs(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, eraseInstFromFunction(), llvm::AllocaInst::getAddressSpace(), llvm::AllocaInst::getAlign(), llvm::AllocaInst::getAllocatedType(), llvm::AllocaInst::getArraySize(), llvm::BasicBlock::getFirstNonPHIOrDbg(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getKnownMinValue(), llvm::getOrEnforceKnownAlignment(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), I, llvm::AllocaInst::isArrayAllocation(), isDereferenceableForAllocaSize(), isOnlyCopiedFromConstantMemory(), llvm::Type::isSized(), LLVM_DEBUG, llvm::Instruction::moveBefore(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::AllocaInst::setAlignment(), simplifyAllocaArraySize(), and visitAllocSite().
Instruction * InstCombinerImpl::visitAllocSite | ( | Instruction & | FI | ) |
Definition at line 3236 of file InstructionCombining.cpp.
References llvm::InstCombiner::AA, llvm::InstructionWorklist::add(), assert(), llvm::CallingConv::C, llvm::ConvertDebugDeclareToDebugValue(), llvm::InvokeInst::Create(), llvm::InstCombiner::DL, eraseInstFromFunction(), F, llvm::findDbgUsers(), llvm::PoisonValue::get(), llvm::Intrinsic::getDeclaration(), llvm::Type::getInt1Ty(), I, II, isAllocSiteRemovable(), llvm::isRemovableAlloc(), llvm::lowerObjectSizeCall(), MI, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::TLI, Users, and llvm::InstCombiner::Worklist.
Referenced by visitAllocaInst().
Instruction * InstCombinerImpl::visitAnd | ( | BinaryOperator & | I | ) |
Definition at line 2318 of file InstCombineAndOrXor.cpp.
References A, llvm::And, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeLogicFirst(), llvm::InstCombiner::computeKnownBits(), llvm::ConstantFoldCompareInstOperands(), llvm::APInt::countr_zero(), llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateIsNeg(), llvm::IRBuilderBase::CreateIsNull(), llvm::IRBuilderBase::CreateLogicalAnd(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateSExt(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::InstCombiner::DL, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, llvm::APInt::exactLogBase2(), foldAndToXor(), foldBinOpIntoSelectOrPhi(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBitwiseLogicWithIntrinsics(), foldComplexAndOrPatterns(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::ConstantExpr::getAdd(), llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getExactLogBase2(), llvm::InstCombiner::getFreelyInverted(), llvm::IRBuilderBase::GetInsertBlock(), llvm::APInt::getLowBitsSet(), llvm::KnownBits::getMaxValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::BasicBlock::getParent(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::APInt::getZExtValue(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_ULT, llvm::Type::isFloatingPointTy(), llvm::Type::isIEEE(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::APInt::isPowerOf2(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalShift(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_MaxSignedValue(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_SExtOrSelf(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSelf(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), matchDeMorgansLaws(), llvm::matchSimpleRecurrence(), reassociateFCmps(), reassociateForUses(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::simplifyAndInst(), simplifyAndOrWithOpReplaced(), SimplifyAssociativeOrCommutative(), SimplifyDemandedInstructionBits(), sinkNotIntoOtherHandOfLogicalOp(), llvm::InstCombiner::SQ, llvm::APInt::trunc(), llvm::APInt::ult(), X, llvm::Xor, Y, and llvm::APInt::zext().
Instruction * InstCombinerImpl::visitAShr | ( | BinaryOperator & | I | ) |
Definition at line 1682 of file InstCombineShifts.cpp.
References llvm::BitWidth, llvm::InstCombiner::Builder, commonShiftTransforms(), llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateAShr(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::BinaryOperator::CreateNeg(), llvm::BinaryOperator::CreateNot(), foldVariableSignZeroExtensionOfVariableHighBitExtract(), foldVectorBinop(), llvm::Value::getName(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignMask(), llvm::SimplifyQuery::getWithInstruction(), llvm::APInt::getZExtValue(), hasNoUnsignedWrap(), I, llvm::Type::isVectorTy(), llvm::APInt::logBase2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::Constant::mergeUndefsWith(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setIsExact(), setShiftFlags(), llvm::simplifyAShrInst(), llvm::InstCombiner::SQ, llvm::APInt::ult(), X, and Y.
Instruction * InstCombinerImpl::visitAtomicRMWInst | ( | AtomicRMWInst & | SI | ) |
Definition at line 103 of file InstCombineAtomicRMW.cpp.
References assert(), llvm::AtomicRMWInst::FAdd, llvm::ConstantFP::getNegativeZero(), llvm::AtomicRMWInst::getOperation(), llvm::AtomicRMWInst::getOrdering(), llvm::Value::getType(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::AtomicRMWInst::isVolatile(), llvm::NotAtomic, llvm::AtomicRMWInst::Or, llvm::InstCombiner::replaceOperand(), llvm::AtomicRMWInst::setOperation(), llvm::Unordered, and llvm::AtomicRMWInst::Xchg.
Instruction * InstCombinerImpl::visitBitCast | ( | BitCastInst & | CI | ) |
Definition at line 2690 of file InstCombineCasts.cpp.
References assert(), llvm::BitWidth, llvm::InstCombiner::Builder, canonicalizeBitCastExtElt(), commonCastTransforms(), llvm::CallInst::Create(), llvm::CastInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateExtractElement(), llvm::IRBuilderBase::CreateZExt(), llvm::InstCombiner::DL, foldBitCastBitwiseLogic(), foldBitCastSelect(), foldCopySignIdioms(), llvm::Value::getContext(), llvm::Intrinsic::getDeclaration(), llvm::APInt::getHighBitsSet(), llvm::Type::getInt32Ty(), llvm::Instruction::getModule(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::DataLayout::isBigEndian(), llvm::Type::isIntegerTy(), llvm::DataLayout::isLegalInteger(), llvm::Type::isVectorTy(), LHS, llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), optimizeIntegerToVectorInsertions(), optimizeVectorResizeWithIntegerBitCasts(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::InstCombiner::SQ, X, and Y.
Instruction * InstCombinerImpl::visitBranchInst | ( | BranchInst & | BI | ) |
Definition at line 3649 of file InstructionCombining.cpp.
References llvm::InstCombiner::BPI, llvm::InstCombiner::Builder, Cond, llvm::IRBuilderBase::CreateLogicalOr(), llvm::IRBuilderBase::CreateNot(), llvm::InstCombiner::DC, llvm::BranchInst::getCondition(), llvm::ConstantInt::getFalse(), llvm::CmpInst::getInversePredicate(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BranchInst::getSuccessor(), handlePotentiallyDeadSuccessors(), llvm::InstCombiner::isCanonicalPredicate(), llvm::BranchInst::isUnconditional(), llvm::PatternMatch::m_FCmp(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Or, llvm::InstructionWorklist::push(), llvm::DomConditionCache::registerBranch(), llvm::InstCombiner::replaceOperand(), llvm::BranchProbabilityInfo::swapSuccEdgesProbabilities(), llvm::BranchInst::swapSuccessors(), visitUnconditionalBranchInst(), llvm::InstCombiner::Worklist, X, and Y.
Instruction * InstCombinerImpl::visitCallBrInst | ( | CallBrInst & | CBI | ) |
Definition at line 3686 of file InstCombineCalls.cpp.
Instruction * InstCombinerImpl::visitCallInst | ( | CallInst & | CI | ) |
CallInst simplification.
This mostly only handles folding of intrinsic instructions. For normal calls, it allows visitCallBase to do the heavy lifting.
This will remove the boolean Condition from the assume given as argument and remove the assume if it becomes useless. always returns nullptr for use as a return values.
Note: this doesn't preserve the offset information but merges offset and alignment. TODO: we can generate a GEP instead of merging the alignment with the offset.
Canonicalize Knowledge in operand bundles.
Definition at line 1509 of file InstCombineCalls.cpp.
References A, llvm::InstCombiner::AA, llvm::InstCombiner::AC, llvm::InstructionWorklist::add(), llvm::CallBase::addRetAttr(), llvm::alignDown(), llvm::FastMathFlags::allowReassoc(), llvm::AlwaysOverflowsHigh, llvm::AlwaysOverflowsLow, llvm::Instruction::andIRFlags(), llvm::CallBase::args(), llvm::RetainedKnowledge::ArgValue, assert(), llvm::RetainedKnowledge::AttrKind, B, llvm::BitWidth, llvm::buildAssumeFromKnowledge(), llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeConstantArg0ToArg1(), llvm::APFloat::clearSign(), llvm::computeConstantRangeIncludingKnownBits(), llvm::InstCombiner::computeKnownBits(), llvm::computeKnownFPSignBit(), computeOverflow(), Cond, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldCompareInstOperands(), llvm::Instruction::copyFastMathFlags(), llvm::Instruction::copyIRFlags(), llvm::KnownBits::countMinLeadingZeros(), llvm::KnownBits::countMinTrailingZeros(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAddReduce(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateAndReduce(), llvm::IRBuilderBase::CreateAssumption(), llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateCast(), llvm::BinaryOperator::CreateFDivFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::IRBuilderBase::CreateFNeg(), llvm::UnaryOperator::CreateFNegFMF(), llvm::IRBuilderBase::CreateFNegFMF(), llvm::BinaryOperator::CreateFSubFMF(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpNE(), llvm::IRBuilderBase::CreateIntCast(), llvm::CastInst::CreateIntegerCast(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateIsNull(), llvm::IRBuilderBase::CreateLdexp(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateNeg(), CreateNonTerminatorUnreachable(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::BinaryOperator::CreateNSW(), llvm::IRBuilderBase::CreateNSWMul(), llvm::BinaryOperator::CreateNSWNeg(), llvm::BinaryOperator::CreateNUW(), llvm::IRBuilderBase::CreateOrReduce(), llvm::IRBuilderBase::CreatePtrToInt(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::BinaryOperator::CreateWithCopiedFlags(), llvm::UnaryOperator::CreateWithCopiedFlags(), llvm::IRBuilderBase::CreateZExt(), llvm::IRBuilderBase::CreateZExtOrTrunc(), llvm::Data, llvm::InstCombiner::DL, llvm::Function::doesNotThrow(), llvm::CallBase::doesNotThrow(), llvm::Value::dropDroppableUse(), llvm::InstCombiner::DT, llvm::EnableKnowledgeRetention, eraseInstFromFunction(), factorizeMinMaxTree(), llvm::FAdd, foldClampRangeOfTwo(), foldCtpop(), foldCttzCtlz(), FoldOpIntoSelect(), foldShuffledIntrinsicOperands(), llvm::ConstantPtrAuth::get(), llvm::MDNode::get(), llvm::ConstantPointerNull::get(), llvm::ConstantAggregateZero::get(), llvm::APInt::getAllOnes(), llvm::Constant::getAllOnesValue(), llvm::CallBase::getArgOperand(), llvm::InstCombiner::getAssumptionCache(), llvm::KnownBits::getBitWidth(), llvm::ConstantInt::getBool(), llvm::CallBase::getCalledOperand(), llvm::Value::getContext(), llvm::Intrinsic::getDeclaration(), llvm::InstCombiner::getDominatorTree(), llvm::VectorType::getElementCount(), llvm::IRBuilderBase::getFalse(), llvm::getFreedOperand(), llvm::InstCombiner::getFreelyInverted(), llvm::Instruction::getFunction(), llvm::IRBuilderBase::getInt1Ty(), llvm::Type::getInt64Ty(), llvm::Constant::getIntegerValue(), llvm::IRBuilderBase::getIntNTy(), llvm::CallBase::getIntrinsicID(), llvm::getInverseMinMaxIntrinsic(), llvm::getKnowledgeFromBundle(), llvm::getKnownAlignment(), getKnownSign(), getKnownSignOrZero(), getLosslessSignedTrunc(), getLosslessUnsignedTrunc(), llvm::APInt::getLowBitsSet(), llvm::APSInt::getMaxValue(), llvm::APSInt::getMinValue(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::ConstantExpr::getNeg(), llvm::Instruction::getNextNonDebugInstruction(), llvm::CmpInst::getNonStrictPredicate(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), getOpcode(), llvm::ConstantExpr::getPointerCast(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::MinMaxIntrinsic::getPredicate(), llvm::IRBuilderBase::getPtrTy(), llvm::CallBase::getRetAlign(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignedMinValue(), llvm::APInt::getSignMask(), llvm::InstCombiner::getSimplifyQuery(), llvm::ConstantExpr::getSub(), llvm::CmpInst::getSwappedPredicate(), llvm::OperandBundleUse::getTagName(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::getUnderlyingObject(), llvm::Attribute::getWithAlignment(), llvm::SimplifyQuery::getWithInstruction(), GuardWideningWindow, llvm::Value::hasOneUse(), llvm::CallBase::hasRetAttr(), I, llvm::ConstantRange::icmp(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, Idx, II, llvm::OperandBundleUse::Inputs, llvm::KnownBits::isAllOnes(), llvm::isAssumeWithEmptyBundle(), llvm::InstCombiner::isFreeToInvert(), llvm::ConstantRange::isFullSet(), llvm::details::FixedOrScalableQuantity< ElementCount, unsigned >::isKnownGT(), llvm::details::FixedOrScalableQuantity< ElementCount, unsigned >::isKnownLT(), llvm::isKnownNegation(), llvm::isKnownNonZero(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::APFloat::isNegative(), llvm::APInt::isNonNegative(), llvm::KnownBits::isNonZero(), llvm::Type::isPointerTy(), llvm::isPowerOf2_32(), llvm::isPowerOf2_64(), llvm::isSafeToSpeculativelyExecute(), llvm::MinMaxIntrinsic::isSigned(), llvm::isSplatValue(), llvm::isValidAssumeForContext(), LHS, llvm_unreachable, llvm::Log2(), llvm::Log2_32_Ceil(), llvm::lowerObjectSizeCall(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_CopySign(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FAbs(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_LogicalShift(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_NegZeroFP(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWAddLike(), llvm::PatternMatch::m_NSWNeg(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_SpecificICmp(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_UnOp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VecReverse(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExtOrSelf(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), matchBSwapOrBitReverse(), llvm::Value::MaxAlignmentExponent, llvm::maximum(), llvm::maxnum(), llvm::MayOverflow, MI, llvm::MinAlign(), llvm::minimum(), llvm::minnum(), llvm::Mod, moveAddAfterMinMax(), llvm::Instruction::moveBefore(), llvm::NeverOverflows, llvm::None, llvm::NullPointerIsDefined(), llvm::Offset, llvm::Other, llvm::PoisonMaskElem, Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstructionWorklist::pushValue(), reassociateMinMaxWithConstantInOperand(), reassociateMinMaxWithConstants(), llvm::AssumptionCache::registerAssumption(), removeTriviallyEmptyRange(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::InstCombiner::replaceUse(), RetTy, llvm::APInt::sadd_ov(), Select, llvm::CallBase::setCalledFunction(), llvm::CallBase::setDoesNotThrow(), llvm::Value::setMetadata(), llvm::FastMathFlags::setNoSignedZeros(), signBitMustBeTheSame(), SimplifyAnyMemSet(), SimplifyAnyMemTransfer(), llvm::simplifyCall(), llvm::simplifyConstrainedFPCall(), SimplifyDemandedBits(), SimplifyDemandedInstructionBits(), SimplifyDemandedVectorElts(), llvm::simplifyFMAFMul(), llvm::simplifyFMulInst(), simplifyInvariantGroupIntrinsic(), simplifyNeonTbl1(), simplifyReductionOperand(), llvm::simplifyRetainedKnowledge(), llvm::Splat, llvm::InstCombiner::SQ, std::swap(), llvm::InstCombiner::targetInstCombineIntrinsic(), llvm::InstCombiner::TLI, llvm::APInt::uadd_ov(), llvm::APInt::uadd_sat(), llvm::AssumptionCache::updateAffectedValues(), llvm::Value::use_empty(), llvm::MaybeAlign::valueOrOne(), visitFree(), llvm::RetainedKnowledge::WasOn, llvm::InstCombiner::Worklist, X, and Y.
Instruction * InstCombinerImpl::visitExtractElementInst | ( | ExtractElementInst & | EI | ) |
Definition at line 398 of file InstCombineVectorOps.cpp.
References llvm::InstructionWorklist::addValue(), llvm::BitWidth, llvm::InstCombiner::Builder, cheapToScalarize(), llvm::count_if(), llvm::CastInst::Create(), llvm::GetElementPtrInst::Create(), llvm::ExtractElementInst::Create(), llvm::IRBuilderBase::CreateExtractElement(), llvm::BinaryOperator::CreateWithCopiedFlags(), llvm::CmpInst::CreateWithCopiedFlags(), llvm::UnaryOperator::CreateWithCopiedFlags(), findDemandedEltsByAllUsers(), FoldOpIntoSelect(), GEP, llvm::PoisonValue::get(), llvm::Value::getContext(), llvm::VectorType::getElementCount(), llvm::ExtractElementInst::getIndexOperand(), llvm::Type::getInt64Ty(), llvm::Type::getIntegerBitWidth(), llvm::UnaryOperator::getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::CmpInst::getOpcode(), llvm::User::getOperand(), getPreferredVectorIndex(), llvm::Value::getType(), llvm::ExtractElementInst::getVectorOperand(), llvm::ExtractElementInst::getVectorOperandType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), I, Idx, II, llvm::APInt::isAllOnes(), llvm::isSafeToSpeculativelyExecute(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Cmp(), llvm::PatternMatch::m_UnOp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::APInt::setBit(), llvm::GetElementPtrInst::setIsInBounds(), SimplifyDemandedVectorElts(), llvm::simplifyExtractElementInst(), llvm::InstCombiner::SQ, llvm::InstCombiner::Worklist, X, and Y.
Instruction * InstCombinerImpl::visitExtractValueInst | ( | ExtractValueInst & | EV | ) |
Definition at line 3958 of file InstructionCombining.cpp.
References llvm::InstCombiner::Builder, llvm::ExtractValueInst::Create(), llvm::InsertValueInst::Create(), llvm::IRBuilderBase::CreateExtractValue(), llvm::IRBuilderBase::CreateInBoundsGEP(), llvm::IRBuilderBase::CreateLoad(), foldOpIntoPhi(), FoldOpIntoSelect(), GEP, llvm::ExtractValueInst::getAggregateOperand(), llvm::ExtractValueInst::getIndices(), llvm::IRBuilderBase::getInt32(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::ExtractValueInst::hasIndices(), Idx, llvm::ExtractValueInst::idx_begin(), llvm::ExtractValueInst::idx_end(), llvm::ExtractValueInst::indices(), IV, NL, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::IRBuilderBase::SetInsertPoint(), llvm::simplifyExtractValueInst(), and llvm::InstCombiner::SQ.
Instruction * InstCombinerImpl::visitFAdd | ( | BinaryOperator & | I | ) |
Definition at line 1891 of file InstCombineAddSub.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::BinaryOperator::CreateFAddFMF(), llvm::IRBuilderBase::CreateFDivFMF(), llvm::IRBuilderBase::CreateFMulFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::BinaryOperator::CreateFSubFMF(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::InstCombiner::DL, F, factorizeFAddFSub(), foldBinOpIntoSelectOrPhi(), foldBinopWithPhiOperands(), foldSquareSumFP(), foldVectorBinop(), llvm::SimplifyQuery::getWithInstruction(), I, LHS, llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_c_FAdd(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_FMul(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), RHS, simplify, SimplifyAssociativeOrCommutative(), llvm::simplifyFAddInst(), SimplifySelectsFeedingBinaryOp(), llvm::InstCombiner::SQ, X, and Y.
Instruction * InstCombinerImpl::visitFCmpInst | ( | FCmpInst & | I | ) |
Orders the operands of the compare so that they are listed from most complex to least complex. This puts constants before unary operators, before binary operators.
Definition at line 8173 of file InstCombineCompares.cpp.
References A, assert(), B, llvm::CmpInst::BAD_ICMP_PREDICATE, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::APFloat::clearSign(), llvm::ConstantFoldUnaryOpOperand(), llvm::APFloat::convert(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBitCast(), llvm::InstCombiner::DL, llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, llvm::CmpInst::FCMP_UNO, llvm::SelectPatternResult::Flavor, foldCmpLoadFromIndexedGlobal(), foldFabsWithFcmpZero(), foldFCmpFNegCommonOp(), foldFCmpFSubIntoFCmp(), foldFCmpIntToFPConst(), foldFCmpReciprocalAndZero(), foldOpIntoPhi(), FoldOpIntoSelect(), foldSqrtWithFcmpZero(), foldVectorCmp(), GEP, llvm::VectorType::get(), llvm::InstCombiner::getComplexity(), llvm::ConstantInt::getFalse(), llvm::IRBuilderBase::getIntNTy(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::InstCombiner::getSimplifyQuery(), llvm::APFloat::getSmallestNormalized(), llvm::CmpInst::getSwappedPredicate(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::ConstantFP::getZero(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SLT, IntX, llvm::FCmpInst::isEquality(), llvm::isKnownNeverNaN(), llvm::APFloat::isZero(), llvm_unreachable, llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_FAdd(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PosZeroFP(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::APFloatBase::rmNearestTiesToEven, llvm::simplifyFCmpInst(), llvm::SPF_UNKNOWN, llvm::InstCombiner::SQ, X, and Y.
Instruction * InstCombinerImpl::visitFDiv | ( | BinaryOperator & | I | ) |
Definition at line 1875 of file InstCombineMulDivRem.cpp.
References B, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateFAddFMF(), llvm::BinaryOperator::CreateFDivFMF(), llvm::IRBuilderBase::CreateFMulFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::emitUnaryFloatFnCall(), foldBinopWithPhiOperands(), foldFDivConstantDividend(), foldFDivPowDivisor(), foldFDivSqrtDivisor(), FoldOpIntoSelect(), foldPowiReassoc(), foldVectorBinop(), llvm::SimplifyQuery::getWithInstruction(), llvm::hasFloatFn(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FAbs(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Mul, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::simplifyFDivInst(), llvm::InstCombiner::SQ, llvm::InstCombiner::TLI, X, and Y.
Instruction * InstCombinerImpl::visitFenceInst | ( | FenceInst & | FI | ) |
Definition at line 3653 of file InstCombineCalls.cpp.
References eraseInstFromFunction(), llvm::Instruction::getNextNonDebugInstruction(), llvm::FenceInst::getOrdering(), llvm::Instruction::getPrevNonDebugInstruction(), llvm::FenceInst::getSyncScopeID(), llvm::isAtLeastOrStrongerThan(), llvm::Instruction::isIdenticalTo(), llvm::SyncScope::SingleThread, and llvm::SyncScope::System.
Instruction * InstCombinerImpl::visitFMul | ( | BinaryOperator & | I | ) |
Definition at line 856 of file InstCombineMulDivRem.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldUnaryOpOperand(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateFMulFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::UnaryOperator::CreateFNegFMF(), llvm::IRBuilderBase::CreateFNegFMF(), llvm::BinaryOperator::CreateFSubFMF(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::InstCombiner::DL, foldBinOpIntoSelectOrPhi(), foldBinopWithPhiOperands(), foldFMulReassoc(), foldMulSelectToNegate(), foldVectorBinop(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::isKnownNeverNaN(), llvm::APFloat::isNegative(), llvm::APFloat::isZero(), llvm::Log2(), llvm::PatternMatch::m_APFloatAllowPoison(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_FMul(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_UIToFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::matchSimpleRecurrence(), llvm::InstCombiner::replaceInstUsesWith(), SimplifyAssociativeOrCommutative(), llvm::simplifyFMulInst(), SimplifySelectsFeedingBinaryOp(), llvm::InstCombiner::SQ, X, and Y.
Instruction * InstCombinerImpl::visitFNeg | ( | UnaryOperator & | I | ) |
Definition at line 2751 of file InstCombineAddSub.cpp.
References llvm::InstCombiner::Builder, Cond, llvm::Instruction::copyFastMathFlags(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateCopySign(), llvm::IRBuilderBase::CreateFNeg(), llvm::IRBuilderBase::CreateFNegFMF(), llvm::BinaryOperator::CreateFSubFMF(), llvm::InstCombiner::DL, foldFNegIntoConstant(), llvm::InstCombiner::getSimplifyQuery(), I, llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::PatternMatch::m_CopySign(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), P, llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setFastMathFlags(), llvm::IRBuilderBase::setFastMathFlags(), llvm::Instruction::setHasNoSignedZeros(), llvm::simplifyFNegInst(), X, and Y.
Instruction * InstCombinerImpl::visitFPExt | ( | CastInst & | CI | ) |
Definition at line 1896 of file InstCombineCasts.cpp.
References commonCastTransforms(), llvm::CastInst::Create(), llvm::User::getOperand(), llvm::Value::getType(), and isKnownExactCastIntToFP().
Instruction * InstCombinerImpl::visitFPToSI | ( | FPToSIInst & | FI | ) |
Definition at line 1977 of file InstCombineCasts.cpp.
References commonCastTransforms(), foldFPtoI(), foldItoFPtoI(), and I.
Instruction * InstCombinerImpl::visitFPToUI | ( | FPToUIInst & | FI | ) |
Definition at line 1967 of file InstCombineCasts.cpp.
References commonCastTransforms(), foldFPtoI(), foldItoFPtoI(), and I.
Instruction * InstCombinerImpl::visitFPTrunc | ( | FPTruncInst & | CI | ) |
Definition at line 1710 of file InstCombineCasts.cpp.
References llvm::InstCombiner::Builder, commonCastTransforms(), Cond, llvm::Instruction::copyFastMathFlags(), llvm::BinaryOperator::Create(), llvm::CallInst::Create(), llvm::CastInst::Create(), llvm::BinaryOperator::CreateFDivFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::UnaryOperator::CreateFNegFMF(), llvm::CastInst::CreateFPCast(), llvm::IRBuilderBase::CreateFPTrunc(), llvm::IRBuilderBase::CreateFRemFMF(), llvm::IRBuilderBase::CreateSelect(), llvm::Intrinsic::getDeclaration(), llvm::Type::getFPMantissaWidth(), getMinimumFPType(), llvm::Instruction::getModule(), llvm::User::getOperand(), llvm::CastInst::getSrcTy(), llvm::Value::getType(), I, II, llvm::Type::isBFloatTy(), isKnownExactCastIntToFP(), LHS, llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::IRBuilderBase::setFastMathFlags(), shrinkInsertElt(), X, and Y.
Instruction * InstCombinerImpl::visitFree | ( | CallInst & | FI, |
Value * | FreedOp | ||
) |
Definition at line 3452 of file InstructionCombining.cpp.
References CreateNonTerminatorUnreachable(), llvm::InstCombiner::DL, eraseInstFromFunction(), llvm::TargetLibraryInfo::getLibFunc(), llvm::getReallocatedOperand(), llvm::TargetLibraryInfo::has(), llvm::Value::hasOneUse(), I, llvm::InstCombiner::MinimizeSize, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::TLI, and tryToMoveFreeBeforeNullTest().
Referenced by visitCallInst().
Instruction * InstCombinerImpl::visitFreeze | ( | FreezeInst & | I | ) |
Definition at line 4608 of file InstructionCombining.cpp.
References assert(), llvm::CallingConv::C, foldFreezeIntoRecurrence(), foldOpIntoPhi(), freezeOtherUses(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::ConstantInt::getTrue(), llvm::SimplifyQuery::getWithInstruction(), I, isUsedWithinShuffleVector(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), pushFreezeToPreventPoisonFromPropagating(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Constant::replaceUndefsWith(), llvm::simplifyFreezeInst(), and llvm::InstCombiner::SQ.
Instruction * InstCombinerImpl::visitFRem | ( | BinaryOperator & | I | ) |
Definition at line 2308 of file InstCombineMulDivRem.cpp.
References foldBinopWithPhiOperands(), foldVectorBinop(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::InstCombiner::replaceInstUsesWith(), llvm::simplifyFRemInst(), llvm::InstCombiner::SQ, and X.
Instruction * InstCombinerImpl::visitFSub | ( | BinaryOperator & | I | ) |
Definition at line 2836 of file InstCombineAddSub.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::cannotBeNegativeZero(), llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldUnaryOpOperand(), llvm::IRBuilderBase::CreateFAddFMF(), llvm::BinaryOperator::CreateFAddFMF(), llvm::IRBuilderBase::CreateFDivFMF(), llvm::IRBuilderBase::CreateFMulFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::UnaryOperator::CreateFNegFMF(), llvm::IRBuilderBase::CreateFPExt(), llvm::IRBuilderBase::CreateFPTrunc(), llvm::IRBuilderBase::CreateFSubFMF(), llvm::BinaryOperator::CreateFSubFMF(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::InstCombiner::DL, F, factorizeFAddFSub(), llvm::FAdd, llvm::FMul, foldBinopWithPhiOperands(), foldFNegIntoConstant(), FoldOpIntoSelect(), foldVectorBinop(), llvm::InstCombiner::getSimplifyQuery(), llvm::Value::getType(), I, llvm::PatternMatch::m_c_FAdd(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_FMul(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_FPTrunc(), llvm::PatternMatch::m_FSub(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), simplify, llvm::simplifyFSubInst(), SimplifySelectsFeedingBinaryOp(), X, and Y.
Instruction * InstCombinerImpl::visitGEPOfGEP | ( | GetElementPtrInst & | GEP, |
GEPOperator * | Src | ||
) |
Definition at line 2379 of file InstructionCombining.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::append_range(), llvm::InstCombiner::Builder, canonicalizeGEPOfConstGEPI8(), llvm::IRBuilderBase::CreateGEP(), llvm::InstCombiner::DL, llvm::drop_begin(), llvm::drop_end(), llvm::SmallVectorBase< Size_T >::empty(), llvm::enumerate(), GEP, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::DataLayout::getGEPIndicesForOffset(), llvm::DataLayout::getIndexedOffsetInType(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::DataLayout::getIndexTypeSizeInBits(), llvm::IRBuilderBase::getInt(), llvm::Type::getInt32Ty(), llvm::IRBuilderBase::getInt8Ty(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), I, Idx, isMergedGEPInBounds(), llvm::Offset, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), shouldMergeGEPs(), llvm::simplifyAddInst(), and llvm::InstCombiner::SQ.
Referenced by visitGetElementPtrInst().
Instruction * InstCombinerImpl::visitGetElementPtrInst | ( | GetElementPtrInst & | GEP | ) |
Definition at line 2709 of file InstructionCombining.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::countr_zero(), llvm::GetElementPtrInst::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateGEP(), llvm::GetElementPtrInst::CreateInBounds(), llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreatePHI(), llvm::IRBuilderBase::CreatePtrAdd(), llvm::IRBuilderBase::CreateSExt(), llvm::InstCombiner::DL, F, foldSelectGEP(), GEP, llvm::gep_type_begin(), llvm::VectorType::get(), llvm::APInt::getAllOnes(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::DataLayout::getIndexSizeInBits(), llvm::DataLayout::getIndexType(), llvm::DataLayout::getIndexTypeSizeInBits(), llvm::IRBuilderBase::getInt(), llvm::IRBuilderBase::getInt8Ty(), llvm::Constant::getNullValue(), llvm::Type::getPointerAddressSpace(), llvm::Value::getPointerDereferenceableBytes(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::GetElementPtrInst::getTypeAtIndex(), llvm::getUnderlyingObject(), llvm::SimplifyQuery::getWithInstruction(), llvm::has_single_bit(), I, llvm::APInt::isAllOnes(), llvm::Type::isIntegerTy(), llvm::isKnownNonNegative(), llvm::APInt::isNonNegative(), llvm::Type::isScalableTy(), llvm::Type::isSized(), llvm::generic_gep_type_iterator< ItTy >::isStruct(), llvm::Type::isStructTy(), llvm::Type::isVectorTy(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isZero(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_IDiv(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_NSWAdd(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_SExtLike(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::Offset, llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::APInt::sdivrem(), llvm::IRBuilderBase::SetInsertPoint(), SimplifyDemandedVectorElts(), llvm::simplifyGEPInst(), llvm::InstCombiner::SQ, llvm::Value::stripAndAccumulateInBoundsConstantOffsets(), llvm::APInt::udivrem(), llvm::APInt::ule(), visitGEPOfGEP(), X, and Y.
Instruction * InstCombinerImpl::visitICmpInst | ( | ICmpInst & | I | ) |
Orders the operands of the compare so that they are listed from most complex to least complex. This puts constants before unary operators, before binary operators.
Definition at line 7359 of file InstCombineCompares.cpp.
References A, llvm::AllOnes, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeCmpWithConstant(), canonicalizeICmpBool(), canonicalizeICmpPredicate(), Cond, llvm::CmpInst::Create(), llvm::ExtractValueInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateICmpSLT(), D, llvm::InstCombiner::DL, eraseInstFromFunction(), llvm::SelectPatternResult::Flavor, foldAllocaCmp(), foldICmpBinOp(), foldICmpBitCast(), foldICmpCommutative(), foldICmpEquality(), foldICmpInstWithConstant(), foldICmpInstWithConstantNotInt(), foldICmpInvariantGroup(), foldICmpOfUAddOv(), foldICmpPow2Test(), foldICmpTruncWithTruncOrExt(), foldICmpUsingBoolRange(), foldICmpUsingKnownBits(), foldICmpWithCastOp(), foldICmpWithConstant(), foldICmpWithDominatingICmp(), foldICmpWithHighBitMask(), foldICmpWithZero(), foldReductionIdiom(), foldSignBitTest(), foldVectorCmp(), llvm::Constant::getAllOnesValue(), llvm::InstCombiner::getComplexity(), llvm::InstCombiner::getFreelyInverted(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::getUnderlyingObject(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::InstCombiner::isFreeToInvert(), llvm::Type::isIntOrIntVectorTy(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::Type::isPointerTy(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_UAddWithOverflow(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), processUMulZExtIdiom(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::simplifyICmpInst(), llvm::SPF_UNKNOWN, llvm::InstCombiner::SQ, std::swap(), X, and Y.
Instruction * InstCombinerImpl::visitInsertElementInst | ( | InsertElementInst & | IE | ) |
Definition at line 1606 of file InstCombineVectorOps.cpp.
References llvm::InstCombiner::Builder, collectShuffleElements(), llvm::InsertElementInst::Create(), llvm::IRBuilderBase::CreateInsertElement(), llvm::InstCombiner::DL, foldConstantInsEltIntoShuffle(), foldInsEltIntoIdentityShuffle(), foldInsEltIntoSplat(), foldInsSequenceIntoSplat(), foldTruncInsEltPair(), llvm::VectorType::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::APInt::getAllOnes(), llvm::IRBuilderBase::getInt64(), getPreferredVectorIndex(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), hoistInsEltConst(), llvm::DataLayout::isBigEndian(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ExtractElt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), narrowInsElt(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), SimplifyDemandedVectorElts(), llvm::simplifyInsertElementInst(), llvm::Splat, and llvm::InstCombiner::SQ.
Instruction * InstCombinerImpl::visitInsertValueInst | ( | InsertValueInst & | I | ) |
Try to find redundant insertvalue instructions, like the following ones: %0 = insertvalue { i8, i32 } undef, i8 x, 0 %1 = insertvalue { i8, i32 } %0, i8 y, 0 Here the second instruction inserts values at the same indices, as the first one, making the first one redundant.
It should be transformed to: %0 = insertvalue { i8, i32 } undef, i8 y, 0
Definition at line 1148 of file InstCombineVectorOps.cpp.
References llvm::Depth, foldAggregateConstructionIntoAggregateReuse(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::InstCombiner::replaceInstUsesWith(), llvm::simplifyInsertValueInst(), and llvm::InstCombiner::SQ.
|
inline |
Specify what to return for unhandled instructions.
Definition at line 185 of file InstCombineInternal.h.
Instruction * InstCombinerImpl::visitIntToPtr | ( | IntToPtrInst & | CI | ) |
Definition at line 2009 of file InstCombineCasts.cpp.
References llvm::InstCombiner::Builder, commonCastTransforms(), llvm::IRBuilderBase::CreateZExtOrTrunc(), llvm::InstCombiner::DL, llvm::IntToPtrInst::getAddressSpace(), llvm::Value::getContext(), llvm::DataLayout::getIntPtrType(), llvm::User::getOperand(), llvm::DataLayout::getPointerSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Type::getWithNewType(), I, and P.
Instruction * InstCombinerImpl::visitInvokeInst | ( | InvokeInst & | II | ) |
Definition at line 3681 of file InstCombineCalls.cpp.
References II.
Instruction * InstCombinerImpl::visitLandingPadInst | ( | LandingPadInst & | LI | ) |
Definition at line 4115 of file InstructionCombining.cpp.
References llvm::LandingPadInst::addClause(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::CallingConv::C, llvm::classifyEHPersonality(), llvm::LandingPadInst::Create(), llvm::SmallVectorImpl< T >::erase(), llvm::Filter, llvm::ConstantArray::get(), llvm::ArrayType::get(), llvm::ArrayType::getElementType(), llvm::Constant::getNullValue(), llvm::ArrayType::getNumElements(), llvm::User::getOperand(), llvm::Value::getType(), getType(), llvm::SmallPtrSetImpl< PtrType >::insert(), isCatchAll(), llvm::InstCombiner::LI, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::LandingPadInst::setCleanup(), shorter_filter(), llvm::SmallVectorBase< Size_T >::size(), llvm::Constant::stripPointerCasts(), and llvm::Value::stripPointerCasts().
Instruction * InstCombinerImpl::visitLoadInst | ( | LoadInst & | LI | ) |
Definition at line 1004 of file InstCombineLoadStoreAlloca.cpp.
References llvm::InstCombiner::AA, llvm::InstCombiner::AC, assert(), llvm::InstCombiner::Builder, canSimplifyNullLoadOrGEP(), combineLoadToOperationType(), llvm::combineMetadataForCSE(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateBitOrPointerCast(), llvm::IRBuilderBase::CreateLoad(), CreateNonTerminatorUnreachable(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, llvm::EnableInferAlignmentPass, llvm::FindAvailableLoadedValue(), llvm::PoisonValue::get(), llvm::getOrEnforceKnownAlignment(), llvm::DataLayout::getPrefTypeAlign(), llvm::SimplifyQuery::getWithInstruction(), llvm::isSafeToLoadUnconditionally(), llvm::InstCombiner::LI, llvm::NullPointerIsDefined(), replaceGEPIdxWithZero(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::LoadInst::setAlignment(), llvm::LoadInst::setAtomic(), llvm::simplifyLoadInst(), llvm::InstCombiner::SQ, and unpackLoadToAggregate().
Instruction * InstCombinerImpl::visitLShr | ( | BinaryOperator & | I | ) |
Definition at line 1271 of file InstCombineShifts.cpp.
References llvm::AllOnes, llvm::And, assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, commonShiftTransforms(), llvm::InstCombiner::computeKnownBits(), llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateAShr(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateIsNotNeg(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), llvm::IRBuilderBase::CreateZExt(), llvm::APInt::eq(), foldVectorBinop(), llvm::APInt::getAllOnes(), llvm::Constant::getAllOnesValue(), llvm::APInt::getLowBitsSet(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::Type::getScalarSizeInBits(), getScalarSizeInBits(), llvm::ConstantInt::getSigned(), llvm::Value::getType(), getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::APInt::getZExtValue(), hasNoSignedWrap(), hasNoUnsignedWrap(), llvm::Value::hasOneUse(), I, II, llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::isPowerOf2_32(), llvm::Log2_32(), llvm::APInt::logBase2(), llvm::APInt::lshr(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), RHS, setShiftFlags(), llvm::APInt::shl(), llvm::simplifyLShrInst(), llvm::InstCombiner::SQ, llvm::APInt::uge(), llvm::APInt::ugt(), llvm::APInt::ult(), X, and Y.
Instruction * InstCombinerImpl::visitMul | ( | BinaryOperator & | I | ) |
Definition at line 195 of file InstCombineMulDivRem.cpp.
References llvm::And, assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::APInt::countr_zero(), llvm::CastInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateBinOp(), llvm::BinaryOperator::CreateExact(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateIsNeg(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateNSWMul(), llvm::BinaryOperator::CreateNSWNeg(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateZExt(), llvm::InstCombiner::DL, foldBinOpIntoSelectOrPhi(), foldBinOpOfSelectAndCastOfSelectCondition(), foldBinopWithPhiOperands(), foldMulSelectToNegate(), foldMulShl1(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::ConstantInt::getBool(), llvm::ConstantExpr::getExactLogBase2(), llvm::ConstantExpr::getNeg(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::IRBuilderBase::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), hasNoSignedWrap(), llvm::Value::hasOneUse(), I, llvm::APInt::isAllOnes(), llvm::Instruction::isExact(), llvm::isGuaranteedNotToBeUndef(), llvm::Type::isIntOrIntVectorTy(), llvm::Constant::isNotMinSignedValue(), llvm::APInt::isZero(), llvm::PatternMatch::m_AddLike(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_CheckedInt(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::CmpInst::makeCmpResultType(), llvm::PatternMatch::match(), llvm::Mul, N, llvm::Negator::Negate(), llvm::InstCombiner::replaceInstUsesWith(), llvm::APInt::sdivrem(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), SimplifyAssociativeOrCommutative(), llvm::simplifyMulInst(), llvm::InstCombiner::SQ, takeLog2(), llvm::Value::takeName(), X, and Y.
Instruction * InstCombinerImpl::visitOr | ( | BinaryOperator & | I | ) |
Res, Overflow = xxx_with_overflow X, C1 Try to canonicalize the pattern "Overflow | icmp pred Res, C2" into "Overflow | icmp pred X, C2 +/- C1".
Definition at line 3508 of file InstCombineAndOrXor.cpp.
References A, llvm::AllOnes, llvm::And, B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(), canonicalizeLogicFirst(), llvm::InstCombiner::computeKnownBits(), Concat, llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateFNeg(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateICmpSGT(), llvm::IRBuilderBase::CreateIsNotNull(), llvm::IRBuilderBase::CreateLogicalOr(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), D, llvm::DominatorTree::dominates(), llvm::InstCombiner::DT, foldBinOpIntoSelectOrPhi(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBitwiseLogicWithIntrinsics(), foldComplexAndOrPatterns(), foldOrOfInversions(), foldOrToXor(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::BinaryOpIntrinsic::getBinaryOp(), llvm::IRBuilderBase::GetInsertBlock(), llvm::BinaryOpIntrinsic::getLHS(), llvm::Constant::getNullValue(), llvm::BasicBlock::getParent(), llvm::BinaryOpIntrinsic::getRHS(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), I, llvm::CmpInst::ICMP_NE, llvm::APInt::isAllOnes(), llvm::ICmpInst::isEquality(), llvm::Type::isFloatingPointTy(), llvm::Type::isIEEE(), llvm::Type::isIntOrIntVectorTy(), llvm::CmpInst::isSigned(), llvm::BinaryOpIntrinsic::isSigned(), isZero(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_DisjointOr(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificICmp(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_WithOverflowInst(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZeroInt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), matchBSwapOrBitReverse(), matchDeMorgansLaws(), matchFunnelShift(), matchOrConcat(), llvm::matchSimpleRecurrence(), llvm::Mul, llvm::KnownBits::One, llvm::Or, reassociateFCmps(), reassociateForUses(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::APInt::sadd_ov(), SimplifyAddWithRemainder(), simplifyAndOrWithOpReplaced(), SimplifyAssociativeOrCommutative(), SimplifyDemandedInstructionBits(), llvm::simplifyOrInst(), sinkNotIntoOtherHandOfLogicalOp(), llvm::InstCombiner::SQ, llvm::APInt::ssub_ov(), std::swap(), llvm::Value::takeName(), tryFoldInstWithCtpopWithNot(), llvm::APInt::uadd_ov(), llvm::APInt::usub_ov(), X, llvm::Xor, and Y.
Instruction * InstCombinerImpl::visitPHINode | ( | PHINode & | PN | ) |
Definition at line 1439 of file InstCombinePHI.cpp.
References llvm::all_of(), llvm::CastInst::CreatePointerCast(), foldIntegerTypedPHI(), foldPHIArgIntToPtrToPHI(), foldPHIArgOpIntoPHI(), foldPHIArgZextsIntoPHI(), llvm::PoisonValue::get(), getAnyNonZeroConstInt(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::InstCombiner::getSimplifyQuery(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasNUsesOrMore(), llvm::Value::hasOneUse(), I, if(), llvm::PHINode::incoming_values(), llvm::SmallPtrSetImpl< PtrType >::insert(), isDeadPHICycle(), llvm::CmpInst::isEquality(), llvm::isKnownNonZero(), llvm::Type::isPointerTy(), IV, llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), llvm::simplifyInstruction(), llvm::InstCombiner::SQ, llvm::Value::stripPointerCasts(), llvm::Instruction::user_back(), and llvm::Value::users().
Instruction * InstCombinerImpl::visitPtrToInt | ( | PtrToIntInst & | CI | ) |
Definition at line 2028 of file InstCombineCasts.cpp.
References assert(), llvm::sampleprof::Base, llvm::InstCombiner::Builder, commonCastTransforms(), llvm::InsertElementInst::Create(), llvm::IRBuilderBase::CreateIntCast(), llvm::CastInst::CreateIntegerCast(), llvm::IRBuilderBase::CreatePtrToInt(), llvm::InstCombiner::DL, GEP, llvm::Value::getContext(), llvm::DataLayout::getIntPtrType(), llvm::PtrToIntInst::getPointerAddressSpace(), llvm::PtrToIntInst::getPointerOperand(), llvm::DataLayout::getPointerSizeInBits(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::Type::getWithNewType(), llvm::isKnownNonNegative(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_IntToPtr(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Offset, P, Ptr, llvm::InstCombiner::replaceInstUsesWith(), and llvm::InstCombiner::SQ.
Instruction * InstCombinerImpl::visitReturnInst | ( | ReturnInst & | RI | ) |
Definition at line 3492 of file InstructionCombining.cpp.
References llvm::ReturnInst::Create(), F, llvm::fcNone, llvm::Value::getContext(), llvm::Instruction::getFunction(), llvm::ReturnInst::getReturnValue(), llvm::Value::getType(), llvm::AttributeFuncs::isNoFPClassCompatibleType(), and SimplifyDemandedUseFPClass().
Instruction * InstCombinerImpl::visitSDiv | ( | BinaryOperator & | I | ) |
Definition at line 1583 of file InstCombineMulDivRem.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, commonIDivTransforms(), llvm::InstCombiner::computeKnownBits(), Cond, llvm::KnownBits::countMinTrailingZeros(), llvm::APInt::countr_zero(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAShr(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateIsNotNeg(), llvm::IRBuilderBase::CreateLShr(), llvm::BinaryOperator::CreateNeg(), llvm::BinaryOperator::CreateNSWNeg(), llvm::IRBuilderBase::CreateSDiv(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getExactLogBase2(), llvm::ConstantExpr::getNeg(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignedMinValue(), llvm::APInt::getSignificantBits(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::isKnownNegation(), llvm::isKnownNonNegative(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::APInt::isMinSignedValue(), llvm::KnownBits::isNonNegative(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_NegatedPower2(), llvm::PatternMatch::m_NonNegative(), llvm::PatternMatch::m_NSWNeg(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_SDiv(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setIsExact(), llvm::simplifySDivInst(), llvm::InstCombiner::SQ, X, and Y.
Instruction * llvm::InstCombinerImpl::visitSelectInst | ( | SelectInst & | SI | ) |
Instruction * InstCombinerImpl::visitSExt | ( | SExtInst & | Sext | ) |
Definition at line 1428 of file InstCombineCasts.cpp.
References A, assert(), llvm::InstCombiner::Builder, canEvaluateSExtd(), commonCastTransforms(), llvm::InstCombiner::ComputeNumSignBits(), llvm::ConstantFoldCastOperand(), llvm::CastInst::Create(), llvm::IRBuilderBase::CreateAShr(), llvm::CastInst::CreateIntegerCast(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateVScale(), llvm::dbgs(), llvm::InstCombiner::DL, EvaluateInDifferentType(), llvm::Function::getFnAttribute(), llvm::Instruction::getFunction(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::Attribute::getVScaleRangeMax(), llvm::SimplifyQuery::getWithInstruction(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), I, llvm::Constant::isElementWiseEqual(), llvm::isKnownNonNegative(), LLVM_DEBUG, llvm::Log2_32(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SpecificIntAllowPoison(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VScale(), llvm::PatternMatch::match(), llvm::Constant::mergeUndefsWith(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::SQ, llvm::Instruction::user_back(), X, and Y.
Instruction * InstCombinerImpl::visitShl | ( | BinaryOperator & | I | ) |
Definition at line 1034 of file InstCombineShifts.cpp.
References llvm::AllOnes, B, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, CC, commonShiftTransforms(), llvm::BinaryOperator::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateTrunc(), dropRedundantMaskingOfLeftShiftInput(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::APInt::getHighBitsSet(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::BinaryOperator::getOpcode(), getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::APInt::getSignMask(), llvm::SimplifyQuery::getWithInstruction(), llvm::APInt::getZExtValue(), I, llvm::IRBuilderBase::Insert(), llvm::Instruction::isCommutative(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), setShiftFlags(), llvm::APInt::shl(), llvm::simplifyShlInst(), llvm::InstCombiner::SQ, std::swap(), llvm::APInt::ult(), X, and Y.
Instruction * InstCombinerImpl::visitShuffleVectorInst | ( | ShuffleVectorInst & | SVI | ) |
Definition at line 2791 of file InstCombineVectorOps.cpp.
References assert(), llvm::InstCombiner::Builder, canEvaluateShuffled(), canonicalizeInsertSplat(), llvm::ShuffleVectorInst::commute(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::contains(), llvm::CastInst::Create(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateExtractElement(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::createUnaryMask(), llvm::InstCombiner::DL, evaluateInDifferentElementOrder(), foldCastShuffle(), foldIdentityExtractShuffle(), foldIdentityPaddedShuffles(), foldSelectShuffle(), foldShuffleOfUnaryOps(), foldShuffleWithInsert(), foldTruncShuffle(), llvm::FixedVectorType::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::APInt::getAllOnes(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), llvm::SimplifyQuery::getWithInstruction(), llvm::Value::hasOneUse(), I, Idx, llvm::DataLayout::isBigEndian(), isShuffleExtractingFromLHS(), isSplat(), llvm::VectorType::isValidElementType(), LHS, llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), narrowVectorSelect(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), RHS, llvm::scaleShuffleMaskElts(), simplifyBinOpSplats(), SimplifyDemandedVectorElts(), llvm::simplifyShuffleVectorInst(), llvm::InstCombiner::SQ, llvm::Value::users(), X, and Y.
Instruction * InstCombinerImpl::visitSIToFP | ( | CastInst & | CI | ) |
Definition at line 1997 of file InstCombineCasts.cpp.
References commonCastTransforms(), llvm::CastInst::Create(), llvm::User::getOperand(), llvm::Value::getType(), llvm::isKnownNonNegative(), and llvm::InstCombiner::SQ.
Instruction * InstCombinerImpl::visitSRem | ( | BinaryOperator & | I | ) |
Definition at line 2236 of file InstCombineMulDivRem.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, commonIRemTransforms(), llvm::BinaryOperator::CreateNSWNeg(), llvm::IRBuilderBase::CreateSRem(), foldVectorBinop(), llvm::ConstantVector::get(), llvm::ConstantExpr::getNeg(), llvm::APInt::getSignMask(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::PatternMatch::m_Negative(), llvm::PatternMatch::m_NSWNeg(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Value(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::InstCombiner::replaceOperand(), RHS, llvm::simplifySRemInst(), llvm::InstCombiner::SQ, X, and Y.
Instruction * InstCombinerImpl::visitStoreInst | ( | StoreInst & | SI | ) |
Definition at line 1353 of file InstCombineLoadStoreAlloca.cpp.
References llvm::InstCombiner::AA, llvm::InstCombiner::AC, assert(), canSimplifyNullStoreOrGEP(), combineStoreToValueType(), llvm::InstCombiner::DL, llvm::InstCombiner::DT, llvm::EnableInferAlignmentPass, equivalentAddressValues(), eraseInstFromFunction(), GEP, llvm::PoisonValue::get(), llvm::AAResults::getModRefInfoMask(), llvm::getOrEnforceKnownAlignment(), llvm::DataLayout::getPrefTypeAlign(), llvm::Value::getType(), handlePotentiallyDeadBlocks(), handleUnreachableFrom(), llvm::isModSet(), llvm::InstCombiner::LI, Ptr, llvm::InstructionWorklist::push(), removeInstructionsBeforeUnreachable(), replaceGEPIdxWithZero(), llvm::InstCombiner::replaceOperand(), unpackStoreToAggregate(), and llvm::InstCombiner::Worklist.
Instruction * InstCombinerImpl::visitSub | ( | BinaryOperator & | I | ) |
Definition at line 2116 of file InstCombineAddSub.cpp.
References A, llvm::Add, llvm::InstCombiner::AddOne(), llvm::And, assert(), B, llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(), llvm::computeKnownBits(), Cond, llvm::Instruction::copyMetadata(), llvm::APInt::countr_zero(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateBinaryIntrinsic(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateIsNeg(), llvm::IRBuilderBase::CreateMul(), llvm::BinaryOperator::CreateNeg(), llvm::IRBuilderBase::CreateNeg(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateXor(), factorizeMathWithShlOps(), foldBinOpOfSelectAndCastOfSelectCondition(), foldBinopWithPhiOperands(), foldOpIntoPhi(), FoldOpIntoSelect(), foldSubOfMinMax(), foldUsingDistributiveLaws(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::InstCombiner::getFreelyInverted(), llvm::APInt::getHighBitsSet(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::IRBuilderBase::getTrue(), llvm::Value::getType(), llvm::SimplifyQuery::getWithInstruction(), llvm::SimplifyQuery::getWithoutDomCondCache(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::Value::hasNUsesOrMore(), llvm::Value::hasOneUse(), I, llvm::InstCombiner::isFreeToInvert(), llvm::APInt::isMask(), llvm::APInt::isNegatedPowerOf2(), llvm::APInt::isSubsetOf(), isZero(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_MaxOrMin(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_SMax(), llvm::PatternMatch::m_c_SMin(), llvm::PatternMatch::m_c_UMax(), llvm::PatternMatch::m_c_UMin(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_PtrToInt(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::Mul, llvm::Negator::Negate(), llvm::none_of(), OptimizePointerDifference(), llvm::InstCombiner::replaceInstUsesWith(), RHS, Select, llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::simplifySubInst(), llvm::InstCombiner::SQ, llvm::InstCombiner::SubOne(), tryFoldInstWithCtpopWithNot(), X, Y, and llvm::KnownBits::Zero.
Instruction * InstCombinerImpl::visitSwitchInst | ( | SwitchInst & | SI | ) |
Definition at line 3744 of file InstructionCombining.cpp.
References llvm::all_of(), llvm::APInt::ashr(), assert(), llvm::BitWidth, llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::InstCombiner::computeKnownBits(), Cond, llvm::KnownBits::countMinLeadingOnes(), llvm::KnownBits::countMinLeadingZeros(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateTrunc(), llvm::IntegerType::get(), llvm::KnownBits::getBitWidth(), llvm::APInt::getLowBitsSet(), llvm::Type::getScalarSizeInBits(), getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), getType(), handlePotentiallyDeadSuccessors(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), llvm::Value::hasOneUse(), llvm::APInt::lshr(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), Select, llvm::IRBuilderBase::SetInsertPoint(), simplifySwitchOnSelectUsingRanges(), and llvm::APInt::trunc().
Instruction * InstCombinerImpl::visitTrunc | ( | TruncInst & | CI | ) |
Definition at line 677 of file InstCombineCasts.cpp.
References A, llvm::And, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canEvaluateTruncated(), commonCastTransforms(), llvm::InstCombiner::ComputeMaxSignificantBits(), llvm::ConstantFoldCastOperand(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldSelectInstruction(), llvm::BinaryOperator::Create(), llvm::ExtractElementInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateAShr(), llvm::IRBuilderBase::CreateBitCast(), llvm::CastInst::CreateIntegerCast(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateVScale(), llvm::dbgs(), llvm::InstCombiner::DL, EvaluateInDifferentType(), llvm::APInt::exactLogBase2(), foldVecTruncToExtElt(), llvm::VectorType::get(), llvm::APInt::getBitsSetFrom(), llvm::Function::getFnAttribute(), llvm::Instruction::getFunction(), llvm::IRBuilderBase::getInt32(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::ConstantExpr::getSub(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::Attribute::getVScaleRangeMax(), llvm::ConstantInt::getZExtValue(), llvm::Function::hasFnAttribute(), llvm::TruncInst::hasNoSignedWrap(), llvm::TruncInst::hasNoUnsignedWrap(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::DataLayout::isBigEndian(), llvm::Type::isVectorTy(), LHS, LLVM_DEBUG, llvm::Log2_32(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ExtractElt(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Shr(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VScale(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_ZExt(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), llvm::Constant::mergeUndefsWith(), llvm::InstCombiner::replaceInstUsesWith(), RHS, llvm::TruncInst::setHasNoSignedWrap(), llvm::TruncInst::setHasNoUnsignedWrap(), shrinkInsertElt(), shrinkSplatShuffle(), SimplifyDemandedInstructionBits(), llvm::SPF_UNKNOWN, X, and Y.
Instruction * InstCombinerImpl::visitUDiv | ( | BinaryOperator & | I | ) |
Definition at line 1514 of file InstCombineMulDivRem.cpp.
References A, B, llvm::InstCombiner::Builder, commonIDivTransforms(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpUGE(), llvm::IRBuilderBase::CreateLShr(), llvm::CastInst::CreateZExtOrBitCast(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Exact(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Negative(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), narrowUDivURem(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setIsExact(), llvm::simplifyUDivInst(), llvm::InstCombiner::SQ, takeLog2(), llvm::APInt::ushl_ov(), and X.
Instruction * InstCombinerImpl::visitUIToFP | ( | CastInst & | CI | ) |
Definition at line 1987 of file InstCombineCasts.cpp.
References commonCastTransforms(), llvm::User::getOperand(), llvm::Instruction::hasNonNeg(), llvm::isKnownNonNegative(), llvm::Instruction::setNonNeg(), and llvm::InstCombiner::SQ.
Instruction * InstCombinerImpl::visitUnconditionalBranchInst | ( | BranchInst & | BI | ) |
Definition at line 3544 of file InstructionCombining.cpp.
References assert(), llvm::BranchInst::isUnconditional(), and mergeStoreIntoSuccessor().
Referenced by visitBranchInst().
Instruction * InstCombinerImpl::visitUnreachableInst | ( | UnreachableInst & | I | ) |
Definition at line 3539 of file InstructionCombining.cpp.
References I, and removeInstructionsBeforeUnreachable().
Instruction * InstCombinerImpl::visitURem | ( | BinaryOperator & | I | ) |
Definition at line 2164 of file InstCombineMulDivRem.cpp.
References llvm::Add, llvm::InstCombiner::Builder, commonIRemTransforms(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpNE(), llvm::IRBuilderBase::CreateICmpULT(), llvm::IRBuilderBase::CreateSub(), llvm::CastInst::CreateZExtOrBitCast(), foldVectorBinop(), llvm::Constant::getAllOnesValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::CmpInst::ICMP_ULT, llvm::isGuaranteedNotToBeUndef(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_Negative(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), narrowUDivURem(), llvm::InstCombiner::replaceInstUsesWith(), llvm::simplifyICmpInst(), llvm::simplifyURemInst(), llvm::InstCombiner::SQ, and X.
Instruction * InstCombinerImpl::visitVAEndInst | ( | VAEndInst & | I | ) |
Definition at line 803 of file InstCombineCalls.cpp.
References I, and removeTriviallyEmptyRange().
Instruction * InstCombinerImpl::visitXor | ( | BinaryOperator & | I | ) |
Definition at line 4642 of file InstCombineAndOrXor.cpp.
References A, llvm::And, assert(), B, llvm::InstCombiner::Builder, llvm::CallingConv::C, canonicalizeAbs(), canonicalizeLogicFirst(), llvm::CallInst::Create(), llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateFNeg(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateIsNotNeg(), llvm::IRBuilderBase::CreateLShr(), llvm::BinaryOperator::CreateNot(), llvm::IRBuilderBase::CreateNot(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateXor(), D, F, foldBinOpIntoSelectOrPhi(), foldBinOpShiftWithShift(), foldBinopWithPhiOperands(), foldBitwiseLogicWithIntrinsics(), foldUsingDistributiveLaws(), foldVectorBinop(), foldXorToXor(), llvm::APInt::getAllOnes(), llvm::Constant::getAllOnesValue(), llvm::Intrinsic::getDeclaration(), llvm::IRBuilderBase::GetInsertBlock(), llvm::ConstantExpr::getNot(), llvm::BasicBlock::getParent(), llvm::Type::getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::IRBuilderBase::getTrue(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::SimplifyQuery::getWithInstruction(), llvm::ConstantExpr::getXor(), llvm::Function::hasFnAttribute(), llvm::Value::hasOneUse(), I, II, llvm::Type::isFloatingPointTy(), llvm::isGuaranteedNotToBeUndef(), llvm::Type::isIEEE(), llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::APInt::isSignMask(), llvm::Constant::isZeroValue(), LHS, llvm::APInt::lshr(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_APIntAllowPoison(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantExpr(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ElementWiseBitCast(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SignMask(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_TruncOrSelf(), llvm::PatternMatch::m_Unless(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::Constant::mergeUndefsWith(), llvm::Or, reassociateForUses(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Constant::replaceUndefsWith(), RHS, llvm::APInt::shl(), SimplifyAssociativeOrCommutative(), SimplifyDemandedInstructionBits(), llvm::simplifyXorInst(), llvm::InstCombiner::SQ, std::swap(), llvm::Value::takeName(), visitMaskedMerge(), X, llvm::Xor, and Y.
Instruction * InstCombinerImpl::visitZExt | ( | ZExtInst & | Zext | ) |
Definition at line 1138 of file InstCombineCasts.cpp.
References A, llvm::And, assert(), llvm::InstCombiner::Builder, llvm::CallingConv::C, canEvaluateZExtd(), commonCastTransforms(), llvm::IRBuilderBase::CreateAnd(), llvm::IRBuilderBase::CreateTrunc(), llvm::IRBuilderBase::CreateVScale(), llvm::IRBuilderBase::CreateZExt(), llvm::dbgs(), llvm::InstCombiner::DT, EvaluateInDifferentType(), llvm::Function::getFnAttribute(), llvm::Instruction::getFunction(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLowBitsSet(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), getScalarSizeInBits(), llvm::Value::getType(), llvm::Attribute::getVScaleRangeMax(), llvm::SimplifyQuery::getWithInstruction(), llvm::Function::hasFnAttribute(), llvm::Instruction::hasNonNeg(), llvm::Value::hasOneUse(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownNonNegative(), LLVM_DEBUG, llvm::Log2_32(), llvm::Log2_64_Ceil(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shift(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_VScale(), llvm::PatternMatch::m_Xor(), llvm::InstCombiner::MaskedValueIsZero(), llvm::PatternMatch::match(), llvm::replaceAllDbgUsesWith(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setNonNeg(), llvm::InstCombiner::SQ, llvm::Instruction::user_back(), and X.