Disable constant-variable substitution when optimization is off.

When optimization is disabled, I did not expect to see arithmetic like
`color * ONE` disappear (even though it's just a constant fold):

    const vec4 ONE = half4(1);
    vec4 x = color * ONE;

Change-Id: Id24a632712591c73a904b90e5efdba092d846c0e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/382477
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-03-09 20:15:17 -05:00 committed by Skia Commit-Bot
parent 0dd1a77e12
commit be6cbf331c

View File

@ -312,9 +312,16 @@ std::unique_ptr<Expression> ConstantFolder::Simplify(const Context& context,
Operator op,
const Expression& rightExpr,
const Type& resultType) {
// Replace constant variables with trivial initial-values.
const Expression* left = GetConstantValueForVariable(leftExpr);
const Expression* right = GetConstantValueForVariable(rightExpr);
// When optimization is enabled, replace constant variables with trivial initial-values.
const Expression* left;
const Expression* right;
if (context.fConfig->fSettings.fOptimize) {
left = GetConstantValueForVariable(leftExpr);
right = GetConstantValueForVariable(rightExpr);
} else {
left = &leftExpr;
right = &rightExpr;
}
// If this is the comma operator, the left side is evaluated but not otherwise used in any way.
// So if the left side has no side effects, it can just be eliminated entirely.