diff options
Diffstat (limited to 'lib/Transforms/Utils/LCSSA.cpp')
| -rw-r--r-- | lib/Transforms/Utils/LCSSA.cpp | 26 | 
1 files changed, 18 insertions, 8 deletions
| diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index ae0e2bb6c280..956d0387c7a8 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -36,13 +36,14 @@  #include "llvm/Analysis/LoopPass.h"  #include "llvm/Analysis/ScalarEvolution.h"  #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" +#include "llvm/Transforms/Utils/Local.h"  #include "llvm/IR/Constants.h"  #include "llvm/IR/Dominators.h"  #include "llvm/IR/Function.h"  #include "llvm/IR/Instructions.h"  #include "llvm/IR/PredIteratorCache.h"  #include "llvm/Pass.h" -#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils.h"  #include "llvm/Transforms/Utils/LoopUtils.h"  #include "llvm/Transforms/Utils/SSAUpdater.h"  using namespace llvm; @@ -214,18 +215,27 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,          Worklist.push_back(PostProcessPN);      // Keep track of PHI nodes that we want to remove because they did not have -    // any uses rewritten. +    // any uses rewritten. If the new PHI is used, store it so that we can +    // try to propagate dbg.value intrinsics to it. +    SmallVector<PHINode *, 2> NeedDbgValues;      for (PHINode *PN : AddedPHIs)        if (PN->use_empty())          PHIsToRemove.insert(PN); - +      else +        NeedDbgValues.push_back(PN); +    insertDebugValuesForPHIs(InstBB, NeedDbgValues);      Changed = true;    } -  // Remove PHI nodes that did not have any uses rewritten. -  for (PHINode *PN : PHIsToRemove) { -    assert (PN->use_empty() && "Trying to remove a phi with uses."); -    PN->eraseFromParent(); -  } +  // Remove PHI nodes that did not have any uses rewritten. We need to redo the +  // use_empty() check here, because even if the PHI node wasn't used when added +  // to PHIsToRemove, later added PHI nodes can be using it.  This cleanup is +  // not guaranteed to handle trees/cycles of PHI nodes that only are used by +  // each other. Such situations has only been noticed when the input IR +  // contains unreachable code, and leaving some extra redundant PHI nodes in +  // such situations is considered a minor problem. +  for (PHINode *PN : PHIsToRemove) +    if (PN->use_empty()) +      PN->eraseFromParent();    return Changed;  } | 
