Go to the documentation of this file.
42 #define DEBUG_TYPE "loop-instsimplify"
44 STATISTIC(NumSimplified,
"Number of redundant instructions simplified");
83 if (
auto *PI = dyn_cast<PHINode>(&
I))
88 DeadInsts.push_back(&
I);
94 bool IsFirstIteration = ToSimplify->
empty();
96 if (!IsFirstIteration && !ToSimplify->
count(&
I))
104 auto *UserI = cast<Instruction>(U.getUser());
114 if (
auto *UserPI = dyn_cast<PHINode>(UserI))
115 if (VisitedPHIs.
count(UserPI)) {
116 Next->insert(UserPI);
129 "Uses outside the loop should be PHI nodes due to LCSSA!");
130 if (!IsFirstIteration && L.
contains(UserI))
131 ToSimplify->
insert(UserI);
135 if (
Instruction *SimpleI = dyn_cast_or_null<Instruction>(V))
138 MA->replaceAllUsesWith(ReplacementMA);
140 assert(
I.use_empty() &&
"Should always have replaced all uses!");
142 DeadInsts.push_back(&
I);
150 if (!DeadInsts.empty()) {
176 class LoopInstSimplifyLegacyPass :
public LoopPass {
187 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
188 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
190 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
193 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
195 MemorySSA *MSSA = &getAnalysis<MemorySSAWrapperPass>().getMSSA();
237 "Simplify instructions in loops",
false,
false)
246 return new LoopInstSimplifyLegacyPass();
A set of analyses that are preserved following a run of a transformation pass.
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
This is an optimization pass for GlobalISel generic memory operations.
void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
A parsed version of the target data layout string in and methods for querying it.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
const Function * getParent() const
Return the enclosing method, or null if none.
Represents a single loop in the control flow graph.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
loop Simplify instructions in loops
Analysis the ScalarEvolution expression for r is< loop > Outside the loop
LLVM Basic Block Representation.
constexpr const T * getPointer() const
Wrapper class to LoopBlocksDFS that provides a standard begin()/end() interface for the DFS reverse p...
Legacy analysis pass which computes MemorySSA.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Represent the analysis usage information of a pass.
INITIALIZE_PASS_BEGIN(LoopInstSimplifyLegacyPass, "loop-instsimplify", "Simplify instructions in loops", false, false) INITIALIZE_PASS_END(LoopInstSimplifyLegacyPass
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form.
The object format emitted by the WebAssembly backed is documented in
static bool simplifyLoopInst(Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC, const TargetLibraryInfo &TLI, MemorySSAUpdater *MSSAU)
Legacy analysis pass which computes a DominatorTree.
STATISTIC(NumFunctions, "Total number of functions")
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
inst_range instructions(Function *F)
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
MemorySSA * getMemorySSA() const
Get handle on MemorySSA.
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
Encapsulates MemorySSA, including all data associated with memory accesses.
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
SimplifyQuery getWithInstruction(Instruction *I) const
An analysis that produces MemorySSA for a function.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
An immutable pass that tracks lazily created AssumptionCache objects.
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
A cache of @llvm.assume calls within a function.
Represents analyses that only rely on functions' control flow.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void initializeLoopInstSimplifyLegacyPassPass(PassRegistry &)
BlockT * getHeader() const
Provides information about what library functions are available for the current target.
Pass * createLoopInstSimplifyPass()
Pass interface - Implemented by all 'passes'.
LLVM_NODISCARD bool empty() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
A container for analyses that lazily runs them and caches their results.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
AnalysisUsage & addRequired()
bool VerifyMemorySSA
Enables verification of MemorySSA.
void perform(LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
LLVM Value Representation.
A Use represents the edge between a Value definition and its users.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.