diff options
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 0e382874dc..7ec31657ec 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1433,21 +1433,28 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB) { continue; HaveRewritablePHIs = true; - - // Check for safety. ConstantExpr *CE = dyn_cast<ConstantExpr>(ThenV); if (!CE) - continue; // Known safe. + continue; // Known safe and cheap. + + if (!isSafeToSpeculativelyExecute(CE)) + return false; + + // Don't speculate into a select with a constant select expression operand. + // FIXME: This should really be a cost metric, but our cost model doesn't + // accurately model the expense of select. + if (Operator::getOpcode(CE) == Instruction::Select) + return false; // An unfolded ConstantExpr could end up getting expanded into // Instructions. Don't speculate this and another instruction at // the same time. + // FIXME: This is strange because provided we haven't already hit the cost + // of 1, this code will speculate an arbitrary number of complex constant + // expression PHI nodes. Also, this doesn't account for how complex the + // constant expression is. if (SpeculationCost > 0) return false; - if (!isSafeToSpeculativelyExecute(CE)) - return false; - if (ComputeSpeculationCost(CE) > PHINodeFoldingThreshold) - return false; } // If there are no PHIs to process, bail early. This helps ensure idempotence |