aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUnroll.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2021-05-16 09:29:25 -0700
committerPhilip Reames <listmail@philipreames.com>2021-05-16 09:38:36 -0700
commit6ae9893ed23f06b48418a6af8625bda3133a0c30 (patch)
treecc4e44354f25a6155dbaa26602ae5492bbf5536c /llvm/lib/Transforms/Utils/LoopUnroll.cpp
parentd539357e1b8a1b5682912a8ea4da6c0088bb770b (diff)
downloadllvm-6ae9893ed23f06b48418a6af8625bda3133a0c30.zip
llvm-6ae9893ed23f06b48418a6af8625bda3133a0c30.tar.gz
llvm-6ae9893ed23f06b48418a6af8625bda3133a0c30.tar.bz2
Revert "Do actual DCE in LoopUnroll (try 2)"
This reverts commit 653fa0b46ae34c06495b542414b704b30381cd02. Reported to trigger pr50354. Reverting until investigated.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnroll.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index 1837fb6..893b918 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -213,11 +213,16 @@ 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();
for (BasicBlock *BB : L->getBlocks()) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
@@ -227,9 +232,14 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
if (LI->replacementPreservesLCSSAForm(Inst, V))
Inst->replaceAllUsesWith(V);
if (isInstructionTriviallyDead(Inst))
- RecursivelyDeleteTriviallyDeadInstructions(Inst);
+ BB->getInstList().erase(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.
}
/// Unroll the given loop by Count. The loop must be in LCSSA form. Unrolling