LLVM 22.0.0git
|
#include "InstCombineInternal.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LastRunTrackingAnalysis.h"
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetFolder.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugCounter.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/KnownFPClass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "llvm/Transforms/Utils/InstructionWorklist.h"
Go to the source code of this file.
Classes | |
class | AliasScopeTracker |
Namespaces | |
namespace | llvm |
This is an optimization pass for GlobalISel generic memory operations. |
Macros | |
#define | DEBUG_TYPE "instcombine" |
Functions | |
STATISTIC (NumWorklistIterations, "Number of instruction combining iterations performed") | |
STATISTIC (NumOneIteration, "Number of functions with one iteration") | |
STATISTIC (NumTwoIterations, "Number of functions with two iterations") | |
STATISTIC (NumThreeIterations, "Number of functions with three iterations") | |
STATISTIC (NumFourOrMoreIterations, "Number of functions with four or more iterations") | |
STATISTIC (NumCombined, "Number of insts combined") | |
STATISTIC (NumConstProp, "Number of constant folds") | |
STATISTIC (NumDeadInst, "Number of dead inst eliminated") | |
STATISTIC (NumSunkInst, "Number of instructions sunk") | |
STATISTIC (NumExpand, "Number of expansions") | |
STATISTIC (NumFactor, "Number of factorizations") | |
STATISTIC (NumReassoc, "Number of reassociations") | |
DEBUG_COUNTER (VisitCounter, "instcombine-visit", "Controls which instructions are visited") | |
static bool | maintainNoSignedWrap (BinaryOperator &I, Value *B, Value *C) |
static bool | hasNoUnsignedWrap (BinaryOperator &I) |
static bool | hasNoSignedWrap (BinaryOperator &I) |
static void | ClearSubclassDataAfterReassociation (BinaryOperator &I) |
Conservatively clears subclassOptionalData after a reassociation or commutation. | |
static bool | simplifyAssocCastAssoc (BinaryOperator *BinOp1, InstCombinerImpl &IC) |
Combine constant operands of associative operations either before or after a cast to eliminate one of the associative operations: (op (cast (op X, C2)), C1) --> (cast (op X, op (C1, C2))) (op (cast (op X, C2)), C1) --> (op (cast X), op (C1, C2)) | |
static bool | leftDistributesOverRight (Instruction::BinaryOps LOp, Instruction::BinaryOps ROp) |
Return whether "X LOp (Y ROp Z)" is always equal to "(X LOp Y) ROp (X LOp Z)". | |
static bool | rightDistributesOverLeft (Instruction::BinaryOps LOp, Instruction::BinaryOps ROp) |
Return whether "(X LOp Y) ROp Z" is always equal to "(X ROp Z) LOp (Y ROp Z)". | |
static Value * | getIdentityValue (Instruction::BinaryOps Opcode, Value *V) |
This function returns identity value for given opcode, which can be used to factor patterns like (X * 2) + X ==> (X * 2) + (X * 1) ==> X * (2 + 1). | |
static Instruction::BinaryOps | getBinOpsForFactorization (Instruction::BinaryOps TopOpcode, BinaryOperator *Op, Value *&LHS, Value *&RHS, BinaryOperator *OtherOp) |
This function predicates factorization using distributive laws. | |
static Value * | tryFactorization (BinaryOperator &I, const SimplifyQuery &SQ, InstCombiner::BuilderTy &Builder, Instruction::BinaryOps InnerOpcode, Value *A, Value *B, Value *C, Value *D) |
This tries to simplify binary operations by factorizing out common terms (e. | |
static std::optional< std::pair< Value *, Value * > > | matchSymmetricPhiNodesPair (PHINode *LHS, PHINode *RHS) |
static Value * | simplifyOperationIntoSelectOperand (Instruction &I, SelectInst *SI, bool IsTrueArm) |
static Value * | foldOperationIntoSelectOperand (Instruction &I, SelectInst *SI, Value *NewOp, InstCombiner &IC) |
static Value * | simplifyInstructionWithPHI (Instruction &I, PHINode *PN, Value *InValue, BasicBlock *InBB, const DataLayout &DL, const SimplifyQuery SQ) |
static bool | shouldMergeGEPs (GEPOperator &GEP, GEPOperator &Src) |
static GEPNoWrapFlags | getMergedGEPNoWrapFlags (GEPOperator &GEP1, GEPOperator &GEP2) |
Determine nowrap flags for (gep (gep p, x), y) to (gep p, (x + y)) transform. | |
static Instruction * | foldSelectGEP (GetElementPtrInst &GEP, InstCombiner::BuilderTy &Builder) |
Thread a GEP operation with constant indices through the constant true/false arms of a select. | |
static Instruction * | canonicalizeGEPOfConstGEPI8 (GetElementPtrInst &GEP, GEPOperator *Src, InstCombinerImpl &IC) |
static Instruction * | combineConstantOffsets (GetElementPtrInst &GEP, InstCombinerImpl &IC) |
Combine constant offsets separated by variable offsets. | |
static bool | shouldCanonicalizeGEPToPtrAdd (GetElementPtrInst &GEP) |
Return true if we should canonicalize the gep to an i8 ptradd. | |
static Instruction * | foldGEPOfPhi (GetElementPtrInst &GEP, PHINode *PN, IRBuilderBase &Builder) |
static bool | isNeverEqualToUnescapedAlloc (Value *V, const TargetLibraryInfo &TLI, Instruction *AI) |
static bool | isRemovableWrite (CallBase &CB, Value *UsedV, const TargetLibraryInfo &TLI) |
Given a call CB which uses an address UsedV, return true if we can prove the call's only possible effect is storing to V. | |
static std::optional< ModRefInfo > | isAllocSiteRemovable (Instruction *AI, SmallVectorImpl< WeakTrackingVH > &Users, const TargetLibraryInfo &TLI, bool KnowInit) |
static Instruction * | tryToMoveFreeBeforeNullTest (CallInst &FI, const DataLayout &DL) |
Move the call to free before a NULL test. | |
static Value * | simplifySwitchOnSelectUsingRanges (SwitchInst &SI, SelectInst *Select, bool IsTrueArm) |
static Value * | foldFrexpOfSelect (ExtractValueInst &EV, IntrinsicInst *FrexpCall, SelectInst *SelectInst, InstCombiner::BuilderTy &Builder) |
static bool | isCatchAll (EHPersonality Personality, Constant *TypeInfo) |
Return 'true' if the given typeinfo will match anything. | |
static bool | shorter_filter (const Value *LHS, const Value *RHS) |
static bool | isUsedWithinShuffleVector (Value *V) |
static bool | SoleWriteToDeadLocal (Instruction *I, TargetLibraryInfo &TLI) |
Check for case where the call writes to an otherwise dead alloca. | |
static bool | combineInstructionsOverFunction (Function &F, InstructionWorklist &Worklist, AliasAnalysis *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI, ProfileSummaryInfo *PSI, const InstCombineOptions &Opts) |
INITIALIZE_PASS_BEGIN (InstructionCombiningPass, "instcombine", "Combine redundant instructions", false, false) INITIALIZE_PASS_END(InstructionCombiningPass |
Variables | |
static cl::opt< bool > | llvm::EnableCodeSinking ("instcombine-code-sinking", cl::desc("Enable code sinking"), cl::init(true)) |
static cl::opt< unsigned > | llvm::MaxSinkNumUsers ("instcombine-max-sink-users", cl::init(32), cl::desc("Maximum number of undroppable users for instruction sinking")) |
static cl::opt< unsigned > | llvm::MaxArraySize ("instcombine-maxarray-size", cl::init(1024), cl::desc("Maximum array size considered when doing a combine")) |
static cl::opt< unsigned > | llvm::ShouldLowerDbgDeclare ("instcombine-lower-dbg-declare", cl::Hidden, cl::init(true)) |
instcombine | |
Combine redundant | instructions |
Combine redundant | false |
#define DEBUG_TYPE "instcombine" |
Definition at line 110 of file InstructionCombining.cpp.
|
static |
Definition at line 2643 of file InstructionCombining.cpp.
References llvm::sampleprof::Base, llvm::InstCombiner::Builder, llvm::cast(), llvm::GetElementPtrInst::Create(), llvm::IRBuilderBase::CreatePtrAdd(), DL, GEP, llvm::APInt::getBitWidth(), llvm::InstCombiner::getDataLayout(), llvm::IRBuilderBase::getInt(), llvm::Type::getScalarType(), llvm::GEPNoWrapFlags::inBounds(), llvm::isa(), llvm::APInt::isZero(), llvm::PatternMatch::m_AddLike(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_PtrAdd(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::GEPNoWrapFlags::none(), and llvm::GEPNoWrapFlags::noUnsignedWrap().
Referenced by llvm::InstCombinerImpl::visitGEPOfGEP().
|
static |
Conservatively clears subclassOptionalData after a reassociation or commutation.
We preserve fast-math flags when applicable as they can be preserved.
Definition at line 400 of file InstructionCombining.cpp.
References llvm::dyn_cast(), and I.
Referenced by llvm::InstCombinerImpl::SimplifyAssociativeOrCommutative().
|
static |
Combine constant offsets separated by variable offsets.
ptradd (ptradd (ptradd p, C1), x), C2 -> ptradd (ptradd p, x), C1+C2
Definition at line 2688 of file InstructionCombining.cpp.
References llvm::GEPNoWrapFlags::all(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreatePtrAdd(), DL, llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::front(), GEP, llvm::InstCombiner::getDataLayout(), llvm::IRBuilderBase::getInt(), llvm::GEPNoWrapFlags::intersectForOffsetAdd(), llvm::GEPNoWrapFlags::intersectForReassociate(), llvm::Offset, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), and llvm::InstCombiner::replaceOperand().
Referenced by llvm::InstCombinerImpl::visitGEPOfGEP().
|
static |
Builder - This is an IRBuilder that automatically inserts new instructions into the worklist when they are created.
Definition at line 5926 of file InstructionCombining.cpp.
References llvm::InstructionWorklist::add(), llvm::dbgs(), DL, llvm::dyn_cast(), F, I, LLVM_DEBUG, llvm::LowerDbgDeclare(), llvm::MaxArraySize, llvm::InstCombiner::MaxArraySizeForCombine, llvm::InstCombineOptions::MaxIterations, llvm::InstCombinerImpl::prepareWorklist(), llvm::AssumptionCache::registerAssumption(), llvm::reportFatalUsageError(), llvm::InstCombinerImpl::run(), llvm::ShouldLowerDbgDeclare, and llvm::InstCombineOptions::VerifyFixpoint.
Referenced by llvm::InstCombinePass::run(), and llvm::InstructionCombiningPass::runOnFunction().
DEBUG_COUNTER | ( | VisitCounter | , |
"instcombine-visit" | , | ||
"Controls which instructions are visited" | ) |
|
static |
Definition at line 4451 of file InstructionCombining.cpp.
References Cond, llvm::Instruction::copyIRFlags(), llvm::frexp(), llvm::CallBase::getCalledFunction(), llvm::SelectInst::getCondition(), llvm::SelectInst::getFalseValue(), llvm::SelectInst::getTrueValue(), llvm::Value::hasOneUse(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::match(), and llvm::APFloatBase::rmNearestTiesToEven.
Referenced by llvm::InstCombinerImpl::visitExtractValueInst().
|
static |
Definition at line 3024 of file InstructionCombining.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::cast(), llvm::dyn_cast(), E(), F, GEP, llvm::PHINode::getIncomingBlock(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::GetElementPtrInst::getTypeAtIndex(), llvm::Value::hasOneUse(), I, llvm::Type::isStructTy(), llvm::User::op_begin(), llvm::User::op_end(), and llvm::User::operands().
Referenced by llvm::InstCombinerImpl::visitGetElementPtrInst().
|
static |
Definition at line 1767 of file InstructionCombining.cpp.
References llvm::Instruction::dropUBImplyingAttrsAndMetadata(), I, llvm::InstCombiner::InsertNewInstBefore(), and llvm::User::replaceUsesOfWith().
Referenced by llvm::InstCombinerImpl::FoldOpIntoSelect().
|
static |
Thread a GEP operation with constant indices through the constant true/false arms of a select.
Definition at line 2616 of file InstructionCombining.cpp.
References Cond, llvm::SelectInst::Create(), GEP, llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitGetElementPtrInst().
|
static |
This function predicates factorization using distributive laws.
By default, it just returns the 'Op' inputs. But for special-cases like 'add(shl(X, 5), ...)', this function will have TopOpcode == Instruction::Add and Op = shl(X, 5). The 'shl' is treated as the more general 'mul X, 32' to allow more factorization opportunities.
Definition at line 719 of file InstructionCombining.cpp.
References assert(), llvm::CallingConv::C, llvm::ConstantFoldBinaryInstruction(), llvm::BinaryOperator::getOpcode(), llvm::Instruction::isBitwiseLogicOp(), LHS, llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_NonNegative(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and RHS.
Referenced by llvm::InstCombinerImpl::tryFactorizationFolds().
|
static |
This function returns identity value for given opcode, which can be used to factor patterns like (X * 2) + X ==> (X * 2) + (X * 1) ==> X * (2 + 1).
Definition at line 706 of file InstructionCombining.cpp.
References llvm::ConstantExpr::getBinOpIdentity(), and llvm::isa().
Referenced by llvm::InstCombinerImpl::tryFactorizationFolds().
|
static |
Determine nowrap flags for (gep (gep p, x), y) to (gep p, (x + y)) transform.
Definition at line 2609 of file InstructionCombining.cpp.
References llvm::GEPOperator::getNoWrapFlags(), and llvm::GEPNoWrapFlags::intersectForOffsetAdd().
Referenced by llvm::InstCombinerImpl::visitGEPOfGEP().
|
static |
Definition at line 392 of file InstructionCombining.cpp.
References llvm::dyn_cast(), and I.
Referenced by llvm::SDNode::print_details(), llvm::InstCombinerImpl::SimplifyAssociativeOrCommutative(), llvm::InstCombinerImpl::visitCallInst(), llvm::InstCombinerImpl::visitLShr(), and llvm::InstCombinerImpl::visitMul().
|
static |
Definition at line 387 of file InstructionCombining.cpp.
References llvm::dyn_cast(), and I.
Referenced by llvm::InstCombinerImpl::commonIDivTransforms(), computeKnownBitsFromCond(), computeKnownBitsFromICmpCond(), getSmallConstantTripCount(), isTruePredicate(), llvm::SDNode::print_details(), llvm::InstCombinerImpl::SimplifyAssociativeOrCommutative(), llvm::InstCombinerImpl::visitAShr(), and llvm::InstCombinerImpl::visitLShr().
INITIALIZE_PASS_BEGIN | ( | InstructionCombiningPass | , |
"instcombine" | , | ||
"Combine redundant instructions" | , | ||
false | , | ||
false | ) |
References INITIALIZE_PASS_DEPENDENCY.
|
static |
Definition at line 3519 of file InstructionCombining.cpp.
References Access, assert(), llvm::cast(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::getAllocationFamily(), llvm::getFreedOperand(), llvm::TargetLibraryInfo::getLibFunc(), llvm::User::getOperand(), llvm::LoadInst::getPointerOperand(), llvm::getReallocatedOperand(), llvm::TargetLibraryInfo::has(), I, II, llvm::ICmpInst::isEquality(), llvm::isModSet(), isNeverEqualToUnescapedAlloc(), llvm::APInt::isPowerOf2(), llvm::isRefSet(), isRemovableWrite(), llvm::LoadInst::isVolatile(), llvm_unreachable, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), MI, llvm::Mod, llvm::ModRef, llvm::NoModRef, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Ref, Size, Users, and llvm::Value::users().
Referenced by llvm::InstCombinerImpl::visitAllocSite().
|
static |
Return 'true' if the given typeinfo will match anything.
Definition at line 4624 of file InstructionCombining.cpp.
References llvm::CoreCLR, llvm::GNU_Ada, llvm::GNU_C, llvm::GNU_C_SjLj, llvm::GNU_CXX, llvm::GNU_CXX_SjLj, llvm::GNU_ObjC, llvm::Constant::isNullValue(), llvm_unreachable, llvm::MSVC_CXX, llvm::MSVC_TableSEH, llvm::MSVC_X86SEH, llvm::Rust, llvm::Unknown, llvm::Wasm_CXX, llvm::XL_CXX, and llvm::ZOS_CXX.
Referenced by llvm::InstCombinerImpl::visitLandingPadInst().
|
static |
Definition at line 3486 of file InstructionCombining.cpp.
References llvm::dyn_cast(), llvm::isa(), and llvm::isAllocLikeFn().
Referenced by isAllocSiteRemovable().
|
static |
Given a call CB which uses an address UsedV, return true if we can prove the call's only possible effect is storing to V.
Definition at line 3498 of file InstructionCombining.cpp.
References llvm::CallBase::doesNotThrow(), llvm::MemoryLocation::getForDest(), llvm::Instruction::isTerminator(), llvm::Value::use_empty(), and llvm::Instruction::willReturn().
Referenced by isAllocSiteRemovable().
Definition at line 5145 of file InstructionCombining.cpp.
References llvm::isa(), isUsedWithinShuffleVector(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_Specific(), and llvm::PatternMatch::match().
Referenced by isUsedWithinShuffleVector(), and llvm::InstCombinerImpl::visitFreeze().
|
static |
Return whether "X LOp (Y ROp Z)" is always equal to "(X LOp Y) ROp (X LOp Z)".
Definition at line 670 of file InstructionCombining.cpp.
|
static |
Definition at line 359 of file InstructionCombining.cpp.
References B(), llvm::CallingConv::C, llvm::dyn_cast(), I, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), llvm::APInt::sadd_ov(), llvm::APInt::smul_ov(), and llvm::APInt::ssub_ov().
Referenced by llvm::InstCombinerImpl::SimplifyAssociativeOrCommutative().
|
static |
Definition at line 1298 of file InstructionCombining.cpp.
References E(), llvm::equal(), I, LHS, and RHS.
|
static |
Return whether "(X LOp Y) ROp Z" is always equal to "(X ROp Z) LOp (Y ROp Z)".
Definition at line 691 of file InstructionCombining.cpp.
References llvm::Instruction::isBitwiseLogicOp(), llvm::Instruction::isCommutative(), llvm::Instruction::isShift(), and leftDistributesOverRight().
Referenced by llvm::InstCombinerImpl::foldUsingDistributiveLaws(), and tryFactorization().
Definition at line 4653 of file InstructionCombining.cpp.
References llvm::cast(), LHS, and RHS.
Referenced by llvm::InstCombinerImpl::visitLandingPadInst().
|
static |
Return true if we should canonicalize the gep to an i8 ptradd.
Definition at line 2995 of file InstructionCombining.cpp.
References llvm::any_of(), llvm::dyn_cast(), GEP, llvm::Type::isIntegerTy(), llvm::Type::isScalableTy(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Mul(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitGetElementPtrInst().
|
static |
Definition at line 2276 of file InstructionCombining.cpp.
References GEP.
Referenced by llvm::InstCombinerImpl::visitGEPOfGEP().
|
static |
Combine constant operands of associative operations either before or after a cast to eliminate one of the associative operations: (op (cast (op X, C2)), C1) --> (cast (op X, op (C1, C2))) (op (cast (op X, C2)), C1) --> (op (cast X), op (C1, C2))
Definition at line 416 of file InstructionCombining.cpp.
References llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldCastOperand(), DL, llvm::Instruction::dropPoisonGeneratingFlags(), llvm::dyn_cast(), llvm::InstCombiner::getDataLayout(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Instruction::isBitwiseLogicOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::match(), and llvm::InstCombiner::replaceOperand().
Referenced by llvm::InstCombinerImpl::SimplifyAssociativeOrCommutative().
|
static |
Definition at line 1829 of file InstructionCombining.cpp.
References AbstractManglingParser< Derived, Alloc >::Ops, DL, llvm::dyn_cast(), llvm::ConstantInt::getBool(), llvm::ICmpInst::getCmpPredicate(), llvm::BranchInst::getCondition(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::BranchInst::isConditional(), llvm::isImpliedCondition(), llvm::PatternMatch::m_ConstantExpr(), llvm::PatternMatch::match(), and llvm::simplifyInstructionWithOperands().
Referenced by llvm::InstCombinerImpl::foldOpIntoPhi().
|
static |
Definition at line 1745 of file InstructionCombining.cpp.
References AbstractManglingParser< Derived, Alloc >::Ops, I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::simplifyInstructionWithOperands().
Referenced by llvm::InstCombinerImpl::FoldOpIntoSelect().
|
static |
Definition at line 4208 of file InstructionCombining.cpp.
References llvm::CallingConv::C, llvm::ConstantRange::contains(), llvm::dyn_cast(), llvm::CmpInst::getInversePredicate(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), Select, and X.
Referenced by llvm::InstCombinerImpl::visitSwitchInst().
|
static |
Check for case where the call writes to an otherwise dead alloca.
This shows up for unused out-params in idiomatic C/C++ code. Note that this helper only analyzes the write; doesn't check any other legality aspect.
Definition at line 5279 of file InstructionCombining.cpp.
References llvm::cast(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::MemoryLocation::getForDest(), llvm::getUnderlyingObject(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isa(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::InstCombinerImpl::tryToSinkInstruction().
STATISTIC | ( | NumCombined | , |
"Number of insts combined" | ) |
STATISTIC | ( | NumConstProp | , |
"Number of constant folds" | ) |
STATISTIC | ( | NumDeadInst | , |
"Number of dead inst eliminated" | ) |
STATISTIC | ( | NumExpand | , |
"Number of expansions" | ) |
STATISTIC | ( | NumFactor | , |
"Number of factorizations" | ) |
STATISTIC | ( | NumFourOrMoreIterations | , |
"Number of functions with four or more iterations" | ) |
STATISTIC | ( | NumOneIteration | , |
"Number of functions with one iteration" | ) |
STATISTIC | ( | NumReassoc | , |
"Number of reassociations" | ) |
STATISTIC | ( | NumSunkInst | , |
"Number of instructions sunk" | ) |
STATISTIC | ( | NumThreeIterations | , |
"Number of functions with three iterations" | ) |
STATISTIC | ( | NumTwoIterations | , |
"Number of functions with two iterations" | ) |
STATISTIC | ( | NumWorklistIterations | , |
"Number of instruction combining iterations performed" | ) |
|
static |
This tries to simplify binary operations by factorizing out common terms (e.
g. "(A*B)+(A*C)" -> "A*(B+C)").
Definition at line 747 of file InstructionCombining.cpp.
References A(), assert(), B(), llvm::CallingConv::C, llvm::cast(), D(), llvm::dyn_cast(), llvm::SimplifyQuery::getWithInstruction(), I, llvm::isa(), llvm::Instruction::isCommutative(), llvm::APInt::isMinSignedValue(), leftDistributesOverRight(), LHS, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), RHS, rightDistributesOverLeft(), llvm::simplifyBinOp(), std::swap(), and llvm::Value::takeName().
Referenced by llvm::InstCombinerImpl::tryFactorizationFolds().
|
static |
Move the call to free before a NULL test.
Check if this free is accessed after its argument has been test against NULL (property 0). If yes, it is legal to move this call in its predecessor block.
The move is performed only if the block containing the call to free will be removed, i.e.:
The profitability is out-of concern here and this function should be called only if the caller knows this transformation would be profitable (e.g., for code size).
Definition at line 3832 of file InstructionCombining.cpp.
References assert(), DL, llvm::dyn_cast(), llvm::CallBase::getArgOperand(), llvm::CallBase::getAttributes(), llvm::Value::getContext(), llvm::Attribute::getDereferenceableBytes(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getSinglePredecessor(), llvm::BasicBlock::getTerminator(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::BasicBlock::instructionsWithoutDebug(), llvm::Attribute::isValid(), llvm::PatternMatch::m_Br(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_UnconditionalBr(), llvm::PatternMatch::m_Zero(), llvm::make_early_inc_range(), llvm::PatternMatch::match(), llvm::CallBase::setAttributes(), and llvm::BasicBlock::size().
Referenced by llvm::InstCombinerImpl::visitFree().
Combine redundant false |
Definition at line 6112 of file InstructionCombining.cpp.
instcombine |
Definition at line 6111 of file InstructionCombining.cpp.
Combine redundant instructions |
Definition at line 6112 of file InstructionCombining.cpp.