@@ -717,9 +717,6 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
717
717
718
718
while (expr.operands ().size ()>=2 )
719
719
{
720
- const irep_idt &a_str=expr.op0 ().get (ID_value);
721
- const irep_idt &b_str=expr.op1 ().get (ID_value);
722
-
723
720
if (!expr.op0 ().is_constant ())
724
721
break ;
725
722
@@ -732,32 +729,19 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
732
729
if (expr.op1 ().type ()!=expr.type ())
733
730
break ;
734
731
735
- INVARIANT (
736
- a_str.size () == b_str.size (),
737
- " bitvectors of the same type have the same size" );
732
+ const auto a_val=bv2integer (id2string (to_constant_expr (expr.op0 ()).get_value ()), false );
733
+ const auto b_val=bv2integer (id2string (to_constant_expr (expr.op1 ()).get_value ()), false );
738
734
739
- std::string new_value;
740
- new_value.resize (width);
735
+ mp_integer new_value;
741
736
742
737
if (expr.id ()==ID_bitand)
743
- {
744
- for (std::size_t i=0 ; i<width; i++)
745
- new_value[i]=(a_str[i]==' 1' && b_str[i]==' 1' )?' 1' :' 0' ;
746
- }
738
+ new_value=bitwise_and (a_val, b_val);
747
739
else if (expr.id ()==ID_bitor)
748
- {
749
- for (std::size_t i=0 ; i<width; i++)
750
- new_value[i]=(a_str[i]==' 1' || b_str[i]==' 1' )?' 1' :' 0' ;
751
- }
740
+ new_value=bitwise_or (a_val, b_val);
752
741
else if (expr.id ()==ID_bitxor)
753
- {
754
- for (std::size_t i=0 ; i<width; i++)
755
- new_value[i]=((a_str[i]==' 1' )!=(b_str[i]==' 1' ))?' 1' :' 0' ;
756
- }
757
- else
758
- break ;
742
+ new_value=bitwise_xor (a_val, b_val);
759
743
760
- constant_exprt new_op (new_value, expr.type ());
744
+ constant_exprt new_op (integer2bv ( new_value, width) , expr.type ());
761
745
762
746
// erase first operand
763
747
expr.operands ().erase (expr.operands ().begin ());
0 commit comments