Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifier: c_bool (and others) are also bitvector types #8247

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/util/simplify_expr_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ class simplify_exprt

virtual bool simplify(exprt &expr);

static bool is_bitvector_type(const typet &type)
{
return type.id()==ID_unsignedbv ||
type.id()==ID_signedbv ||
type.id()==ID_bv;
}

protected:
const namespacet &ns;
#ifdef DEBUG_ON_DEMAND
Expand Down
31 changes: 15 additions & 16 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@
simplify_exprt::resultt<>
simplify_exprt::simplify_bitwise(const multi_ary_exprt &expr)
{
if(!is_bitvector_type(expr.type()))
if(!can_cast_type<bitvector_typet>(expr.type()))
return unchanged(expr);

// check if these are really boolean
Expand Down Expand Up @@ -838,7 +838,7 @@
{
const typet &src_type = expr.src().type();

if(!is_bitvector_type(src_type))
if(!can_cast_type<bitvector_typet>(src_type))
return unchanged(expr);

const std::size_t src_bit_width = to_bitvector_type(src_type).get_width();
Expand Down Expand Up @@ -869,7 +869,7 @@

concatenation_exprt new_expr = expr;

if(is_bitvector_type(new_expr.type()))
if(can_cast_type<bitvector_typet>(new_expr.type()))
{
// first, turn bool into bvec[1]
Forall_operands(it, new_expr)
Expand All @@ -891,10 +891,10 @@
exprt &opi = new_expr.operands()[i];
exprt &opn = new_expr.operands()[i + 1];

if(opi.is_constant() &&
opn.is_constant() &&
is_bitvector_type(opi.type()) &&
is_bitvector_type(opn.type()))
if(
opi.is_constant() && opn.is_constant() &&
can_cast_type<bitvector_typet>(opi.type()) &&
can_cast_type<bitvector_typet>(opn.type()))
{
// merge!
const auto &value_i = to_constant_expr(opi).get_value();
Expand Down Expand Up @@ -963,12 +963,10 @@
exprt &opi = new_expr.operands()[i];
exprt &opn = new_expr.operands()[i + 1];

if(opi.is_constant() &&
opn.is_constant() &&
(opi.type().id()==ID_verilog_unsignedbv ||
is_bitvector_type(opi.type())) &&
(opn.type().id()==ID_verilog_unsignedbv ||
is_bitvector_type(opn.type())))
if(
opi.is_constant() && opn.is_constant() &&
can_cast_type<bitvector_typet>(opi.type()) &&
can_cast_type<bitvector_typet>(opn.type()))

Check warning on line 969 in src/util/simplify_expr_int.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/simplify_expr_int.cpp#L967-L969

Added lines #L967 - L969 were not covered by tests
{
// merge!
const std::string new_value=
Expand Down Expand Up @@ -1001,7 +999,7 @@
simplify_exprt::resultt<>
simplify_exprt::simplify_shifts(const shift_exprt &expr)
{
if(!is_bitvector_type(expr.type()))
if(!can_cast_type<bitvector_typet>(expr.type()))
return unchanged(expr);

const auto distance = numeric_cast<mp_integer>(expr.distance());
Expand Down Expand Up @@ -1132,8 +1130,9 @@
{
const typet &op0_type = expr.src().type();

if(!is_bitvector_type(op0_type) &&
!is_bitvector_type(expr.type()))
if(
!can_cast_type<bitvector_typet>(op0_type) &&
!can_cast_type<bitvector_typet>(expr.type()))

Check warning on line 1135 in src/util/simplify_expr_int.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/simplify_expr_int.cpp#L1135

Added line #L1135 was not covered by tests
{
return unchanged(expr);
}
Expand Down
17 changes: 17 additions & 0 deletions unit/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,20 @@
REQUIRE(simp == true_exprt{});
}
}

TEST_CASE("Simplify bitxor", "[core][util]")
{
config.set_arch("none");

const symbol_tablet symbol_table;
const namespacet ns(symbol_table);

SECTION("Simplification for c_bool")
{
constant_exprt false_c_bool = from_integer(0, c_bool_type());

REQUIRE(
simplify_expr(bitxor_exprt{false_c_bool, false_c_bool}, ns) ==

Check warning on line 570 in unit/util/simplify_expr.cpp

View check run for this annotation

Codecov / codecov/patch

unit/util/simplify_expr.cpp#L570

Added line #L570 was not covered by tests
false_c_bool);
}
}
Loading