summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2019-06-23 17:06:57 +0000
committerPhilip Reames <listmail@philipreames.com>2019-06-23 17:06:57 +0000
commitd22a2a9a7264ebe6468c5776b0e95d4dcf800ef5 (patch)
tree556ce88652bc43e5325f9b64113c4334f6f3e755 /llvm/lib/Transforms
parentf955d5f623dd18d87e8b8bd6857cc0dbc1ec636d (diff)
downloadbcm5719-llvm-d22a2a9a7264ebe6468c5776b0e95d4dcf800ef5.tar.gz
bcm5719-llvm-d22a2a9a7264ebe6468c5776b0e95d4dcf800ef5.zip
[IndVars] Remove dead instructions after folding trivial loop exit
In rL364135, I taught IndVars to fold exiting branches in loops with a zero backedge taken count (i.e. loops that only run one iteration). This extends that to eliminate the dead comparison left around. llvm-svn: 364155
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/IndVarSimplify.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 57f246373f0..c173f9e4c03 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2732,10 +2732,12 @@ bool IndVarSimplify::run(Loop *L) {
if (ExitCount->isZero()) {
auto *BI = cast<BranchInst>(ExitingBB->getTerminator());
bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
- auto *NewCond = ExitIfTrue ?
- ConstantInt::getTrue(BI->getCondition()->getType()) :
- ConstantInt::getFalse(BI->getCondition()->getType());
+ auto *OldCond = BI->getCondition();
+ auto *NewCond = ExitIfTrue ? ConstantInt::getTrue(OldCond->getType()) :
+ ConstantInt::getFalse(OldCond->getType());
BI->setCondition(NewCond);
+ if (OldCond->use_empty())
+ DeadInsts.push_back(OldCond);
Changed = true;
continue;
}
OpenPOWER on IntegriCloud