Add support for constant-folded array inequality checks.

This isn't something I expect to occur often. However, we have always
reported that array-ctors with constant arguments are compile-time
constants, and `compareConstant` is supposed to be implemented for all
compile-time constants.

Change-Id: I0bbfe2a3f78c29c14f69c3b6faca71067a0e45c8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/391116
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2021-03-31 11:33:48 -04:00 committed by Skia Commit-Bot
parent d4756598de
commit 22a54543a8
3 changed files with 15 additions and 5 deletions

View File

@ -517,8 +517,9 @@ std::unique_ptr<Expression> ConstantFolder::Simplify(const Context& context,
return nullptr;
}
// Perform constant folding on pairs of matrices.
if (leftType.isMatrix() && rightType.isMatrix()) {
// Perform constant folding on pairs of matrices or arrays.
if ((leftType.isMatrix() && rightType.isMatrix()) ||
(leftType.isArray() && rightType.isArray())) {
bool equality;
switch (op.kind()) {
case Token::Kind::TK_EQEQ:

View File

@ -294,6 +294,17 @@ Expression::ComparisonResult Constructor::compareConstant(const Expression& othe
return ComparisonResult::kEqual;
}
if (myType.isArray()) {
SkASSERT(myType.columns() == c.type().columns());
for (int col = 0; col < myType.columns(); col++) {
ComparisonResult check = this->arguments()[col]->compareConstant(*c.arguments()[col]);
if (check != ComparisonResult::kEqual) {
return check;
}
}
return ComparisonResult::kEqual;
}
SkDEBUGFAILF("compareConstant unexpected type: %s", myType.description().c_str());
return ComparisonResult::kUnknown;
}

View File

@ -3,7 +3,5 @@ out vec4 sk_FragColor;
uniform vec4 colorRed;
uniform vec4 colorGreen;
vec4 main() {
const int _0_x[3] = int[3](1, 2, 3);
const int _2_y[3] = int[3](1, 2, 4);
return _0_x != _2_y && !(_0_x == _2_y) ? colorGreen : colorRed;
return true ? colorGreen : colorRed;
}