diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-20 16:57:10 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-20 16:57:10 +0000 |
commit | e268304122d827396979c61251f2862148ad01c8 (patch) | |
tree | 89d2a20ff0b8e05f94bc60fcbacf1090aac1cd6b | |
parent | f04ab64b25f185873a004cde234c5ad5fd2e675e (diff) | |
download | bcm5719-llvm-e268304122d827396979c61251f2862148ad01c8.tar.gz bcm5719-llvm-e268304122d827396979c61251f2862148ad01c8.zip |
Revert r330431.
There are still stage3/stage4 miscompares :(
llvm-svn: 330446
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 796b6abcbfd..29c707799bd 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -66,7 +66,6 @@ #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/SSAUpdater.h" -#include "llvm/Transforms/Utils/SSAUpdaterBulk.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include <algorithm> #include <cassert> @@ -1986,33 +1985,19 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB, // PHI nodes for NewBB now. AddPHINodeEntriesForMappedBlock(SuccBB, BB, NewBB, ValueMapping); - // Update the terminator of PredBB to jump to NewBB instead of BB. This - // eliminates predecessors from BB, which requires us to simplify any PHI - // nodes in BB. - TerminatorInst *PredTerm = PredBB->getTerminator(); - for (unsigned i = 0, e = PredTerm->getNumSuccessors(); i != e; ++i) - if (PredTerm->getSuccessor(i) == BB) { - BB->removePredecessor(PredBB, true); - PredTerm->setSuccessor(i, NewBB); - } - // If there were values defined in BB that are used outside the block, then we // now have to update all uses of the value to use either the original value, // the cloned value, or some PHI derived value. This can require arbitrary // PHI insertion, of which we are prepared to do, clean these up now. - SSAUpdaterBulk SSAUpdate; - + SSAUpdater SSAUpdate; + SmallVector<Use*, 16> UsesToRename; for (Instruction &I : *BB) { - SmallVector<Use*, 16> UsesToRename; - // Scan all uses of this instruction to see if it is used outside of its - // block, and if so, record them in UsesToRename. Also, skip phi operands - // from PredBB - we'll remove them anyway. + // block, and if so, record them in UsesToRename. for (Use &U : I.uses()) { Instruction *User = cast<Instruction>(U.getUser()); if (PHINode *UserPN = dyn_cast<PHINode>(User)) { - if (UserPN->getIncomingBlock(U) == BB || - UserPN->getIncomingBlock(U) == PredBB) + if (UserPN->getIncomingBlock(U) == BB) continue; } else if (User->getParent() == BB) continue; @@ -2023,24 +2008,35 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB, // If there are no uses outside the block, we're done with this instruction. if (UsesToRename.empty()) continue; - unsigned VarNum = SSAUpdate.AddVariable(I.getName(), I.getType()); - // We found a use of I outside of BB - we need to rename all uses of I that - // are outside its block to be uses of the appropriate PHI node etc. - SSAUpdate.AddAvailableValue(VarNum, BB, &I); - SSAUpdate.AddAvailableValue(VarNum, NewBB, ValueMapping[&I]); - for (auto *U : UsesToRename) - SSAUpdate.AddUse(VarNum, U); + DEBUG(dbgs() << "JT: Renaming non-local uses of: " << I << "\n"); + + // We found a use of I outside of BB. Rename all uses of I that are outside + // its block to be uses of the appropriate PHI node etc. See ValuesInBlocks + // with the two values we know. + SSAUpdate.Initialize(I.getType(), I.getName()); + SSAUpdate.AddAvailableValue(BB, &I); + SSAUpdate.AddAvailableValue(NewBB, ValueMapping[&I]); + + while (!UsesToRename.empty()) + SSAUpdate.RewriteUse(*UsesToRename.pop_back_val()); + DEBUG(dbgs() << "\n"); } + // Ok, NewBB is good to go. Update the terminator of PredBB to jump to + // NewBB instead of BB. This eliminates predecessors from BB, which requires + // us to simplify any PHI nodes in BB. + TerminatorInst *PredTerm = PredBB->getTerminator(); + for (unsigned i = 0, e = PredTerm->getNumSuccessors(); i != e; ++i) + if (PredTerm->getSuccessor(i) == BB) { + BB->removePredecessor(PredBB, true); + PredTerm->setSuccessor(i, NewBB); + } + DDT->applyUpdates({{DominatorTree::Insert, NewBB, SuccBB}, {DominatorTree::Insert, PredBB, NewBB}, {DominatorTree::Delete, PredBB, BB}}); - // Apply all updates we queued with DDT and get the updated Dominator Tree. - DominatorTree *DT = &DDT->flush(); - SSAUpdate.RewriteAllUses(DT); - // At this point, the IR is fully up to date and consistent. Do a quick scan // over the new instructions and zap any that are constants or dead. This // frequently happens because of phi translation. |