[spirv-writer] Emit ShiftRightArithmetic.

This CL updates the SPIR-V writer to emit the arithmetic right shift if
the LHS of the expression is a signed scalar or vector.

Bug: tint:84
Change-Id: I4ca33a31783e1954515db5f12b2cf1d364aedee4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28940
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index f6299e7..b2fcdf1 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -1428,10 +1428,10 @@
     op = spv::Op::OpBitwiseOr;
   } else if (expr->IsShiftLeft()) {
     op = spv::Op::OpShiftLeftLogical;
+  } else if (expr->IsShiftRight() && lhs_type->is_signed_scalar_or_vector()) {
+    // A shift right with a signed LHS is an arithmetic shift.
+    op = spv::Op::OpShiftRightArithmetic;
   } 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->IsSubtract()) {
     op = lhs_is_float_or_vec ? spv::Op::OpFSub : spv::Op::OpISub;
diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc
index 62986ec..a49241c 100644
--- a/src/writer/spirv/builder_binary_expression_test.cc
+++ b/src/writer/spirv/builder_binary_expression_test.cc
@@ -135,7 +135,7 @@
                     BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
                     BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
                     BinaryData{ast::BinaryOp::kShiftRight,
-                               "OpShiftRightLogical"},
+                               "OpShiftRightArithmetic"},
                     BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
                     BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));