summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-11-18 19:19:36 +0000
committerChris Lattner <sabre@nondot.org>2006-11-18 19:19:36 +0000
commit822a87998387a4c52be5162523f09cc8e5e5afb7 (patch)
tree94b975f45f0572e19674fabbad3b8c7eca70760b /lib/Transforms/Utils
parente6cc288941d174d5711d7ae381b722f7b0b87e56 (diff)
downloadllvm-822a87998387a4c52be5162523f09cc8e5e5afb7.tar.gz
llvm-822a87998387a4c52be5162523f09cc8e5e5afb7.tar.bz2
llvm-822a87998387a4c52be5162523f09cc8e5e5afb7.tar.xz
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
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 78f5941b7a..afb483cc5f 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/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) {