diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-11-18 19:19:36 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-11-18 19:19:36 +0000 |
| commit | 95adf8f1da3aebd0a9eaefe607c05177951a389d (patch) | |
| tree | 375a85c900b4df2f65b7d1686ce3964e97a76a0c /llvm/lib/Transforms/Utils | |
| parent | bfbc7ace7d09cbda2f4b1b71cf8168adbc5e255e (diff) | |
| download | bcm5719-llvm-95adf8f1da3aebd0a9eaefe607c05177951a389d.tar.gz bcm5719-llvm-95adf8f1da3aebd0a9eaefe607c05177951a389d.zip | |
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.
llvm-svn: 31853
Diffstat (limited to 'llvm/lib/Transforms/Utils')
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 78f5941b7a1..afb483cc5f6 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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) { |

