Do not convert massive blocks on phi nodes into select statements. Instead

only do these transformations if there are a small number of phi's.
This speeds up Ptrdist/ks from 2.35s to 2.19s on my mac pro.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31853 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-11-18 19:19:36 +00:00
parent e6cc288941
commit 822a879983

View File

@ -1064,6 +1064,16 @@ static bool FoldTwoEntryPHINode(PHINode *PN) {
Value *IfCond = GetIfCondition(BB, IfTrue, IfFalse);
if (!IfCond) return false;
// Okay, we found that we can merge this two-entry phi node into a select.
// Doing so would require us to fold *all* two entry phi nodes in this block.
// At some point this becomes non-profitable (particularly if the target
// doesn't support cmov's). Only do this transformation if there are two or
// fewer PHI nodes in this block.
unsigned NumPhis = 0;
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++NumPhis, ++I)
if (NumPhis > 2)
return false;
DEBUG(std::cerr << "FOUND IF CONDITION! " << *IfCond << " T: "
<< IfTrue->getName() << " F: " << IfFalse->getName() << "\n");
@ -1552,6 +1562,23 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// keep getting unwound.
if (PBIOp != -1 && PBI->getSuccessor(PBIOp) == BB)
PBIOp = BIOp = -1;
// Do not perform this transformation if it would require
// insertion of a large number of select instructions. For targets
// without predication/cmovs, this is a big pessimization.
if (PBIOp != -1) {
BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);
unsigned NumPhis = 0;
for (BasicBlock::iterator II = CommonDest->begin();
isa<PHINode>(II); ++II, ++NumPhis) {
if (NumPhis > 2) {
// Disable this xform.
PBIOp = -1;
break;
}
}
}
// Finally, if everything is ok, fold the branches to logical ops.
if (PBIOp != -1) {