diff options
author | Philip Reames <listmail@philipreames.com> | 2021-05-14 10:03:45 -0700 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2021-05-14 10:05:25 -0700 |
commit | 9d1a61e695eb01298e26c76867d65592f1e1968c (patch) | |
tree | 0a82fe2d3f0a8d77cafc4f5d42e0bac88a312f86 /llvm/lib/Transforms/Utils/LoopUnroll.cpp | |
parent | b7d1ab75cf474fb3ffc7e7173762c4d83eb2ef8e (diff) | |
download | llvm-9d1a61e695eb01298e26c76867d65592f1e1968c.zip llvm-9d1a61e695eb01298e26c76867d65592f1e1968c.tar.gz llvm-9d1a61e695eb01298e26c76867d65592f1e1968c.tar.bz2 |
Do actual DCE in LoopUnroll
LoopUnroll does a limited DCE pass after unrolling, but if you have a chain of dead instructions, it only deletes the last one. Improve the code to recursively delete all trivially dead instructions.
Differential Revision: https://reviews.llvm.org/D102511
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 893b918..9a1f812 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -220,10 +220,10 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, } } - // At this point, the code is well formed. We now do a quick sweep over the - // inserted code, doing constant propagation and dead code elimination as we - // go. + // At this point, the code is well formed. Perform constprop, instsimplify, + // and dce. const DataLayout &DL = L->getHeader()->getModule()->getDataLayout(); + SmallVector<WeakTrackingVH, 16> DeadInsts; for (BasicBlock *BB : L->getBlocks()) { for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) { Instruction *Inst = &*I++; @@ -232,14 +232,15 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, if (LI->replacementPreservesLCSSAForm(Inst, V)) Inst->replaceAllUsesWith(V); if (isInstructionTriviallyDead(Inst)) - BB->getInstList().erase(Inst); + DeadInsts.emplace_back(Inst); } } - // TODO: after peeling or unrolling, previously loop variant conditions are - // likely to fold to constants, eagerly propagating those here will require - // fewer cleanup passes to be run. Alternatively, a LoopEarlyCSE might be - // appropriate. + while (!DeadInsts.empty()) { + Value *V = DeadInsts.pop_back_val(); + if (Instruction *Inst = dyn_cast_or_null<Instruction>(V)) + RecursivelyDeleteTriviallyDeadInstructions(Inst); + } } /// Unroll the given loop by Count. The loop must be in LCSSA form. Unrolling |