Skip to content

Commit bf4abab

Browse files
committed
simplify_concatenation is now independent of bitvector representation
This includes a fix to a bug where changes to the expression were not signalled by returning 'false'.
1 parent 57582b3 commit bf4abab

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,9 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
887887
exprt &op=*it;
888888
if(op.is_true() || op.is_false())
889889
{
890-
bool value=op.is_true();
891-
op=constant_exprt(value?ID_1:ID_0, unsignedbv_typet(1));
890+
const bool value = op.is_true();
891+
op = from_integer(value, unsignedbv_typet(1));
892+
result = false;
892893
}
893894
}
894895

@@ -906,13 +907,24 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
906907
is_bitvector_type(opn.type()))
907908
{
908909
// merge!
909-
const std::string new_value=
910-
opi.get_string(ID_value)+opn.get_string(ID_value);
911-
opi.set(ID_value, new_value);
912-
opi.type().set(ID_width, new_value.size());
910+
const auto &value_i = to_constant_expr(opi).get_value();
911+
const auto &value_n = to_constant_expr(opn).get_value();
912+
const auto width_i = to_bitvector_type(opi.type()).get_width();
913+
const auto width_n = to_bitvector_type(opn.type()).get_width();
914+
const auto new_width = width_i + width_n;
915+
916+
const auto new_value = make_bvrep(
917+
new_width, [&value_i, &value_n, width_i, width_n](std::size_t x) {
918+
return x < width_n
919+
? get_bitvector_bit(value_n, width_n, x)
920+
: get_bitvector_bit(value_i, width_i, x - width_n);
921+
});
922+
923+
to_constant_expr(opi).set_value(new_value);
924+
opi.type().set(ID_width, new_width);
913925
// erase opn
914926
expr.operands().erase(expr.operands().begin()+i+1);
915-
result=true;
927+
result = false;
916928
}
917929
else
918930
i++;
@@ -943,7 +955,7 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
943955
opi.type().id(ID_verilog_unsignedbv);
944956
// erase opn
945957
expr.operands().erase(expr.operands().begin()+i+1);
946-
result=true;
958+
result = false;
947959
}
948960
else
949961
i++;

0 commit comments

Comments
 (0)