Skip to content

Commit 26c1817

Browse files
author
Daniel Kroening
committed
simplifier: eliminate casts from bool to number
This usually enables subsequent simplification, e.g., ((int)B) != 0 turns into (B?1:0) != 0 and then into B?1!=0:0!=0 and then into B?true:false which then turns into B
1 parent 250b140 commit 26c1817

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/util/simplify_expr.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,17 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
552552
return std::move(inequality);
553553
}
554554

555+
// eliminate casts from proper bool
556+
if(op_type.id() == ID_bool)
557+
{
558+
// rewrite (T)(bool) to bool?1:0
559+
auto one = from_integer(1, expr_type);
560+
auto zero = from_integer(0, expr_type);
561+
exprt new_expr = if_exprt(expr.op(), std::move(one), std::move(zero));
562+
simplify_node(new_expr);
563+
return std::move(new_expr);
564+
}
565+
555566
// circular casts through types shorter than `int`
556567
if(op_type == signedbv_typet(32) && expr.op().id() == ID_typecast)
557568
{

0 commit comments

Comments
 (0)