diff --git a/src/tint/ir/binary.cc b/src/tint/ir/binary.cc index d3e3548564..cde8533d48 100644 --- a/src/tint/ir/binary.cc +++ b/src/tint/ir/binary.cc @@ -49,19 +49,13 @@ utils::StringStream& Binary::ToInstruction(utils::StringStream& out) const { out << "mod"; break; case Binary::Kind::kAnd: - out << "bit_and"; + out << "and"; break; case Binary::Kind::kOr: - out << "bit_or"; + out << "or"; break; case Binary::Kind::kXor: - out << "bit_xor"; - break; - case Binary::Kind::kLogicalAnd: - out << "log_and"; - break; - case Binary::Kind::kLogicalOr: - out << "log_or"; + out << "xor"; break; case Binary::Kind::kEqual: out << "eq"; diff --git a/src/tint/ir/binary.h b/src/tint/ir/binary.h index 92a19984cf..8ce3b48d36 100644 --- a/src/tint/ir/binary.h +++ b/src/tint/ir/binary.h @@ -36,9 +36,6 @@ class Binary : public utils::Castable { kOr, kXor, - kLogicalAnd, - kLogicalOr, - kEqual, kNotEqual, kLessThan, diff --git a/src/tint/ir/binary_test.cc b/src/tint/ir/binary_test.cc index e03a61d1a4..056e02f23f 100644 --- a/src/tint/ir/binary_test.cc +++ b/src/tint/ir/binary_test.cc @@ -45,7 +45,7 @@ TEST_F(IR_InstructionTest, CreateAnd) { utils::StringStream str; inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(i32) = bit_and 4i, 2i"); + EXPECT_EQ(str.str(), "%1(i32) = and 4i, 2i"); } TEST_F(IR_InstructionTest, CreateOr) { @@ -69,7 +69,7 @@ TEST_F(IR_InstructionTest, CreateOr) { utils::StringStream str; inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(i32) = bit_or 4i, 2i"); + EXPECT_EQ(str.str(), "%1(i32) = or 4i, 2i"); } TEST_F(IR_InstructionTest, CreateXor) { @@ -93,55 +93,7 @@ TEST_F(IR_InstructionTest, CreateXor) { utils::StringStream str; inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(i32) = bit_xor 4i, 2i"); -} - -TEST_F(IR_InstructionTest, CreateLogicalAnd) { - auto& b = CreateEmptyBuilder(); - - const auto* inst = b.builder.LogicalAnd(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); - - ASSERT_TRUE(inst->Is()); - EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalAnd); - - ASSERT_TRUE(inst->LHS()->Is()); - auto lhs = inst->LHS()->As()->value; - ASSERT_TRUE(lhs->Is>()); - EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - - ASSERT_TRUE(inst->RHS()->Is()); - auto rhs = inst->RHS()->As()->value; - ASSERT_TRUE(rhs->Is>()); - EXPECT_EQ(2_i, rhs->As>()->ValueAs()); - - utils::StringStream str; - inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(bool) = log_and 4i, 2i"); -} - -TEST_F(IR_InstructionTest, CreateLogicalOr) { - auto& b = CreateEmptyBuilder(); - - const auto* inst = b.builder.LogicalOr(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); - - ASSERT_TRUE(inst->Is()); - EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalOr); - - ASSERT_TRUE(inst->LHS()->Is()); - auto lhs = inst->LHS()->As()->value; - ASSERT_TRUE(lhs->Is>()); - EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - - ASSERT_TRUE(inst->RHS()->Is()); - auto rhs = inst->RHS()->As()->value; - ASSERT_TRUE(rhs->Is>()); - EXPECT_EQ(2_i, rhs->As>()->ValueAs()); - - utils::StringStream str; - inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(bool) = log_or 4i, 2i"); + EXPECT_EQ(str.str(), "%1(i32) = xor 4i, 2i"); } TEST_F(IR_InstructionTest, CreateEqual) { diff --git a/src/tint/ir/builder.cc b/src/tint/ir/builder.cc index 2c97737a2b..7090cb6e39 100644 --- a/src/tint/ir/builder.cc +++ b/src/tint/ir/builder.cc @@ -118,14 +118,6 @@ Binary* Builder::Xor(const type::Type* type, Value* lhs, Value* rhs) { return CreateBinary(Binary::Kind::kXor, type, lhs, rhs); } -Binary* Builder::LogicalAnd(const type::Type* type, Value* lhs, Value* rhs) { - return CreateBinary(Binary::Kind::kLogicalAnd, type, lhs, rhs); -} - -Binary* Builder::LogicalOr(const type::Type* type, Value* lhs, Value* rhs) { - return CreateBinary(Binary::Kind::kLogicalOr, type, lhs, rhs); -} - Binary* Builder::Equal(const type::Type* type, Value* lhs, Value* rhs) { return CreateBinary(Binary::Kind::kEqual, type, lhs, rhs); } diff --git a/src/tint/ir/builder.h b/src/tint/ir/builder.h index d509c06164..618679bf6e 100644 --- a/src/tint/ir/builder.h +++ b/src/tint/ir/builder.h @@ -170,20 +170,6 @@ class Builder { /// @returns the operation Binary* Xor(const type::Type* type, Value* lhs, Value* rhs); - /// Creates an LogicalAnd operation - /// @param type the result type of the expression - /// @param lhs the lhs of the add - /// @param rhs the rhs of the add - /// @returns the operation - Binary* LogicalAnd(const type::Type* type, Value* lhs, Value* rhs); - - /// Creates an LogicalOr operation - /// @param type the result type of the expression - /// @param lhs the lhs of the add - /// @param rhs the rhs of the add - /// @returns the operation - Binary* LogicalOr(const type::Type* type, Value* lhs, Value* rhs); - /// Creates an Equal operation /// @param type the result type of the expression /// @param lhs the lhs of the add diff --git a/src/tint/ir/builder_impl.cc b/src/tint/ir/builder_impl.cc index fd6f500298..cce89a481e 100644 --- a/src/tint/ir/builder_impl.cc +++ b/src/tint/ir/builder_impl.cc @@ -309,12 +309,6 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement* case ast::BinaryOp::kXor: inst = builder.Xor(ty, lhs.Get(), rhs.Get()); break; - case ast::BinaryOp::kLogicalAnd: - inst = builder.LogicalAnd(ty, lhs.Get(), rhs.Get()); - break; - case ast::BinaryOp::kLogicalOr: - inst = builder.LogicalOr(ty, lhs.Get(), rhs.Get()); - break; case ast::BinaryOp::kEqual: inst = builder.Equal(ty, lhs.Get(), rhs.Get()); break; @@ -354,6 +348,10 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement* case ast::BinaryOp::kModulo: inst = builder.Modulo(ty, lhs.Get(), rhs.Get()); break; + case ast::BinaryOp::kLogicalAnd: + case ast::BinaryOp::kLogicalOr: + TINT_ICE(IR, diagnostics_) << "invalid compound assignment"; + return; case ast::BinaryOp::kNone: TINT_ICE(IR, diagnostics_) << "missing binary operand type"; return; @@ -790,11 +788,13 @@ utils::Result BuilderImpl::EmitShortCircuit(const ast::BinaryExpression* return utils::Failure; } + // Evaluate the LHS of the short-circuit auto lhs = EmitExpression(expr->lhs); if (!lhs) { return utils::Failure; } + // Generate a variable to store the short-circut into auto* ty = builder.ir.types.Get(); auto* result_var = builder.Declare(ty, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); diff --git a/src/tint/ir/builder_impl_test.cc b/src/tint/ir/builder_impl_test.cc index bcba641637..4df35bfd19 100644 --- a/src/tint/ir/builder_impl_test.cc +++ b/src/tint/ir/builder_impl_test.cc @@ -1728,7 +1728,7 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_And) { Disassembler d(b.builder.ir); d.EmitBlockInstructions(b.current_flow_block->As()); EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func -%2(u32) = bit_and %1(u32), 4u +%2(u32) = and %1(u32), 4u )"); } @@ -1746,7 +1746,7 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_Or) { Disassembler d(b.builder.ir); d.EmitBlockInstructions(b.current_flow_block->As()); EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func -%2(u32) = bit_or %1(u32), 4u +%2(u32) = or %1(u32), 4u )"); } @@ -1764,7 +1764,7 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_Xor) { Disassembler d(b.builder.ir); d.EmitBlockInstructions(b.current_flow_block->As()); EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func -%2(u32) = bit_xor %1(u32), 4u +%2(u32) = xor %1(u32), 4u )"); } diff --git a/src/tint/ir/unary.cc b/src/tint/ir/unary.cc index f3c4f24752..86c06afe20 100644 --- a/src/tint/ir/unary.cc +++ b/src/tint/ir/unary.cc @@ -34,7 +34,7 @@ utils::StringStream& Unary::ToInstruction(utils::StringStream& out) const { out << "addr_of"; break; case Unary::Kind::kComplement: - out << "bit_complement"; + out << "complement"; break; case Unary::Kind::kIndirection: out << "indirection"; @@ -43,7 +43,7 @@ utils::StringStream& Unary::ToInstruction(utils::StringStream& out) const { out << "negation"; break; case Unary::Kind::kNot: - out << "log_not"; + out << "not"; break; } out << " "; diff --git a/src/tint/ir/unary_test.cc b/src/tint/ir/unary_test.cc index ff247a2fc4..c36e3ee2a6 100644 --- a/src/tint/ir/unary_test.cc +++ b/src/tint/ir/unary_test.cc @@ -63,7 +63,7 @@ TEST_F(IR_InstructionTest, CreateComplement) { utils::StringStream str; inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(i32) = bit_complement 4i"); + EXPECT_EQ(str.str(), "%1(i32) = complement 4i"); } TEST_F(IR_InstructionTest, CreateIndirection) { @@ -119,7 +119,7 @@ TEST_F(IR_InstructionTest, CreateNot) { utils::StringStream str; inst->ToInstruction(str); - EXPECT_EQ(str.str(), "%1(bool) = log_not true"); + EXPECT_EQ(str.str(), "%1(bool) = not true"); } TEST_F(IR_InstructionTest, Unary_Usage) {