From 822a87998387a4c52be5162523f09cc8e5e5afb7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 18 Nov 2006 19:19:36 +0000 Subject: [PATCH] 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 --- lib/Transforms/Utils/SimplifyCFG.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 78f5941b7a1..afb483cc5f6 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(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(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) {