[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 <rharrison@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-09-23 14:45:24 +00:00 committed by Commit Bot service account
parent d7abd76dea
commit 596fcdcec6
2 changed files with 10 additions and 7 deletions

View File

@ -1010,7 +1010,7 @@ uint32_t Builder::GenerateUnaryOpExpression(ast::UnaryOpExpression* expr) {
op = spv::Op::OpSNegate; op = spv::Op::OpSNegate;
} }
} else if (expr->op() == ast::UnaryOp::kNot) { } else if (expr->op() == ast::UnaryOp::kNot) {
op = spv::Op::OpNot; op = spv::Op::OpLogicalNot;
} }
if (op == spv::Op::OpNop) { if (op == spv::Op::OpNop) {
error_ = "invalid unary op type"; error_ = "invalid unary op type";

View File

@ -15,10 +15,12 @@
#include <memory> #include <memory>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
#include "src/ast/float_literal.h" #include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.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/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/unary_op_expression.h" #include "src/ast/unary_op_expression.h"
@ -85,11 +87,12 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
} }
TEST_F(BuilderTest, UnaryOp_Not) { TEST_F(BuilderTest, UnaryOp_Not) {
ast::type::I32Type i32; ast::type::BoolType bool_type;
ast::UnaryOpExpression expr( ast::UnaryOpExpression expr(
ast::UnaryOp::kNot, std::make_unique<ast::ScalarConstructorExpression>( ast::UnaryOp::kNot,
std::make_unique<ast::SintLiteral>(&i32, 1))); std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, false)));
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
@ -100,11 +103,11 @@ TEST_F(BuilderTest, UnaryOp_Not) {
Builder b(&mod); Builder b(&mod);
b.push_function(Function{}); b.push_function(Function{});
EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 1u) << b.error(); EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 1u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
%3 = OpConstant %2 1 %3 = OpConstantFalse %2
)"); )");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(%1 = OpNot %2 %3 R"(%1 = OpLogicalNot %2 %3
)"); )");
} }