summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-01-24 11:53:01 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-01-24 11:53:01 +0000
commit8a21005cca67caa0db5db584faada56e1e38627c (patch)
treeb5ca9a4144dcea53c5fba2aa6c32f2f39a3a3e2d /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent7481ca8ff538f96472b32e845b8b086d3364c82d (diff)
downloadbcm5719-llvm-8a21005cca67caa0db5db584faada56e1e38627c.tar.gz
bcm5719-llvm-8a21005cca67caa0db5db584faada56e1e38627c.zip
Switch the constant expression speculation cost evaluation away from
a cost fuction that seems both a bit ad-hoc and also poorly suited to evaluating constant expressions. Notably, it is missing any support for trivial expressions such as 'inttoptr'. I could fix this routine, but it isn't clear to me all of the constraints its other users are operating under. The core protection that seems relevant here is avoiding the formation of a select instruction wich a further chain of select operations in a constant expression operand. Just explicitly encode that constraint. Also, update the comments and organization here to make it clear where this needs to go -- this should be driven off of real cost measurements which take into account the number of constants expressions and the depth of the constant expression tree. llvm-svn: 173340
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 0e382874dcf..7ec31657ec4 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud