diff options
author | Amy Huang <akhuang@google.com> | 2021-05-19 08:47:30 -0700 |
---|---|---|
committer | Amy Huang <akhuang@google.com> | 2021-05-19 08:53:38 -0700 |
commit | 517857421d2ffcebc20da2c68862f7a2ddebaa51 (patch) | |
tree | b639c9ffd785285609ad651a9a81859cfa3fe241 /llvm/lib/Transforms/Utils/LoopUnroll.cpp | |
parent | 84a880e1e23ebc2ca60e6e1f9e8d0d8db3f9a036 (diff) | |
download | llvm-517857421d2ffcebc20da2c68862f7a2ddebaa51.zip llvm-517857421d2ffcebc20da2c68862f7a2ddebaa51.tar.gz llvm-517857421d2ffcebc20da2c68862f7a2ddebaa51.tar.bz2 |
Revert "Do actual DCE in LoopUnroll (try 3)"
This reverts commit b6320eeb8622f05e4a5d4c7f5420523357490fca
as it causes clang to assert; see
https://reviews.llvm.org/rGb6320eeb8622f05e4a5d4c7f5420523357490fca.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 395d2af..20bf5a25 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -213,27 +213,33 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, // Aggressively clean up dead instructions that simplifyLoopIVs already // identified. Any remaining should be cleaned up below. - RecursivelyDeleteTriviallyDeadInstructions(DeadInsts); + while (!DeadInsts.empty()) { + Value *V = DeadInsts.pop_back_val(); + if (Instruction *Inst = dyn_cast_or_null<Instruction>(V)) + RecursivelyDeleteTriviallyDeadInstructions(Inst); + } } - // At this point, the code is well formed. Perform constprop, instsimplify, - // and dce. + // 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. 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++; + if (Value *V = SimplifyInstruction(Inst, {DL, nullptr, DT, AC})) if (LI->replacementPreservesLCSSAForm(Inst, V)) Inst->replaceAllUsesWith(V); if (isInstructionTriviallyDead(Inst)) - DeadInsts.emplace_back(Inst); + BB->getInstList().erase(Inst); } - // We can't do recursive deletion until we're done iterating, as we might - // have a phi which (potentially indirectly) uses instructions later in - // the block we're iterating through. - RecursivelyDeleteTriviallyDeadInstructions(DeadInsts); } + + // 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. } /// Unroll the given loop by Count. The loop must be in LCSSA form. Unrolling |