diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp index a93a89ecaa96e..34a9d5d0e401f 100644 --- a/llvm/lib/CodeGen/PHIElimination.cpp +++ b/llvm/lib/CodeGen/PHIElimination.cpp @@ -30,6 +30,7 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineOperand.h" +#include "llvm/CodeGen/MachinePostDominators.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/TargetInstrInfo.h" @@ -72,6 +73,7 @@ class PHIEliminationImpl { LiveIntervals *LIS = nullptr; MachineLoopInfo *MLI = nullptr; MachineDominatorTree *MDT = nullptr; + MachinePostDominatorTree *PDT = nullptr; /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions /// in predecessor basic blocks. @@ -123,17 +125,22 @@ class PHIEliminationImpl { auto *MLIWrapper = P->getAnalysisIfAvailable(); auto *MDTWrapper = P->getAnalysisIfAvailable(); + auto *PDTWrapper = + P->getAnalysisIfAvailable(); LV = LVWrapper ? &LVWrapper->getLV() : nullptr; LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr; MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr; MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr; + PDT = PDTWrapper ? &PDTWrapper->getPostDomTree() : nullptr; } PHIEliminationImpl(MachineFunction &MF, MachineFunctionAnalysisManager &AM) : LV(AM.getCachedResult(MF)), LIS(AM.getCachedResult(MF)), MLI(AM.getCachedResult(MF)), - MDT(AM.getCachedResult(MF)), MFAM(&AM) {} + MDT(AM.getCachedResult(MF)), + PDT(AM.getCachedResult(MF)), + MFAM(&AM) {} bool run(MachineFunction &MF); }; @@ -172,6 +179,7 @@ PHIEliminationPass::run(MachineFunction &MF, PA.preserve(); PA.preserve(); PA.preserve(); + PA.preserve(); PA.preserve(); return PA; } @@ -197,6 +205,7 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); + AU.addPreserved(); AU.addPreserved(); MachineFunctionPass::getAnalysisUsage(AU); } @@ -204,15 +213,8 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const { bool PHIEliminationImpl::run(MachineFunction &MF) { MRI = &MF.getRegInfo(); - MachineDominatorTree *MDT = nullptr; - if (P) { - auto *MDTWrapper = - P->getAnalysisIfAvailable(); - MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr; - } else { - MDT = MFAM->getCachedResult(MF); - } - MachineDomTreeUpdater MDTU(MDT, MachineDomTreeUpdater::UpdateStrategy::Lazy); + MachineDomTreeUpdater MDTU(MDT, PDT, + MachineDomTreeUpdater::UpdateStrategy::Lazy); bool Changed = false;