|
LLVM 24.0.0git
|
#include "llvm/Transforms/Scalar/LICM.h"#include "ScalarOptions.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/PriorityWorklist.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/AliasAnalysis.h"#include "llvm/Analysis/AliasSetTracker.h"#include "llvm/Analysis/AssumptionCache.h"#include "llvm/Analysis/CaptureTracking.h"#include "llvm/Analysis/DomTreeUpdater.h"#include "llvm/Analysis/GuardUtils.h"#include "llvm/Analysis/LazyBlockFrequencyInfo.h"#include "llvm/Analysis/Loads.h"#include "llvm/Analysis/LoopInfo.h"#include "llvm/Analysis/LoopIterator.h"#include "llvm/Analysis/LoopNestAnalysis.h"#include "llvm/Analysis/LoopPass.h"#include "llvm/Analysis/MemoryLocation.h"#include "llvm/Analysis/MemorySSA.h"#include "llvm/Analysis/MemorySSAUpdater.h"#include "llvm/Analysis/MustExecute.h"#include "llvm/Analysis/OptimizationRemarkEmitter.h"#include "llvm/Analysis/ScalarEvolution.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/IR/CFG.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DebugInfoMetadata.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/LLVMContext.h"#include "llvm/IR/Metadata.h"#include "llvm/IR/Module.h"#include "llvm/IR/PatternMatch.h"#include "llvm/IR/PredIteratorCache.h"#include "llvm/InitializePasses.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Transforms/Scalar.h"#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Transforms/Utils/LoopUtils.h"#include "llvm/Transforms/Utils/SSAUpdater.h"#include <algorithm>#include <utility>Go to the source code of this file.
Namespaces | |
| namespace | llvm |
| This is an optimization pass for GlobalISel generic memory operations. | |
Macros | |
| #define | DEBUG_TYPE "licm" |
Typedefs | |
| using | PointersAndHasReadsOutsideSet |
Functions | |
| STATISTIC (NumSunk, "Number of instructions sunk out of loop") | |
| STATISTIC (NumHoisted, "Number of instructions hoisted out of loop") | |
| STATISTIC (NumMovedLoads, "Number of load insts hoisted or sunk") | |
| STATISTIC (NumMovedCalls, "Number of call insts hoisted or sunk") | |
| STATISTIC (NumPromotionCandidates, "Number of promotion candidates") | |
| STATISTIC (NumLoadPromoted, "Number of load-only promotions") | |
| STATISTIC (NumLoadStorePromoted, "Number of load and store promotions") | |
| STATISTIC (NumMinMaxHoisted, "Number of min/max expressions hoisted out of the loop") | |
| STATISTIC (NumGEPsHoisted, "Number of geps reassociated and hoisted out of the loop") | |
| STATISTIC (NumAddSubHoisted, "Number of add/subtract expressions reassociated " "and hoisted out of the loop") | |
| STATISTIC (NumFPAssociationsHoisted, "Number of invariant FP expressions " "reassociated and hoisted out of the loop") | |
| STATISTIC (NumIntAssociationsHoisted, "Number of invariant int expressions " "reassociated and hoisted out of the loop") | |
| STATISTIC (NumBOAssociationsHoisted, "Number of invariant BinaryOp expressions " "reassociated and hoisted out of the loop") | |
| static bool | inSubLoop (BasicBlock *BB, Loop *CurLoop, LoopInfo *LI) |
| Little predicate that returns true if the specified basic block is in a subloop of the current one, not the current one itself. | |
| static bool | isNotUsedOrFoldableInLoop (const Instruction &I, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, TargetTransformInfo *TTI, bool &FoldableInLoop, bool LoopNestMode) |
| Return true if the only users of this instruction are outside of the loop. | |
| static void | hoist (Instruction &I, const LICMDependencies &Deps, const Loop *CurLoop, BasicBlock *Dest) |
| When an instruction is found to only use loop invariant operands that is safe to hoist, this instruction is called to do the dirty work. | |
| static bool | sink (Instruction &I, const LICMDependencies &Deps, const Loop *CurLoop) |
| When an instruction is found to only be used outside of the loop, this function moves it to the exit blocks and patches up SSA form as needed. | |
| static bool | isSafeToExecuteUnconditionally (Instruction &Inst, const DominatorTree *DT, const TargetLibraryInfo *TLI, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE, const Instruction *CtxI, AssumptionCache *AC, bool AllowSpeculation) |
| Only sink or hoist an instruction if it is not a trapping instruction, or if the instruction is known not to trap when moved to the preheader. | |
| static bool | noConflictingReadWrites (Instruction *I, Loop *CurLoop, const SinkAndHoistDependencies &Deps, SinkAndHoistLICMFlags &Flags) |
| static bool | pointerInvalidatedByLoop (const SinkAndHoistDependencies &Deps, MemoryUse *MU, Loop *CurLoop, Instruction &I, SinkAndHoistLICMFlags &Flags, bool InvariantGroup) |
| static bool | pointerInvalidatedByBlock (BasicBlock &BB, MemorySSA &MSSA, MemoryUse &MU) |
| static bool | hoistArithmetics (const ScalarOptions &Opts, Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Aggregates various functions for hoisting computations out of loop. | |
| static bool | hoistInsertPastInsert (InsertElementInst *Ins, const LICMDependencies &Deps, Loop *CurLoop, BasicBlock *HoistDest) |
| static Instruction * | cloneInstructionInExitBlock (Instruction &I, BasicBlock &ExitBlock, PHINode &PN, const LoopInfo *LI, const LoopSafetyInfo *SafetyInfo, MemorySSAUpdater &MSSAU) |
| static void | eraseInstruction (Instruction &I, const LICMDependencies &Deps) |
| static void | moveInstructionBefore (Instruction &I, BasicBlock::iterator Dest, const LICMDependencies &Deps) |
| static void | foreachMemoryAccess (MemorySSA *MSSA, Loop *L, function_ref< void(Instruction *)> Fn) |
| static SmallVector< PointersAndHasReadsOutsideSet, 0 > | collectPromotionCandidates (const LICMDependencies &Deps, const SmallPtrSetImpl< const MDNode * > &LoopLocalAliasScopes, Loop *L) |
| INITIALIZE_PASS_BEGIN (LegacyLICMPass, "licm", "Loop Invariant Code Motion", false, false) INITIALIZE_PASS_END(LegacyLICMPass | |
| static std::optional< uint64_t > | getConstantInsertionIndex (InsertElementInst *Ins) |
| static bool | isLoadInvariantInLoop (LoadInst *LI, DominatorTree *DT, Loop *CurLoop) |
| static bool | isHoistableAndSinkableInst (Instruction &I) |
| Return true if-and-only-if we know how to (mechanically) both hoist and sink a given instruction out of a loop. | |
| static bool | isOnlyMemoryAccess (const Instruction *I, const Loop *L, const MemorySSAUpdater &MSSAU) |
| Return true if I is the only Instruction with a MemoryAccess in L. | |
| static MemoryAccess * | getClobberingMemoryAccess (MemorySSA &MSSA, BatchAAResults &BAA, SinkAndHoistLICMFlags &Flags, MemoryUseOrDef *MA) |
| static bool | isTriviallyReplaceablePHI (const PHINode &PN, const Instruction &I) |
| Returns true if a PHINode is a trivially replaceable with an Instruction. | |
| static bool | isFoldableInLoop (const Instruction &I, const Loop *CurLoop, const TargetTransformInfo *TTI) |
| Return true if the instruction is foldable in the loop. | |
| static void | removeInstructionFromDeps (Instruction &I, const LICMDependencies &Deps) |
| static Instruction * | sinkThroughTriviallyReplaceablePHI (PHINode *TPN, Instruction *I, LoopInfo *LI, SmallDenseMap< BasicBlock *, Instruction *, 32 > &SunkCopies, const LoopSafetyInfo *SafetyInfo, const Loop *CurLoop, MemorySSAUpdater &MSSAU) |
| static bool | canSplitPredecessors (PHINode *PN, LoopSafetyInfo *SafetyInfo) |
| static void | splitPredecessorsOfLoopExit (PHINode *PN, DominatorTree *DT, LoopInfo *LI, const Loop *CurLoop, LoopSafetyInfo *SafetyInfo, MemorySSAUpdater *MSSAU) |
| static bool | isPotentiallyPromotable (const Instruction *I, const Loop *L) |
Returns whether I is a memory access that may be a candidate for promotion out of the loop L. | |
| static bool | hasAnyMDOperandsFrom (const MDNode *N, const SmallPtrSetImpl< const MDNode * > &Operands) |
Returns whether N has any operand from the set Operands. | |
| static SmallPtrSet< const StoreInst *, 8 > | collectStoresWithInvariantAATags (MemorySSA *MSSA, DominatorTree *DT, const SmallPtrSetImpl< const MDNode * > &LoopLocalAliasScopes, Loop *L) |
Returns the potentially promotable stores with AA tags that are valid along all non-unwinding execution paths of the loop L, which allows for the AA tags to be used when deciding promotions. | |
| static bool | hoistMinMax (Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Try to simplify things like (A < INV_1 AND icmp A < INV_2) into (A < min(INV_1, INV_2)), if INV_1 and INV_2 are both loop invariants and their minimun can be computed outside of loop, and X is not a loop-invariant. | |
| static bool | hoistGEP (Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Reassociate gep (gep ptr, idx1), idx2 to gep (gep ptr, idx2), idx1 if this allows hoisting the inner GEP. | |
| static bool | hoistAdd (ICmpInst::Predicate Pred, Value *VariantLHS, Value *InvariantRHS, ICmpInst &ICmp, Loop &L, const LICMDependencies &Deps) |
| Try to turn things like "LV + C1 < C2" into "LV < C2 - C1". | |
| static bool | hoistSub (ICmpInst::Predicate Pred, Value *VariantLHS, Value *InvariantRHS, ICmpInst &ICmp, Loop &L, const LICMDependencies &Deps) |
| Try to reassociate and hoist the following two patterns: LV - C1 < C2 --> LV < C1 + C2, C1 - LV < C2 --> LV > C1 - C2. | |
| static bool | hoistAddSub (Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Reassociate and hoist add/sub expressions. | |
| static bool | isReassociableOp (Instruction *I, unsigned IntOpcode, unsigned FPOpcode) |
| static bool | hoistMulAddAssociation (const ScalarOptions &Opts, Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Try to reassociate expressions like ((A1 * B1) + (A2 * B2) + ...) * C where A1, A2, ... and C are loop invariants into expressions like ((A1 * C * B1) + (A2 * C * B2) + ...) and hoist the (A1 * C), (A2 * C), ... invariant expressions. | |
| static bool | hoistBOAssociation (Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Reassociate associative binary expressions of the form. | |
| static bool | hoistSubAddAssociation (Instruction &I, Loop &L, const LICMDependencies &Deps) |
| Reassociate add/sub expressions of the form: | |
Variables | |
| licm | |
| Loop Invariant Code | Motion |
| Loop Invariant Code | false |
|
static |
Definition at line 1220 of file LICM.cpp.
References llvm::BasicBlock::canSplitPredecessors(), llvm::LoopSafetyInfo::getBlockColors(), llvm::BasicBlock::getFirstNonPHIIt(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::isa(), and llvm::predecessors().
Referenced by sink().
|
static |
Definition at line 1101 of file LICM.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::BasicBlock::begin(), llvm::MemorySSA::Beginning, llvm::cast(), llvm::CallInst::Create(), llvm::PHINode::Create(), llvm::MemorySSAUpdater::createMemoryAccessInBB(), llvm::dyn_cast(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::TinyPtrVector< EltTy >::front(), llvm::LoopSafetyInfo::getBlockColors(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getFirstNonPHIIt(), llvm::PHINode::getIncomingBlock(), llvm::MemorySSA::getMemoryAccess(), llvm::MemorySSAUpdater::getMemorySSA(), llvm::PHINode::getNumIncomingValues(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::OperandBundleUse::getTagID(), I, llvm::Instruction::insertBefore(), llvm::MemorySSAUpdater::insertDef(), llvm::MemorySSAUpdater::insertUse(), llvm::LLVMContext::OB_funclet, llvm::TinyPtrVector< EltTy >::size(), and llvm::LoopInfo::wouldBeOutOfLoopUseRequiringLCSSA().
Referenced by sinkThroughTriviallyReplaceablePHI().
|
static |
Definition at line 2040 of file LICM.cpp.
References llvm::SinkAndHoistDependencies::AA, llvm::AliasSetTracker::add(), llvm::AliasSetTracker::addWithoutAATags(), collectStoresWithInvariantAATags(), llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::SinkAndHoistDependencies::DT, llvm::dyn_cast(), llvm::SinkAndHoistDependencies::EEA, llvm::erase_if(), foreachMemoryAccess(), llvm::MemorySSAUpdater::getMemorySSA(), llvm::PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info >::getPointer(), I, llvm::SetVector< T, Vector, Set, N >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::ICFLoopSafetyInfo::isGuaranteedToExecute(), llvm::isModSet(), isPotentiallyPromotable(), llvm::isRefSet(), llvm::SinkAndHoistDependencies::MSSAU, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::LICMDependencies::SafetyInfo, and llvm::PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info >::setInt().
|
static |
Returns the potentially promotable stores with AA tags that are valid along all non-unwinding execution paths of the loop L, which allows for the AA tags to be used when deciding promotions.
Definition at line 1999 of file LICM.cpp.
References llvm::all_of(), llvm::any_of(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), foreachMemoryAccess(), llvm::MemoryLocation::get(), hasAnyMDOperandsFrom(), I, llvm::SmallPtrSetImpl< PtrType >::insert_range(), and isPotentiallyPromotable().
Referenced by collectPromotionCandidates().
|
static |
Definition at line 1185 of file LICM.cpp.
References I, and removeInstructionFromDeps().
Referenced by hoistAdd(), hoistBOAssociation(), hoistGEP(), hoistMinMax(), hoistMulAddAssociation(), llvm::hoistRegion(), hoistSub(), hoistSubAddAssociation(), llvm::promoteLoopAccessesToScalars(), sink(), and llvm::sinkRegion().
|
static |
Definition at line 1960 of file LICM.cpp.
References Access, Accesses, llvm::dyn_cast(), and llvm::MemorySSA::getBlockAccesses().
Referenced by collectPromotionCandidates(), and collectStoresWithInvariantAATags().
|
static |
Definition at line 873 of file LICM.cpp.
References llvm::MemorySSAWalker::getClobberingMemoryAccess(), llvm::MemoryUseOrDef::getDefiningAccess(), and llvm::MemorySSA::getSkipSelfWalker().
Referenced by noConflictingReadWrites(), and pointerInvalidatedByLoop().
|
static |
Definition at line 715 of file LICM.cpp.
References llvm::cast(), llvm::dyn_cast(), llvm::User::getOperand(), and llvm::InsertElementInst::getType().
Referenced by hoistInsertPastInsert().
|
static |
Returns whether N has any operand from the set Operands.
Definition at line 1989 of file LICM.cpp.
References llvm::any_of(), N, and Operands.
Referenced by collectStoresWithInvariantAATags().
|
static |
When an instruction is found to only use loop invariant operands that is safe to hoist, this instruction is called to do the dirty work.
Definition at line 1417 of file LICM.cpp.
References llvm::dbgs(), DEBUG_TYPE, llvm::SinkAndHoistDependencies::DT, llvm::OptimizationRemarkEmitter::emit(), llvm::BasicBlock::getFirstNonPHIIt(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getNameOrAsOperand(), llvm::BasicBlock::getTerminator(), I, llvm::isa(), llvm::ICFLoopSafetyInfo::isGuaranteedToExecute(), LLVM_DEBUG, moveInstructionBefore(), llvm::SinkAndHoistDependencies::ORE, and llvm::LICMDependencies::SafetyInfo.
Referenced by hoistInsertPastInsert(), and llvm::hoistRegion().
|
static |
Try to turn things like "LV + C1 < C2" into "LV < C2 - C1".
Here C1 and C2 are loop invariants and LV is a loop-variant.
Definition at line 2365 of file LICM.cpp.
References llvm::LICMDependencies::AC, assert(), llvm::cast(), llvm::computeOverflowForSignedSub(), llvm::computeOverflowForUnsignedSub(), DL, llvm::Instruction::dropPoisonGeneratingFlags(), llvm::SinkAndHoistDependencies::DT, eraseInstruction(), llvm::BasicBlock::getTerminator(), llvm::CmpInst::isSigned(), llvm::PatternMatch::m_NSWAddLike(), llvm::PatternMatch::m_NUWAddLike(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::NeverOverflows, Pred, llvm::salvageDebugInfo(), llvm::User::setOperand(), llvm::CmpInst::setPredicate(), and std::swap().
Referenced by hoistAddSub().
|
static |
Reassociate and hoist add/sub expressions.
Definition at line 2506 of file LICM.cpp.
References llvm::cast(), llvm::CmpInst::getSwappedPredicate(), hoistAdd(), hoistSub(), I, LHS, llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Pred, RHS, and std::swap().
Referenced by hoistArithmetics().
|
static |
Aggregates various functions for hoisting computations out of loop.
Definition at line 2812 of file LICM.cpp.
References hoistAddSub(), hoistBOAssociation(), hoistGEP(), hoistMinMax(), hoistMulAddAssociation(), hoistSubAddAssociation(), and I.
Referenced by llvm::hoistRegion().
|
static |
Reassociate associative binary expressions of the form.
where op is an associative BinOp, LV is a loop variant, and C1 and C2 are loop invariants that we want to hoist, noting that associativity implies commutativity.
Definition at line 2650 of file LICM.cpp.
References llvm::LICMDependencies::AC, llvm::OverflowTracking::AllKnownNonNegative, assert(), C1, llvm::computeOverflowForSignedAdd(), llvm::BinaryOperator::Create(), llvm::SinkAndHoistDependencies::DT, llvm::dyn_cast(), eraseInstruction(), llvm::DebugLoc::getDropped(), llvm::Value::getName(), llvm::BasicBlock::getTerminator(), I, llvm::NeverOverflows, llvm::salvageDebugInfo(), and std::swap().
Referenced by hoistArithmetics().
|
static |
Reassociate gep (gep ptr, idx1), idx2 to gep (gep ptr, idx2), idx1 if this allows hoisting the inner GEP.
Definition at line 2308 of file LICM.cpp.
References llvm::LICMDependencies::AC, llvm::all_of(), DL, llvm::SinkAndHoistDependencies::DT, llvm::dyn_cast(), eraseInstruction(), GEP, llvm::BasicBlock::getTerminator(), I, llvm::isKnownNonNegative(), NonNegative, llvm::salvageDebugInfo(), and V.
Referenced by hoistArithmetics().
|
static |
Definition at line 730 of file LICM.cpp.
References llvm::dyn_cast(), getConstantInsertionIndex(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), hoist(), llvm::Loop::isLoopInvariant(), llvm::Instruction::moveBefore(), llvm::Value::replaceAllUsesWith(), and llvm::User::setOperand().
Referenced by llvm::hoistRegion().
|
static |
Try to simplify things like (A < INV_1 AND icmp A < INV_2) into (A < min(INV_1, INV_2)), if INV_1 and INV_2 are both loop invariants and their minimun can be computed outside of loop, and X is not a loop-invariant.
Definition at line 2228 of file LICM.cpp.
References assert(), C(), llvm::cast(), eraseInstruction(), llvm::CmpInst::getInversePredicate(), llvm::CmpPredicate::getMatching(), llvm::Value::getName(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), I, llvm::isa(), llvm::ICmpInst::isGE(), llvm::ICmpInst::isGT(), llvm::ICmpInst::isLE(), llvm::ICmpInst::isLT(), llvm::ICmpInst::isRelational(), llvm::CmpInst::isSigned(), LHS, llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), P, RHS, llvm::salvageDebugInfo(), std::swap(), and llvm::Value::takeName().
Referenced by hoistArithmetics().
|
static |
Try to reassociate expressions like ((A1 * B1) + (A2 * B2) + ...) * C where A1, A2, ... and C are loop invariants into expressions like ((A1 * C * B1) + (A2 * C * B2) + ...) and hoist the (A1 * C), (A2 * C), ... invariant expressions.
This functions returns true only if any hoisting has actually occurred.
Definition at line 2549 of file LICM.cpp.
References llvm::Add, assert(), llvm::cast(), llvm::BinaryOperator::Create(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), eraseInstruction(), llvm::DebugLoc::getDropped(), llvm::User::getOperand(), llvm::User::getOperandUse(), llvm::BasicBlock::getTerminator(), llvm::Value::hasOneUse(), I, llvm::isa(), isReassociableOp(), LHS, Mul, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), RHS, llvm::SmallVectorTemplateCommon< T, typename >::size(), and std::swap().
Referenced by hoistArithmetics().
|
static |
Try to reassociate and hoist the following two patterns: LV - C1 < C2 --> LV < C1 + C2, C1 - LV < C2 --> LV > C1 - C2.
Definition at line 2425 of file LICM.cpp.
References llvm::LICMDependencies::AC, assert(), llvm::cast(), llvm::computeOverflowForSignedAdd(), llvm::computeOverflowForSignedSub(), llvm::computeOverflowForUnsignedAdd(), llvm::computeOverflowForUnsignedSub(), DL, llvm::Instruction::dropPoisonGeneratingFlags(), llvm::SinkAndHoistDependencies::DT, eraseInstruction(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), llvm::CmpInst::isSigned(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::NeverOverflows, Pred, llvm::salvageDebugInfo(), llvm::User::setOperand(), llvm::CmpInst::setPredicate(), and std::swap().
Referenced by hoistAddSub().
|
static |
Reassociate add/sub expressions of the form:
where LV is a loop variant, and C1 and C2 are loop invariants. Sub is not associative, but these algebraic identities allow hoisting invariant computations out of the loop.
Definition at line 2737 of file LICM.cpp.
References assert(), C1, llvm::BinaryOperator::Create(), eraseInstruction(), llvm::DebugLoc::getDropped(), llvm::BasicBlock::getTerminator(), I, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_Instruction(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::salvageDebugInfo(), and std::swap().
Referenced by hoistArithmetics().
| INITIALIZE_PASS_BEGIN | ( | LegacyLICMPass | , |
| "licm" | , | ||
| "Loop Invariant Code Motion" | , | ||
| false | , | ||
| false | ) |
References INITIALIZE_PASS_DEPENDENCY.
|
static |
Little predicate that returns true if the specified basic block is in a subloop of the current one, not the current one itself.
Definition at line 2865 of file LICM.cpp.
References assert(), llvm::LoopBase< BlockT, LoopT >::contains(), and llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor().
Referenced by llvm::hoistRegion(), and llvm::sinkRegion().
|
static |
Return true if the instruction is foldable in the loop.
Definition at line 1028 of file LICM.cpp.
References llvm::cast(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::dyn_cast(), GEP, llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), I, llvm::isa(), llvm::TargetTransformInfo::TCC_Free, and llvm::TargetTransformInfo::TCK_SizeAndLatency.
Referenced by isNotUsedOrFoldableInLoop().
|
static |
Return true if-and-only-if we know how to (mechanically) both hoist and sink a given instruction out of a loop.
Does not address legality concerns such as aliasing or speculation safety.
Definition at line 845 of file LICM.cpp.
References I, and llvm::isa().
Referenced by llvm::canSinkOrHoistInst().
|
static |
Definition at line 787 of file LICM.cpp.
References llvm::cast(), DL, llvm::dyn_cast(), llvm::Instruction::getDataLayout(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::Instruction::getFunction(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoadInst::getPointerOperand(), llvm::getScalarOptions(), llvm::ConstantInt::getSExtValue(), llvm::Value::getType(), II, llvm::isa(), llvm::ConstantInt::isNegative(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), llvm::DominatorTreeBase< NodeT, IsPostDom >::properlyDominates(), uint64_t, and llvm::Value::users().
Referenced by llvm::canHoistLoad().
|
static |
Return true if the only users of this instruction are outside of the loop.
If this is true, we can sink the instruction to the exit blocks of the loop.
We also return true if the instruction could be folded away in lowering. (e.g., a GEP can be folded into a load as an addressing mode in the loop).
Definition at line 1058 of file LICM.cpp.
References llvm::cast(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::dyn_cast(), llvm::LoopSafetyInfo::getBlockColors(), llvm::User::getNumOperands(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::hasOneUser(), I, llvm::isa(), isFoldableInLoop(), and llvm::Instruction::user_back().
Referenced by llvm::sinkRegion().
|
static |
Return true if I is the only Instruction with a MemoryAccess in L.
Definition at line 857 of file LICM.cpp.
References llvm::cast(), llvm::MemorySSA::getBlockAccesses(), llvm::MemorySSAUpdater::getMemorySSA(), I, and llvm::isa().
Referenced by llvm::canSinkOrHoistInst().
|
static |
Returns whether I is a memory access that may be a candidate for promotion out of the loop L.
Definition at line 1971 of file LICM.cpp.
References llvm::dyn_cast(), I, llvm::isa(), and llvm::isStrongerThanMonotonic().
Referenced by collectPromotionCandidates(), and collectStoresWithInvariantAATags().
|
static |
Definition at line 2534 of file LICM.cpp.
References I.
Referenced by FindSingleUseMultiplyFactors(), hoistMulAddAssociation(), isFMulAddCandidate(), LinearizeExprTree(), NegateValue(), ShouldBreakUpSubtract(), and shouldConvertOrWithNoCommonBitsToAdd().
|
static |
Only sink or hoist an instruction if it is not a trapping instruction, or if the instruction is known not to trap when moved to the preheader.
or if it is a trapping instruction and is guaranteed to execute.
Definition at line 1461 of file LICM.cpp.
References DEBUG_TYPE, llvm::dyn_cast(), llvm::OptimizationRemarkEmitter::emit(), llvm::LoopSafetyInfo::isGuaranteedToExecute(), llvm::Loop::isLoopInvariant(), llvm::isSafeToSpeculativelyExecute(), and TLI.
Referenced by llvm::hoistRegion(), and llvm::promoteLoopAccessesToScalars().
|
static |
Returns true if a PHINode is a trivially replaceable with an Instruction.
This is true when all incoming values are that instruction. This pattern occurs most often with LCSSA PHI nodes.
Definition at line 1019 of file LICM.cpp.
References I, and llvm::PHINode::incoming_values().
Referenced by sink(), and sinkThroughTriviallyReplaceablePHI().
|
static |
Definition at line 1190 of file LICM.cpp.
References llvm::MemorySSA::BeforeTerminator, llvm::cast_or_null(), llvm::SinkAndHoistDependencies::EEA, llvm::ScalarEvolution::forgetBlockAndLoopDispositions(), llvm::MemorySSA::getMemoryAccess(), llvm::MemorySSAUpdater::getMemorySSA(), I, llvm::ICFLoopSafetyInfo::insertInstructionTo(), llvm::EarliestEscapeAnalysis::insertPotentialCapture(), llvm::MemorySSAUpdater::moveToPlace(), llvm::SinkAndHoistDependencies::MSSAU, llvm::ICFLoopSafetyInfo::removeInstruction(), llvm::LICMDependencies::SafetyInfo, and llvm::LICMDependencies::SE.
Referenced by hoist().
|
static |
Definition at line 2122 of file LICM.cpp.
References llvm::SinkAndHoistDependencies::AA, Accesses, assert(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::MemorySSA::dominates(), llvm::dyn_cast(), llvm::SinkAndHoistDependencies::EEA, llvm::MemorySSA::getBlockAccesses(), llvm::LoopBase< BlockT, LoopT >::getBlocks(), getClobberingMemoryAccess(), llvm::MemorySSA::getMemoryAccess(), llvm::MemorySSAUpdater::getMemorySSA(), llvm::BatchAAResults::getModRefInfo(), I, llvm::isa(), llvm::MemorySSA::isLiveOnEntryDef(), llvm::isNoModRef(), and llvm::SinkAndHoistDependencies::MSSAU.
Referenced by llvm::canSinkOrHoistInst().
|
static |
Definition at line 2216 of file LICM.cpp.
References Accesses, llvm::dyn_cast(), llvm::MemoryAccess::getBlock(), llvm::MemorySSA::getBlockDefs(), and llvm::MemorySSA::locallyDominates().
Referenced by pointerInvalidatedByLoop().
|
static |
Definition at line 2163 of file LICM.cpp.
References llvm::LoopBase< BlockT, LoopT >::contains(), llvm::SinkAndHoistDependencies::EEA, llvm::MemorySSA::getAA(), llvm::LoopBase< BlockT, LoopT >::getBlocks(), getClobberingMemoryAccess(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::MemorySSAUpdater::getMemorySSA(), I, llvm::isa(), llvm::MemorySSA::isLiveOnEntryDef(), llvm::SinkAndHoistDependencies::MSSAU, and pointerInvalidatedByBlock().
Referenced by llvm::canHoistLoad(), and llvm::canSinkOrHoistInst().
|
static |
Definition at line 1178 of file LICM.cpp.
References llvm::SinkAndHoistDependencies::EEA, I, llvm::SinkAndHoistDependencies::MSSAU, llvm::EarliestEscapeAnalysis::removeInstruction(), llvm::ICFLoopSafetyInfo::removeInstruction(), llvm::MemorySSAUpdater::removeMemoryAccess(), and llvm::LICMDependencies::SafetyInfo.
Referenced by eraseInstruction().
|
static |
When an instruction is found to only be used outside of the loop, this function moves it to the exit blocks and patches up SSA form as needed.
This method is guaranteed to remove the original instruction from its position, and may either delete it or move it to outside of the loop.
Definition at line 1310 of file LICM.cpp.
References assert(), canSplitPredecessors(), llvm::cast(), Changed, llvm::LoopBase< BlockT, LoopT >::contains(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), DEBUG_TYPE, llvm::SinkAndHoistDependencies::DT, llvm::OptimizationRemarkEmitter::emit(), llvm::SmallPtrSetImplBase::empty(), eraseInstruction(), llvm::from_range, llvm::PoisonValue::get(), llvm::PHINode::getIncomingBlock(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::LoopBase< BlockT, LoopT >::getUniqueExitBlocks(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isa(), llvm::DominatorTree::isReachableFromEntry(), isTriviallyReplaceablePHI(), llvm::LICMDependencies::LI, LLVM_DEBUG, llvm::SinkAndHoistDependencies::MSSAU, llvm::SinkAndHoistDependencies::ORE, llvm::Value::replaceAllUsesWith(), llvm::LICMDependencies::SafetyInfo, sinkThroughTriviallyReplaceablePHI(), splitPredecessorsOfLoopExit(), and Users.
Referenced by llvm::GCOVFile::readGCDA(), and llvm::sinkRegion().
|
static |
Definition at line 1205 of file LICM.cpp.
References assert(), cloneInstructionInExitBlock(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), I, isTriviallyReplaceablePHI(), and llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
Referenced by sink().
|
static |
Definition at line 1238 of file LICM.cpp.
References assert(), llvm::SetVector< T, Vector, Set, N >::begin(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::LoopSafetyInfo::copyColors(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::SetVector< T, Vector, Set, N >::empty(), llvm::from_range, llvm::PHINode::getBasicBlockIndex(), llvm::LoopSafetyInfo::getBlockColors(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::LoopBase< BlockT, LoopT >::getUniqueExitBlocks(), llvm::pred_begin(), llvm::pred_end(), llvm::SetVector< T, Vector, Set, N >::remove(), and llvm::SplitBlockPredecessors().
Referenced by sink().
| STATISTIC | ( | NumAddSubHoisted | , |
| "Number of add/subtract expressions reassociated " "and hoisted out of the loop" | ) |
| STATISTIC | ( | NumBOAssociationsHoisted | , |
| "Number of invariant BinaryOp expressions " "reassociated and hoisted out of the loop" | ) |
| STATISTIC | ( | NumFPAssociationsHoisted | , |
| "Number of invariant FP expressions " "reassociated and hoisted out of the loop" | ) |
| STATISTIC | ( | NumGEPsHoisted | , |
| "Number of geps reassociated and hoisted out of the loop" | ) |
| STATISTIC | ( | NumHoisted | , |
| "Number of instructions hoisted out of loop" | ) |
| STATISTIC | ( | NumIntAssociationsHoisted | , |
| "Number of invariant int expressions " "reassociated and hoisted out of the loop" | ) |
| STATISTIC | ( | NumLoadStorePromoted | , |
| "Number of load and store promotions" | ) |
| STATISTIC | ( | NumMinMaxHoisted | , |
| "Number of min/max expressions hoisted out of the loop" | ) |
| STATISTIC | ( | NumMovedCalls | , |
| "Number of call insts hoisted or sunk" | ) |
| STATISTIC | ( | NumPromotionCandidates | , |
| "Number of promotion candidates" | ) |
| STATISTIC | ( | NumSunk | , |
| "Number of instructions sunk out of loop" | ) |
| licm |
Definition at line 343 of file LICM.cpp.
Referenced by llvm::VPlanTransforms::optimize().