Remove right shift arithmetic operand.
The `>>>` symbol was folded into the `>>` symbol in WGSL. This CL
removes `>>>` from Tint.
Change-Id: I9d900de9a6026a8099796b94aad44483f0c6813f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22582
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/src/ast/binary_expression.h b/src/ast/binary_expression.h
index 00fdf66..9724ad2 100644
--- a/src/ast/binary_expression.h
+++ b/src/ast/binary_expression.h
@@ -40,7 +40,6 @@
kGreaterThanEqual,
kShiftLeft,
kShiftRight,
- kShiftRightArith,
kAdd,
kSubtract,
kMultiply,
@@ -105,8 +104,6 @@
bool IsShiftLeft() const { return op_ == BinaryOp::kShiftLeft; }
/// @returns true if the op is shift right
bool IsShiftRight() const { return op_ == BinaryOp::kShiftRight; }
- /// @returns true if the op is shift right arith
- bool IsShiftRightArith() const { return op_ == BinaryOp::kShiftRightArith; }
/// @returns true if the op is add
bool IsAdd() const { return op_ == BinaryOp::kAdd; }
/// @returns true if the op is subtract
@@ -193,9 +190,6 @@
case BinaryOp::kShiftRight:
out << "shift_right";
break;
- case BinaryOp::kShiftRightArith:
- out << "shift_right_arith";
- break;
case BinaryOp::kAdd:
out << "add";
break;
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index eb1e6fc..f826786 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -199,9 +199,8 @@
case SpvOpShiftLeftLogical:
return ast::BinaryOp::kShiftLeft;
case SpvOpShiftRightLogical:
- return ast::BinaryOp::kShiftRight;
case SpvOpShiftRightArithmetic:
- return ast::BinaryOp::kShiftRightArith;
+ return ast::BinaryOp::kShiftRight;
case SpvOpLogicalEqual:
case SpvOpIEqual:
case SpvOpFOrdEqual:
diff --git a/src/reader/spirv/function_bit_test.cc b/src/reader/spirv/function_bit_test.cc
index e32421e..549be19 100644
--- a/src/reader/spirv/function_bit_test.cc
+++ b/src/reader/spirv/function_bit_test.cc
@@ -246,36 +246,36 @@
::testing::Values(
// Both uint
BinaryData{"uint", "uint_10", "OpShiftRightArithmetic", "uint_20",
- "__u32", "ScalarConstructor{10}", "shift_right_arith",
+ "__u32", "ScalarConstructor{10}", "shift_right",
"ScalarConstructor{20}"},
// Both int
BinaryData{"int", "int_30", "OpShiftRightArithmetic", "int_40", "__i32",
- "ScalarConstructor{30}", "shift_right_arith",
+ "ScalarConstructor{30}", "shift_right",
"ScalarConstructor{40}"},
// Mixed, returning uint
BinaryData{"uint", "int_30", "OpShiftRightArithmetic", "uint_10",
- "__u32", "ScalarConstructor{30}", "shift_right_arith",
+ "__u32", "ScalarConstructor{30}", "shift_right",
"ScalarConstructor{10}"},
// Mixed, returning int
BinaryData{"int", "int_30", "OpShiftRightArithmetic", "uint_10",
- "__i32", "ScalarConstructor{30}", "shift_right_arith",
+ "__i32", "ScalarConstructor{30}", "shift_right",
"ScalarConstructor{10}"},
// Both v2uint
BinaryData{"v2uint", "v2uint_10_20", "OpShiftRightArithmetic",
"v2uint_20_10", "__vec_2__u32", AstFor("v2uint_10_20"),
- "shift_right_arith", AstFor("v2uint_20_10")},
+ "shift_right", AstFor("v2uint_20_10")},
// Both v2int
BinaryData{"v2int", "v2int_30_40", "OpShiftRightArithmetic",
"v2int_40_30", "__vec_2__i32", AstFor("v2int_30_40"),
- "shift_right_arith", AstFor("v2int_40_30")},
+ "shift_right", AstFor("v2int_40_30")},
// Mixed, returning v2uint
BinaryData{"v2uint", "v2int_30_40", "OpShiftRightArithmetic",
"v2uint_10_20", "__vec_2__u32", AstFor("v2int_30_40"),
- "shift_right_arith", AstFor("v2uint_10_20")},
+ "shift_right", AstFor("v2uint_10_20")},
// Mixed, returning v2int
BinaryData{"v2int", "v2int_40_30", "OpShiftRightArithmetic",
"v2uint_20_10", "__vec_2__i32", AstFor("v2int_40_30"),
- "shift_right_arith", AstFor("v2uint_20_10")}));
+ "shift_right", AstFor("v2uint_20_10")}));
INSTANTIATE_TEST_SUITE_P(
SpvParserTest_BitwiseAnd,
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 1367bce..1886d62 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -2291,13 +2291,11 @@
// :
// | LESS_THAN LESS_THAN additive_expression shift_expr
// | GREATER_THAN GREATER_THAN additive_expression shift_expr
-// | GREATER_THAN GREATER_THAN GREATER_THAN additive_expression shift_expr
std::unique_ptr<ast::Expression> ParserImpl::shift_expr(
std::unique_ptr<ast::Expression> lhs) {
auto t = peek();
auto source = t.source();
auto t2 = peek(1);
- auto t3 = peek(2);
auto* name = "";
ast::BinaryOp op = ast::BinaryOp::kNone;
@@ -2306,12 +2304,6 @@
next(); // Consume the t2 peek
op = ast::BinaryOp::kShiftLeft;
name = "<<";
- } else if (t.IsGreaterThan() && t2.IsGreaterThan() && t3.IsGreaterThan()) {
- next(); // Consume the t peek
- next(); // Consume the t2 peek
- next(); // Consume the t3 peek
- op = ast::BinaryOp::kShiftRightArith;
- name = ">>>";
} else if (t.IsGreaterThan() && t2.IsGreaterThan()) {
next(); // Consume the t peek
next(); // Consume the t2 peek
diff --git a/src/reader/wgsl/parser_impl_shift_expression_test.cc b/src/reader/wgsl/parser_impl_shift_expression_test.cc
index 25b3fde..2acf06b 100644
--- a/src/reader/wgsl/parser_impl_shift_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_shift_expression_test.cc
@@ -67,27 +67,6 @@
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
-TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRightArith) {
- auto* p = parser("a >>> true");
- auto e = p->shift_expression();
- ASSERT_FALSE(p->has_error()) << p->error();
- ASSERT_NE(e, nullptr);
-
- ASSERT_TRUE(e->IsBinary());
- auto* rel = e->AsBinary();
- EXPECT_EQ(ast::BinaryOp::kShiftRightArith, rel->op());
-
- ASSERT_TRUE(rel->lhs()->IsIdentifier());
- auto* ident = rel->lhs()->AsIdentifier();
- EXPECT_EQ(ident->name(), "a");
-
- ASSERT_TRUE(rel->rhs()->IsConstructor());
- ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
- auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
- ASSERT_TRUE(init->literal()->IsBool());
- ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
-}
-
TEST_F(ParserImplTest, ShiftExpression_InvalidLHS) {
auto* p = parser("if (a) {} << true");
auto e = p->shift_expression();
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 14eb480..4a562df 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -558,8 +558,8 @@
// Result type matches first parameter type
if (expr->IsAnd() || expr->IsOr() || expr->IsXor() || expr->IsShiftLeft() ||
- expr->IsShiftRight() || expr->IsShiftRightArith() || expr->IsAdd() ||
- expr->IsSubtract() || expr->IsDivide() || expr->IsModulo()) {
+ expr->IsShiftRight() || expr->IsAdd() || expr->IsSubtract() ||
+ expr->IsDivide() || expr->IsModulo()) {
expr->set_result_type(expr->lhs()->result_type()->UnwrapPtrIfNeeded());
return true;
}
diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc
index 124407a..1cdca1a 100644
--- a/src/type_determiner_test.cc
+++ b/src/type_determiner_test.cc
@@ -953,7 +953,6 @@
ast::BinaryOp::kXor,
ast::BinaryOp::kShiftLeft,
ast::BinaryOp::kShiftRight,
- ast::BinaryOp::kShiftRightArith,
ast::BinaryOp::kAdd,
ast::BinaryOp::kSubtract,
ast::BinaryOp::kDivide,
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index cc3b433..7feaab3 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -1144,9 +1144,10 @@
} else if (expr->IsShiftLeft()) {
op = spv::Op::OpShiftLeftLogical;
} else if (expr->IsShiftRight()) {
+ // TODO(dsinclair): This depends on the type of the LHS if it's a
+ // OpShiftRightLogical or OpShiftRightArithmetic
+ // http://crbug.com/tint/84
op = spv::Op::OpShiftRightLogical;
- } else if (expr->IsShiftRightArith()) {
- op = spv::Op::OpShiftRightArithmetic;
} else if (expr->IsSubtract()) {
op = lhs_is_float_or_vec ? spv::Op::OpFSub : spv::Op::OpISub;
} else if (expr->IsXor()) {
diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc
index 83f7ebb..3d4899f 100644
--- a/src/writer/spirv/builder_binary_expression_test.cc
+++ b/src/writer/spirv/builder_binary_expression_test.cc
@@ -125,18 +125,17 @@
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryArithSignedIntegerTest,
- testing::Values(
- BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
- BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
- BinaryData{ast::BinaryOp::kDivide, "OpSDiv"},
- BinaryData{ast::BinaryOp::kModulo, "OpSMod"},
- BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
- BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
- BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
- BinaryData{ast::BinaryOp::kShiftRight, "OpShiftRightLogical"},
- BinaryData{ast::BinaryOp::kShiftRightArith, "OpShiftRightArithmetic"},
- BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
- BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
+ testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
+ BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
+ BinaryData{ast::BinaryOp::kDivide, "OpSDiv"},
+ BinaryData{ast::BinaryOp::kModulo, "OpSMod"},
+ BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
+ BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
+ BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
+ BinaryData{ast::BinaryOp::kShiftRight,
+ "OpShiftRightLogical"},
+ BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
+ BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
using BinaryArithUnsignedIntegerTest = testing::TestWithParam<BinaryData>;
TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
@@ -215,18 +214,17 @@
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryArithUnsignedIntegerTest,
- testing::Values(
- BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
- BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
- BinaryData{ast::BinaryOp::kDivide, "OpUDiv"},
- BinaryData{ast::BinaryOp::kModulo, "OpUMod"},
- BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
- BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
- BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
- BinaryData{ast::BinaryOp::kShiftRight, "OpShiftRightLogical"},
- BinaryData{ast::BinaryOp::kShiftRightArith, "OpShiftRightArithmetic"},
- BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
- BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
+ testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
+ BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
+ BinaryData{ast::BinaryOp::kDivide, "OpUDiv"},
+ BinaryData{ast::BinaryOp::kModulo, "OpUMod"},
+ BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
+ BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
+ BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
+ BinaryData{ast::BinaryOp::kShiftRight,
+ "OpShiftRightLogical"},
+ BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
+ BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
using BinaryArithFloatTest = testing::TestWithParam<BinaryData>;
TEST_P(BinaryArithFloatTest, Scalar) {
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index 3093e61..df1506a 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -554,9 +554,6 @@
case ast::BinaryOp::kShiftRight:
out_ << ">>";
break;
- case ast::BinaryOp::kShiftRightArith:
- out_ << ">>>";
- break;
case ast::BinaryOp::kAdd:
out_ << "+";
break;
diff --git a/src/writer/wgsl/generator_impl_relational_test.cc b/src/writer/wgsl/generator_impl_relational_test.cc
index 983b29c..9006135 100644
--- a/src/writer/wgsl/generator_impl_relational_test.cc
+++ b/src/writer/wgsl/generator_impl_relational_test.cc
@@ -62,7 +62,6 @@
BinaryData{"(left >= right)", ast::BinaryOp::kGreaterThanEqual},
BinaryData{"(left << right)", ast::BinaryOp::kShiftLeft},
BinaryData{"(left >> right)", ast::BinaryOp::kShiftRight},
- BinaryData{"(left >>> right)", ast::BinaryOp::kShiftRightArith},
BinaryData{"(left + right)", ast::BinaryOp::kAdd},
BinaryData{"(left - right)", ast::BinaryOp::kSubtract},
BinaryData{"(left * right)", ast::BinaryOp::kMultiply},