Skip to content

Commit ddf6c92

Browse files
Simplify equalities of constants
Enables some pruning of virtual function dispatch in goto-symex
1 parent 0da026b commit ddf6c92

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,11 +1215,6 @@ bool simplify_exprt::simplify_inequality(exprt &expr)
12151215
(expr.id()==ID_equal || expr.id()==ID_notequal))
12161216
return simplify_inequality_pointer_object(expr);
12171217

1218-
// first see if we compare to a constant
1219-
1220-
bool op0_is_const=tmp0.is_constant();
1221-
bool op1_is_const=tmp1.is_constant();
1222-
12231218
ns.follow_symbol(tmp0.type());
12241219
ns.follow_symbol(tmp1.type());
12251220

@@ -1229,9 +1224,20 @@ bool simplify_exprt::simplify_inequality(exprt &expr)
12291224
if(tmp1.type().id()==ID_c_enum_tag)
12301225
tmp1.type()=ns.follow_tag(to_c_enum_tag_type(tmp1.type()));
12311226

1227+
const auto tmp0_const = expr_try_dynamic_cast<constant_exprt>(tmp0);
1228+
const auto tmp1_const = expr_try_dynamic_cast<constant_exprt>(tmp1);
1229+
12321230
// are _both_ constant?
1233-
if(op0_is_const && op1_is_const)
1231+
if(tmp0_const && tmp1_const)
12341232
{
1233+
if(expr.id() == ID_equal || expr.id() == ID_notequal)
1234+
{
1235+
1236+
bool equal = (tmp0_const->get_value() == tmp1_const->get_value());
1237+
expr.make_bool(expr.id() == ID_equal ? equal : !equal);
1238+
return false;
1239+
}
1240+
12351241
if(tmp0.type().id()==ID_bool)
12361242
{
12371243
bool v0=tmp0.is_true();
@@ -1347,7 +1353,7 @@ bool simplify_exprt::simplify_inequality(exprt &expr)
13471353
return false;
13481354
}
13491355
}
1350-
else if(op0_is_const)
1356+
else if(tmp0_const)
13511357
{
13521358
// we want the constant on the RHS
13531359

@@ -1366,7 +1372,7 @@ bool simplify_exprt::simplify_inequality(exprt &expr)
13661372
simplify_inequality_constant(expr);
13671373
return false;
13681374
}
1369-
else if(op1_is_const)
1375+
else if(tmp1_const)
13701376
{
13711377
// one is constant
13721378
return simplify_inequality_constant(expr);

0 commit comments

Comments
 (0)