diff options
-rw-r--r-- | include/llvm/Analysis/Dominators.h | 9 | ||||
-rw-r--r-- | lib/Transforms/Utils/LoopSimplify.cpp | 8 |
2 files changed, 12 insertions, 5 deletions
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index f6ac58a69f..b6453bae17 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -27,6 +27,7 @@ #define LLVM_ANALYSIS_DOMINATORS_H #include "llvm/Analysis/ET-Forest.h" +#include "llvm/Function.h" #include "llvm/Pass.h" #include <set> @@ -395,7 +396,7 @@ public: } } - // dominates - Return true if A dominates B. THis performs the + // dominates - Return true if A dominates B. This performs the // special checks necessary if A and B are in the same basic block. bool dominates(Instruction *A, Instruction *B); @@ -405,6 +406,12 @@ public: return dominates(A, B) && A != B; } + /// isReachableFromEntry - Return true if A is dominated by the entry + /// block of the function containing it. + bool isReachableFromEntry(BasicBlock* A) { + return dominates(&A->getParent()->getEntryBlock(), A); + } + /// Return the nearest common dominator of A and B. BasicBlock *nearestCommonDominator(BasicBlock *A, BasicBlock *B) const { ETNode *NodeA = getNode(A); diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 5319d18b1c..ffdc91c37a 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -312,6 +312,8 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB, // Can we eliminate this phi node now? if (Value *V = PN->hasConstantValue(true)) { Instruction *I = dyn_cast<Instruction>(V); + // If I is in NewBB, the ETForest call will fail, because NewBB isn't + // registered in ETForest yet. Handle this case explicitly. if (!I || (I->getParent() != NewBB && getAnalysis<ETForest>().dominates(I, PN))) { PN->replaceAllUsesWith(V); @@ -701,15 +703,13 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB, { BasicBlock *OnePred = PredBlocks[0]; unsigned i = 1, e = PredBlocks.size(); - for (i = 1; !ETF.dominates(&OnePred->getParent()->getEntryBlock(), OnePred); - ++i) { + for (i = 1; !ETF.isReachableFromEntry(OnePred); ++i) { assert(i != e && "Didn't find reachable pred?"); OnePred = PredBlocks[i]; } for (; i != e; ++i) - if (PredBlocks[i] != OnePred && - ETF.dominates(&PredBlocks[i]->getParent()->getEntryBlock(), OnePred)){ + if (PredBlocks[i] != OnePred && ETF.isReachableFromEntry(OnePred)){ NewBBDominatesNewBBSucc = false; break; } |