diff --git a/ispc.h b/ispc.h index ba5ce632..a2cacc99 100644 --- a/ispc.h +++ b/ispc.h @@ -367,6 +367,8 @@ enum { COST_TASK_LAUNCH = 16, COST_TYPECAST_COMPLEX = 4, COST_TYPECAST_SIMPLE = 1, + COST_UNIFORM_IF = 2, + COST_VARYING_IF = 3, COST_UNIFORM_LOOP = 4, COST_VARYING_LOOP = 6, COST_ASSERT = 8, diff --git a/stmt.cpp b/stmt.cpp index b2c43b4d..364f931b 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -541,9 +541,15 @@ Stmt *IfStmt::TypeCheck() { int IfStmt::EstimateCost() const { - return ((test ? test->EstimateCost() : 0) + - (trueStmts ? trueStmts->EstimateCost() : 0) + - (falseStmts ? falseStmts->EstimateCost() : 0)); + int ifcost = 0; + const Type *type; + if (test && (type = test->GetType()) != NULL) + ifcost = type->IsUniformType() ? COST_UNIFORM_IF : COST_VARYING_IF; + + return ifcost + + ((test ? test->EstimateCost() : 0) + + (trueStmts ? trueStmts->EstimateCost() : 0) + + (falseStmts ? falseStmts->EstimateCost() : 0)); }