[llvm] r306162 - Revert "[LoopDeletion] NFC: Move phi node value setting into prepass"
Anna Thomas via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 14:30:48 PDT 2017
Author: annat
Date: Fri Jun 23 16:30:48 2017
New Revision: 306162
URL: http://llvm.org/viewvc/llvm-project?rev=306162&view=rev
Log:
Revert "[LoopDeletion] NFC: Move phi node value setting into prepass"
This reverts commit r306157.
It caused some timeouts in clang tests. Perhaps unreachable loops have
far too many phi nodes.
Reverting and investigating.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp?rev=306162&r1=306161&r2=306162&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp Fri Jun 23 16:30:48 2017
@@ -31,19 +31,20 @@ using namespace llvm;
STATISTIC(NumDeleted, "Number of loops deleted");
/// This function deletes dead loops. The caller of this function needs to
-/// guarantee that the loop is infact dead. Here we handle two kinds of dead
+/// guarantee that the loop is infact dead. Here we handle two kinds of dead
/// loop. The first kind (\p isLoopDead) is where only invariant values from
/// within the loop are used outside of it. The second kind (\p
/// isLoopNeverExecuted) is where the loop is provably never executed. We can
-/// always remove never executed loops since they will not cause any difference
-/// to program behaviour.
+/// always remove never executed loops since they will not cause any
+/// difference to program behaviour.
///
/// This also updates the relevant analysis information in \p DT, \p SE, and \p
/// LI. It also updates the loop PM if an updater struct is provided.
// TODO: This function will be used by loop-simplifyCFG as well. So, move this
// to LoopUtils.cpp
static void deleteDeadLoop(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
- LoopInfo &LI, LPMUpdater *Updater = nullptr);
+ LoopInfo &LI, bool LoopIsNeverExecuted,
+ LPMUpdater *Updater = nullptr);
/// Determines if a loop is dead.
///
/// This assumes that we've already checked for unique exit and exiting blocks,
@@ -167,13 +168,7 @@ static bool deleteLoopIfDead(Loop *L, Do
BasicBlock *ExitBlock = L->getUniqueExitBlock();
if (ExitBlock && isLoopNeverExecuted(L)) {
- // Set incoming value to undef for phi nodes in the exit block.
- BasicBlock::iterator BI = ExitBlock->begin();
- while (PHINode *P = dyn_cast<PHINode>(BI)) {
- for (unsigned i = 0; i < P->getNumIncomingValues(); i++)
- P->setIncomingValue(i, UndefValue::get(P->getType()));
- }
- deleteDeadLoop(L, DT, SE, LI, Updater);
+ deleteDeadLoop(L, DT, SE, LI, true /* LoopIsNeverExecuted */, Updater);
++NumDeleted;
return true;
}
@@ -201,14 +196,15 @@ static bool deleteLoopIfDead(Loop *L, Do
if (isa<SCEVCouldNotCompute>(S))
return Changed;
- deleteDeadLoop(L, DT, SE, LI, Updater);
+ deleteDeadLoop(L, DT, SE, LI, false /* LoopIsNeverExecuted */, Updater);
++NumDeleted;
return true;
}
static void deleteDeadLoop(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
- LoopInfo &LI, LPMUpdater *Updater) {
+ LoopInfo &LI, bool LoopIsNeverExecuted,
+ LPMUpdater *Updater) {
assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
auto *Preheader = L->getLoopPreheader();
assert(Preheader && "Preheader should exist!");
@@ -250,6 +246,8 @@ static void deleteDeadLoop(Loop *L, Domi
// other incoming values. Given the loop has dedicated exits, all other
// incoming values must be from the exiting blocks.
int PredIndex = 0;
+ if (LoopIsNeverExecuted)
+ P->setIncomingValue(PredIndex, UndefValue::get(P->getType()));
P->setIncomingBlock(PredIndex, Preheader);
// Removes all incoming values from all other exiting blocks (including
// duplicate values from an exiting block).
More information about the llvm-commits
mailing list