spirv-writer: Fix | and & on bool and bool-vec
Fixed: tint:861
Change-Id: Ib9709b3793fb5c405f4ba519c189295999f556ee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53280
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index fc6cbb5..a076318 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -1892,7 +1892,14 @@
spv::Op op = spv::Op::OpNop;
if (expr->IsAnd()) {
- op = spv::Op::OpBitwiseAnd;
+ if (lhs_is_integer_or_vec) {
+ op = spv::Op::OpBitwiseAnd;
+ } else if (lhs_is_bool_or_vec) {
+ op = spv::Op::OpLogicalAnd;
+ } else {
+ error_ = "invalid and expression";
+ return 0;
+ }
} else if (expr->IsAdd()) {
op = lhs_is_float_or_vec ? spv::Op::OpFAdd : spv::Op::OpIAdd;
} else if (expr->IsDivide()) {
@@ -2006,7 +2013,14 @@
return 0;
}
} else if (expr->IsOr()) {
- op = spv::Op::OpBitwiseOr;
+ if (lhs_is_integer_or_vec) {
+ op = spv::Op::OpBitwiseOr;
+ } else if (lhs_is_bool_or_vec) {
+ op = spv::Op::OpLogicalOr;
+ } else {
+ error_ = "invalid and expression";
+ return 0;
+ }
} else if (expr->IsShiftLeft()) {
op = spv::Op::OpShiftLeftLogical;
} else if (expr->IsShiftRight() && lhs_type->is_signed_scalar_or_vector()) {
diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc
index f18f460..ac4100f 100644
--- a/src/writer/spirv/builder_binary_expression_test.cc
+++ b/src/writer/spirv/builder_binary_expression_test.cc
@@ -250,8 +250,8 @@
BinaryData{ast::BinaryOp::kMultiply, "OpFMul"},
BinaryData{ast::BinaryOp::kSubtract, "OpFSub"}));
-using BinaryCompareBoolTest = TestParamHelper<BinaryData>;
-TEST_P(BinaryCompareBoolTest, Scalar) {
+using BinaryOperatorBoolTest = TestParamHelper<BinaryData>;
+TEST_P(BinaryOperatorBoolTest, Scalar) {
auto param = GetParam();
auto* lhs = Expr(true);
@@ -274,7 +274,7 @@
"%4 = " + param.name + " %1 %2 %3\n");
}
-TEST_P(BinaryCompareBoolTest, Vector) {
+TEST_P(BinaryOperatorBoolTest, Vector) {
auto param = GetParam();
auto* lhs = vec3<bool>(false, true, false);
@@ -301,9 +301,11 @@
}
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
- BinaryCompareBoolTest,
+ BinaryOperatorBoolTest,
testing::Values(BinaryData{ast::BinaryOp::kEqual, "OpLogicalEqual"},
- BinaryData{ast::BinaryOp::kNotEqual, "OpLogicalNotEqual"}));
+ BinaryData{ast::BinaryOp::kNotEqual, "OpLogicalNotEqual"},
+ BinaryData{ast::BinaryOp::kAnd, "OpLogicalAnd"},
+ BinaryData{ast::BinaryOp::kOr, "OpLogicalOr"}));
using BinaryCompareUnsignedIntegerTest = TestParamHelper<BinaryData>;
TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {