From 596fcdcec629a55cec5af6720ebf8028c7dd7f64 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 23 Sep 2020 14:45:24 +0000 Subject: [PATCH] [spirv-writer] Fix ! to emit logical not. The ! operator should emit an OpLogicalNot instead of an OpNot. Bug: tint:248 Change-Id: I6e404c3286db7819e0692603e3cf9a87a1b37ed9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28841 Commit-Queue: Ryan Harrison Reviewed-by: Corentin Wallez Reviewed-by: Ryan Harrison --- src/writer/spirv/builder.cc | 2 +- .../spirv/builder_unary_op_expression_test.cc | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index a1a004ed1f..f6299e711e 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -1010,7 +1010,7 @@ uint32_t Builder::GenerateUnaryOpExpression(ast::UnaryOpExpression* expr) { op = spv::Op::OpSNegate; } } else if (expr->op() == ast::UnaryOp::kNot) { - op = spv::Op::OpNot; + op = spv::Op::OpLogicalNot; } if (op == spv::Op::OpNop) { error_ = "invalid unary op type"; diff --git a/src/writer/spirv/builder_unary_op_expression_test.cc b/src/writer/spirv/builder_unary_op_expression_test.cc index 2b4be370b4..2ca7f094e1 100644 --- a/src/writer/spirv/builder_unary_op_expression_test.cc +++ b/src/writer/spirv/builder_unary_op_expression_test.cc @@ -15,10 +15,12 @@ #include #include "gtest/gtest.h" +#include "src/ast/bool_literal.h" #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" +#include "src/ast/type/bool_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/unary_op_expression.h" @@ -85,11 +87,12 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) { } TEST_F(BuilderTest, UnaryOp_Not) { - ast::type::I32Type i32; + ast::type::BoolType bool_type; ast::UnaryOpExpression expr( - ast::UnaryOp::kNot, std::make_unique( - std::make_unique(&i32, 1))); + ast::UnaryOp::kNot, + std::make_unique( + std::make_unique(&bool_type, false))); Context ctx; ast::Module mod; @@ -100,11 +103,11 @@ TEST_F(BuilderTest, UnaryOp_Not) { Builder b(&mod); b.push_function(Function{}); EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 1u) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 -%3 = OpConstant %2 1 + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool +%3 = OpConstantFalse %2 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%1 = OpNot %2 %3 + R"(%1 = OpLogicalNot %2 %3 )"); }