@@ -787,10 +787,12 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
787787 it!=expr.operands ().end ();
788788 ) // no it++
789789 {
790- if (it->is_constant () &&
791- id2string (to_constant_expr (*it).get_value ()).find (' 0' )==
792- std::string::npos &&
793- expr.operands ().size ()>1 )
790+ if (
791+ it->is_constant () &&
792+ bv2integer (
793+ id2string (to_constant_expr (*it).get_value ()), width, false ) ==
794+ power (2 , width) - 1 &&
795+ expr.operands ().size () > 1 )
794796 {
795797 it=expr.operands ().erase (it);
796798 result=false ;
@@ -885,8 +887,9 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
885887 exprt &op=*it;
886888 if (op.is_true () || op.is_false ())
887889 {
888- bool value=op.is_true ();
889- 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 ;
890893 }
891894 }
892895
@@ -904,13 +907,24 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
904907 is_bitvector_type (opn.type ()))
905908 {
906909 // merge!
907- const std::string new_value=
908- opi.get_string (ID_value)+opn.get_string (ID_value);
909- opi.set (ID_value, new_value);
910- 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);
911925 // erase opn
912926 expr.operands ().erase (expr.operands ().begin ()+i+1 );
913- result= true ;
927+ result = false ;
914928 }
915929 else
916930 i++;
@@ -941,7 +955,7 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
941955 opi.type ().id (ID_verilog_unsignedbv);
942956 // erase opn
943957 expr.operands ().erase (expr.operands ().begin ()+i+1 );
944- result= true ;
958+ result = false ;
945959 }
946960 else
947961 i++;
@@ -1269,13 +1283,15 @@ bool simplify_exprt::simplify_bitnot(exprt &expr)
12691283
12701284 exprt &op=operands.front ();
12711285
1272- if (expr.type ().id ()==ID_bv ||
1273- expr.type ().id ()==ID_unsignedbv ||
1274- expr.type ().id ()==ID_signedbv)
1286+ const auto &type = expr.type ();
1287+
1288+ if (
1289+ type.id () == ID_bv || type.id () == ID_unsignedbv ||
1290+ type.id () == ID_signedbv)
12751291 {
1276- const auto width = to_bitvector_type (expr. type () ).get_width ();
1292+ const auto width = to_bitvector_type (type).get_width ();
12771293
1278- if (op.type ()==expr. type () )
1294+ if (op.type () == type)
12791295 {
12801296 if (op.id ()==ID_constant)
12811297 {
0 commit comments