From be6cbf331c5a0a1b087cb1d082879253f72416ca Mon Sep 17 00:00:00 2001 From: John Stiles Date: Tue, 9 Mar 2021 20:15:17 -0500 Subject: [PATCH] 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 Auto-Submit: John Stiles Reviewed-by: Ethan Nicholas --- src/sksl/SkSLConstantFolder.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sksl/SkSLConstantFolder.cpp b/src/sksl/SkSLConstantFolder.cpp index 1f0ec47b04..c397cab5b5 100644 --- a/src/sksl/SkSLConstantFolder.cpp +++ b/src/sksl/SkSLConstantFolder.cpp @@ -312,9 +312,16 @@ std::unique_ptr 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.