From 97b9b97853d7e4fbb5c8460ef28126013c76e9a9 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 17 Aug 2010 01:20:36 +0000 Subject: 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 --- lib/CodeGen/MachineBasicBlock.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/MachineBasicBlock.cpp') 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(); + 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()) MDT->addNewBlock(NMBB, this); - if (MachineLoopInfo *MLI = - P->getAnalysisIfAvailable()) + 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. -- cgit v1.2.3-18-g5258