Skip to content

Commit e0a6bbd

Browse files
authored
Merge pull request #1226 from diffblue/simplify_bitand_all_ones
simplifier: erase 'all ones' out of bitand
2 parents 51cc77b + 60906b1 commit e0a6bbd

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
664664
result=false;
665665
}
666666

667-
// now erase zeros out of bitor, bitxor
667+
// now erase 'all zeros' out of bitor, bitxor
668668

669669
if(expr.id()==ID_bitor || expr.id()==ID_bitxor)
670670
{
@@ -683,6 +683,28 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
683683
}
684684
}
685685

686+
// now erase 'all ones' out of bitand
687+
688+
if(expr.id()==ID_bitand)
689+
{
690+
for(exprt::operandst::iterator
691+
it=expr.operands().begin();
692+
it!=expr.operands().end();
693+
) // no it++
694+
{
695+
if(it->is_constant() &&
696+
id2string(to_constant_expr(*it).get_value()).find('0')==
697+
std::string::npos &&
698+
expr.operands().size()>1)
699+
{
700+
it=expr.operands().erase(it);
701+
result=false;
702+
}
703+
else
704+
it++;
705+
}
706+
}
707+
686708
// two operands that are syntactically the same
687709

688710
if(expr.operands().size()==2 &&

0 commit comments

Comments
 (0)