Make various Expr::EstimateCost() implementations return 0 if operand(s) are constants.

(Assume that constant folding will make these be free.)
This commit is contained in:
Matt Pharr
2012-03-21 15:43:11 -07:00
parent 989966f81b
commit 316de0b880

View File

@@ -1269,6 +1269,9 @@ UnaryExpr::TypeCheck() {
int
UnaryExpr::EstimateCost() const {
if (dynamic_cast<ConstExpr *>(expr) != NULL)
return 0;
return COST_SIMPLE_ARITH_LOGIC_OP;
}
@@ -2501,6 +2504,10 @@ BinaryExpr::TypeCheck() {
int
BinaryExpr::EstimateCost() const {
if (dynamic_cast<ConstExpr *>(arg0) != NULL &&
dynamic_cast<ConstExpr *>(arg1) != NULL)
return 0;
return (op == Div || op == Mod) ? COST_COMPLEX_ARITH_OP :
COST_SIMPLE_ARITH_LOGIC_OP;
}
@@ -6719,6 +6726,9 @@ TypeCastExpr::Optimize() {
int
TypeCastExpr::EstimateCost() const {
if (dynamic_cast<ConstExpr *>(expr) != NULL)
return 0;
// FIXME: return COST_TYPECAST_COMPLEX when appropriate
return COST_TYPECAST_SIMPLE;
}