Skip to content

Commit e116df1

Browse files
authored
Merge pull request #5890 from tautschnig/fix-simplify-inequality
Fully simplify (in)equalities over constants+if
2 parents 94c64da + c20f371 commit e116df1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,10 +1550,10 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
15501550
if(expr.op0().id()==ID_if && expr.op0().operands().size()==3)
15511551
{
15521552
if_exprt if_expr=lift_if(expr, 0);
1553-
if_expr.true_case() = simplify_inequality_rhs_is_constant(
1554-
to_binary_relation_expr(if_expr.true_case()));
1555-
if_expr.false_case() = simplify_inequality_rhs_is_constant(
1556-
to_binary_relation_expr(if_expr.false_case()));
1553+
if_expr.true_case() =
1554+
simplify_inequality(to_binary_relation_expr(if_expr.true_case()));
1555+
if_expr.false_case() =
1556+
simplify_inequality(to_binary_relation_expr(if_expr.false_case()));
15571557
return changed(simplify_if(if_expr));
15581558
}
15591559

unit/util/simplify_expr.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,27 @@ TEST_CASE("Simplify bitor", "[core][util]")
516516
REQUIRE(simplify_expr(bitor_exprt{b, zero}, ns) == b);
517517
}
518518
}
519+
520+
TEST_CASE("Simplify inequality", "[core][util]")
521+
{
522+
symbol_tablet symbol_table;
523+
namespacet ns(symbol_table);
524+
525+
{
526+
// This checks that 3 < (B ? 4 : 5) simplifies to true, just like (B ? 4 :
527+
// 5) > 3 simplifies to true.
528+
signedbv_typet sbv{4};
529+
symbol_exprt b{"B", bool_typet{}};
530+
if_exprt if_b{b, from_integer(4, sbv), from_integer(5, sbv)};
531+
532+
binary_relation_exprt comparison_gt{if_b, ID_gt, from_integer(3, sbv)};
533+
exprt simp = simplify_expr(comparison_gt, ns);
534+
535+
REQUIRE(simp == true_exprt{});
536+
537+
binary_relation_exprt comparison_lt{from_integer(3, sbv), ID_lt, if_b};
538+
simp = simplify_expr(comparison_lt, ns);
539+
540+
REQUIRE(simp == true_exprt{});
541+
}
542+
}

0 commit comments

Comments
 (0)