diff options
author | Evan Cheng <evan.cheng@apple.com> | 2010-08-17 01:20:36 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2010-08-17 01:20:36 +0000 |
commit | 97b9b97853d7e4fbb5c8460ef28126013c76e9a9 (patch) | |
tree | 00177661907fa80d2ee615063908e042e57911b9 /lib | |
parent | 922157c83440e0197e7fd962cf7030491a8069b1 (diff) | |
download | external_llvm-97b9b97853d7e4fbb5c8460ef28126013c76e9a9.tar.gz external_llvm-97b9b97853d7e4fbb5c8460ef28126013c76e9a9.tar.bz2 external_llvm-97b9b97853d7e4fbb5c8460ef28126013c76e9a9.zip |
PHI elimination should not break back edge. It can cause some significant code placement issues. rdar://8263994
good:
LBB0_2:
mov r2, r0
. . .
mov r1, r2
bne LBB0_2
bad:
LBB0_2:
mov r2, r0
. . .
@ BB#3:
mov r1, r2
b LBB0_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111221 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/MachineBasicBlock.cpp | 11 | ||||
-rw-r--r-- | lib/CodeGen/PHIElimination.cpp | 8 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index a27ee47943..895653d18d 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -439,6 +439,14 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { if (TII->AnalyzeBranch(*this, TBB, FBB, Cond)) return NULL; + // Avoid splitting backedges of loops. It would introduce small out-of-line + // blocks into the loop which is very bad for code placement. + if (this == Succ) + return NULL; + MachineLoopInfo *MLI = P->getAnalysisIfAvailable<MachineLoopInfo>(); + if (MLI->isLoopHeader(Succ)) + return NULL; + MachineBasicBlock *NMBB = MF->CreateMachineBasicBlock(); MF->insert(llvm::next(MachineFunction::iterator(this)), NMBB); DEBUG(dbgs() << "PHIElimination splitting critical edge:" @@ -471,8 +479,7 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { P->getAnalysisIfAvailable<MachineDominatorTree>()) MDT->addNewBlock(NMBB, this); - if (MachineLoopInfo *MLI = - P->getAnalysisIfAvailable<MachineLoopInfo>()) + if (MLI) if (MachineLoop *TIL = MLI->getLoopFor(this)) { // If one or the other blocks were not in a loop, the new block is not // either, and thus LI doesn't need to be updated. diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp index 7bf0aa23af..105f20b448 100644 --- a/lib/CodeGen/PHIElimination.cpp +++ b/lib/CodeGen/PHIElimination.cpp @@ -20,6 +20,7 @@ #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Function.h" @@ -44,9 +45,9 @@ char &llvm::PHIEliminationID = PHIElimination::ID; void llvm::PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved<LiveVariables>(); + AU.addRequired<MachineLoopInfo>(); AU.addPreserved<MachineDominatorTree>(); - // rdar://7401784 This would be nice: - // AU.addPreservedID(MachineLoopInfoID); + AU.addPreservedID(MachineLoopInfoID); MachineFunctionPass::getAnalysisUsage(AU); } @@ -382,6 +383,7 @@ bool llvm::PHIElimination::SplitPHIEdges(MachineFunction &MF, if (MBB.empty() || !MBB.front().isPHI() || MBB.isLandingPad()) return false; // Quick exit for basic blocks without PHIs. + bool Changed = false; for (MachineBasicBlock::const_iterator BBI = MBB.begin(), BBE = MBB.end(); BBI != BBE && BBI->isPHI(); ++BBI) { for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) { @@ -391,7 +393,7 @@ bool llvm::PHIElimination::SplitPHIEdges(MachineFunction &MF, // (not considering PHI nodes). If the register is live in to this block // anyway, we would gain nothing from splitting. if (!LV.isLiveIn(Reg, MBB) && LV.isLiveOut(Reg, *PreMBB)) - PreMBB->SplitCriticalEdge(&MBB, this); + Changed |= PreMBB->SplitCriticalEdge(&MBB, this) != 0; } } return true; |