Optimize SkSL xor where one argument is constant
Change-Id: I9ea41625fd80433f7f6480fe539321d8df7b7930
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/258877
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index fa7c83c..9ee469e 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -1495,8 +1495,12 @@
// (true || expr) -> (true) and (false || expr) -> (expr)
return leftVal ? std::unique_ptr<Expression>(new BoolLiteral(context, left.fOffset, true))
: right.clone();
+ } else if (op == Token::LOGICALXOR) {
+ // (true ^^ expr) -> !(expr) and (false ^^ expr) -> (expr)
+ return leftVal ? std::unique_ptr<Expression>(new PrefixExpression(Token::LOGICALNOT,
+ right.clone()))
+ : right.clone();
} else {
- // Can't short circuit XOR
return nullptr;
}
}