diff --git a/src/tint/ir/binary_test.cc b/src/tint/ir/binary_test.cc index 9b7fd073ed..6a96633dc9 100644 --- a/src/tint/ir/binary_test.cc +++ b/src/tint/ir/binary_test.cc @@ -203,6 +203,25 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) { EXPECT_EQ(2_i, rhs->As>()->ValueAs()); } +TEST_F(IR_InstructionTest, CreateNot) { + auto& b = CreateEmptyBuilder(); + const auto* inst = + b.builder.Not(b.builder.ir.types.Get(), b.builder.Constant(true)); + + ASSERT_TRUE(inst->Is()); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kEqual); + + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; + ASSERT_TRUE(lhs->Is>()); + EXPECT_TRUE(lhs->As>()->ValueAs()); + + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; + ASSERT_TRUE(rhs->Is>()); + EXPECT_FALSE(rhs->As>()->ValueAs()); +} + TEST_F(IR_InstructionTest, CreateShiftLeft) { auto& b = CreateEmptyBuilder(); diff --git a/src/tint/ir/builder.cc b/src/tint/ir/builder.cc index 8badd31809..e826be4d93 100644 --- a/src/tint/ir/builder.cc +++ b/src/tint/ir/builder.cc @@ -16,6 +16,8 @@ #include +#include "src/tint/constant/scalar.h" + namespace tint::ir { Builder::Builder() {} @@ -194,8 +196,8 @@ Unary* Builder::Negation(const type::Type* type, Value* val) { return CreateUnary(Unary::Kind::kNegation, type, val); } -Unary* Builder::Not(const type::Type* type, Value* val) { - return CreateUnary(Unary::Kind::kNot, type, val); +Binary* Builder::Not(const type::Type* type, Value* val) { + return Equal(type, val, Constant(create>(type, false))); } ir::Bitcast* Builder::Bitcast(const type::Type* type, Value* val) { diff --git a/src/tint/ir/builder.h b/src/tint/ir/builder.h index 24c20d0c63..ff01e2deeb 100644 --- a/src/tint/ir/builder.h +++ b/src/tint/ir/builder.h @@ -300,7 +300,7 @@ class Builder { /// @param type the result type of the expression /// @param val the value /// @returns the operation - Unary* Not(const type::Type* type, Value* val); + Binary* Not(const type::Type* type, Value* val); /// Creates a bitcast instruction /// @param type the result type of the bitcast diff --git a/src/tint/ir/builder_impl.cc b/src/tint/ir/builder_impl.cc index 2a42917420..2d6530e7e7 100644 --- a/src/tint/ir/builder_impl.cc +++ b/src/tint/ir/builder_impl.cc @@ -833,7 +833,7 @@ utils::Result BuilderImpl::EmitUnary(const ast::UnaryOpExpression* expr) auto* sem = program_->Sem().Get(expr); auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx); - Unary* inst = nullptr; + Instruction* inst = nullptr; switch (expr->op) { case ast::UnaryOp::kAddressOf: inst = builder.AddressOf(ty, val.Get()); diff --git a/src/tint/ir/disassembler.cc b/src/tint/ir/disassembler.cc index ffda493bc6..ec17624a4b 100644 --- a/src/tint/ir/disassembler.cc +++ b/src/tint/ir/disassembler.cc @@ -493,9 +493,6 @@ void Disassembler::EmitUnary(const Unary* u) { case Unary::Kind::kNegation: out_ << "negation"; break; - case Unary::Kind::kNot: - out_ << "not"; - break; } out_ << " "; EmitValue(u->Val()); diff --git a/src/tint/ir/unary.h b/src/tint/ir/unary.h index 297e48f1ee..64301d4d09 100644 --- a/src/tint/ir/unary.h +++ b/src/tint/ir/unary.h @@ -29,7 +29,6 @@ class Unary : public utils::Castable { kComplement, kIndirection, kNegation, - kNot, }; /// Constructor diff --git a/src/tint/ir/unary_test.cc b/src/tint/ir/unary_test.cc index ace90eb9f8..e205d8fe24 100644 --- a/src/tint/ir/unary_test.cc +++ b/src/tint/ir/unary_test.cc @@ -87,20 +87,6 @@ TEST_F(IR_InstructionTest, CreateNegation) { EXPECT_EQ(4_i, lhs->As>()->ValueAs()); } -TEST_F(IR_InstructionTest, CreateNot) { - auto& b = CreateEmptyBuilder(); - const auto* inst = - b.builder.Not(b.builder.ir.types.Get(), b.builder.Constant(true)); - - ASSERT_TRUE(inst->Is()); - EXPECT_EQ(inst->GetKind(), Unary::Kind::kNot); - - ASSERT_TRUE(inst->Val()->Is()); - auto lhs = inst->Val()->As()->value; - ASSERT_TRUE(lhs->Is>()); - EXPECT_TRUE(lhs->As>()->ValueAs()); -} - TEST_F(IR_InstructionTest, Unary_Usage) { auto& b = CreateEmptyBuilder(); const auto* inst =