@@ -1201,16 +1201,12 @@ simplify_exprt::simplify_bitnot(const bitnot_exprt &expr)
1201
1201
}
1202
1202
1203
1203
// / simplifies inequalities !=, <=, <, >=, >, and also ==
1204
- simplify_exprt::resultt<> simplify_exprt::simplify_inequality (const exprt &expr)
1204
+ simplify_exprt::resultt<>
1205
+ simplify_exprt::simplify_inequality (const binary_relation_exprt &expr)
1205
1206
{
1206
- const exprt::operandst &operands = expr.operands ();
1207
-
1208
1207
if (expr.type ().id ()!=ID_bool)
1209
1208
return unchanged (expr);
1210
1209
1211
- if (operands.size ()!=2 )
1212
- return unchanged (expr);
1213
-
1214
1210
exprt tmp0=expr.op0 ();
1215
1211
exprt tmp1=expr.op1 ();
1216
1212
@@ -1231,8 +1227,10 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality(const exprt &expr)
1231
1227
if (tmp0.id ()==ID_if && tmp0.operands ().size ()==3 )
1232
1228
{
1233
1229
if_exprt if_expr=lift_if (expr, 0 );
1234
- if_expr.true_case () = simplify_inequality (if_expr.true_case ());
1235
- if_expr.false_case () = simplify_inequality (if_expr.false_case ());
1230
+ if_expr.true_case () =
1231
+ simplify_inequality (to_binary_relation_expr (if_expr.true_case ()));
1232
+ if_expr.false_case () =
1233
+ simplify_inequality (to_binary_relation_expr (if_expr.false_case ()));
1236
1234
return changed (simplify_if (if_expr));
1237
1235
}
1238
1236
@@ -1271,7 +1269,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality(const exprt &expr)
1271
1269
{
1272
1270
// we want the constant on the RHS
1273
1271
1274
- exprt new_expr = expr;
1272
+ binary_relation_exprt new_expr = expr;
1275
1273
1276
1274
if (expr.id ()==ID_ge)
1277
1275
new_expr.id (ID_le);
@@ -1301,11 +1299,9 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality(const exprt &expr)
1301
1299
1302
1300
// / simplifies inequalities for the case in which both sides
1303
1301
// / of the inequality are constants
1304
- simplify_exprt::resultt<>
1305
- simplify_exprt::simplify_inequality_both_constant ( const exprt &expr)
1302
+ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_both_constant (
1303
+ const binary_relation_exprt &expr)
1306
1304
{
1307
- PRECONDITION (expr.operands ().size () == 2 );
1308
-
1309
1305
exprt tmp0 = expr.op0 ();
1310
1306
exprt tmp1 = expr.op1 ();
1311
1307
@@ -1466,8 +1462,8 @@ bool simplify_exprt::eliminate_common_addends(
1466
1462
return true ;
1467
1463
}
1468
1464
1469
- simplify_exprt::resultt<>
1470
- simplify_exprt::simplify_inequality_no_constant ( const exprt &expr)
1465
+ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_no_constant (
1466
+ const binary_relation_exprt &expr)
1471
1467
{
1472
1468
// pretty much all of the simplifications below are unsound
1473
1469
// for IEEE float because of NaN!
@@ -1478,35 +1474,34 @@ simplify_exprt::simplify_inequality_no_constant(const exprt &expr)
1478
1474
// eliminate strict inequalities
1479
1475
if (expr.id ()==ID_notequal)
1480
1476
{
1481
- auto new_expr = expr;
1482
- new_expr .id (ID_equal);
1483
- new_expr = simplify_inequality_no_constant (new_expr );
1477
+ auto new_rel_expr = expr;
1478
+ new_rel_expr .id (ID_equal);
1479
+ auto new_expr = simplify_inequality_no_constant (new_rel_expr );
1484
1480
return changed (simplify_not (not_exprt (new_expr)));
1485
1481
}
1486
1482
else if (expr.id ()==ID_gt)
1487
1483
{
1488
- auto new_expr = expr;
1489
- new_expr .id (ID_ge);
1484
+ auto new_rel_expr = expr;
1485
+ new_rel_expr .id (ID_ge);
1490
1486
// swap operands
1491
- new_expr. op0 ().swap (new_expr. op1 ());
1492
- new_expr = simplify_inequality_no_constant (new_expr );
1487
+ new_rel_expr. lhs ().swap (new_rel_expr. rhs ());
1488
+ auto new_expr = simplify_inequality_no_constant (new_rel_expr );
1493
1489
return changed (simplify_not (not_exprt (new_expr)));
1494
1490
}
1495
1491
else if (expr.id ()==ID_lt)
1496
1492
{
1497
- auto new_expr = expr;
1498
- new_expr .id (ID_ge);
1499
- new_expr = simplify_inequality_no_constant (new_expr );
1493
+ auto new_rel_expr = expr;
1494
+ new_rel_expr .id (ID_ge);
1495
+ auto new_expr = simplify_inequality_no_constant (new_rel_expr );
1500
1496
return changed (simplify_not (not_exprt (new_expr)));
1501
1497
}
1502
1498
else if (expr.id ()==ID_le)
1503
1499
{
1504
- auto new_expr = expr;
1505
- new_expr .id (ID_ge);
1500
+ auto new_rel_expr = expr;
1501
+ new_rel_expr .id (ID_ge);
1506
1502
// swap operands
1507
- new_expr.op0 ().swap (new_expr.op1 ());
1508
- new_expr = simplify_inequality_no_constant (new_expr);
1509
- return std::move (new_expr);
1503
+ new_rel_expr.lhs ().swap (new_rel_expr.rhs ());
1504
+ return changed (simplify_inequality_no_constant (new_rel_expr));
1510
1505
}
1511
1506
1512
1507
// now we only have >=, =
@@ -1574,12 +1569,12 @@ simplify_exprt::simplify_inequality_no_constant(const exprt &expr)
1574
1569
// On bit-vectors, this is only sound on '='.
1575
1570
if (expr.id ()==ID_equal)
1576
1571
{
1577
- auto new_expr = expr;
1578
- if (!eliminate_common_addends (new_expr.op0 (), new_expr.op1 ()))
1572
+ auto new_expr = to_equal_expr ( expr) ;
1573
+ if (!eliminate_common_addends (new_expr.lhs (), new_expr.rhs ()))
1579
1574
{
1580
1575
// remove zeros
1581
- new_expr.op0 () = simplify_node (new_expr.op0 ());
1582
- new_expr.op1 () = simplify_node (new_expr.op1 ());
1576
+ new_expr.lhs () = simplify_node (new_expr.lhs ());
1577
+ new_expr.rhs () = simplify_node (new_expr.rhs ());
1583
1578
return changed (simplify_inequality (new_expr)); // recursive call
1584
1579
}
1585
1580
}
@@ -1589,19 +1584,19 @@ simplify_exprt::simplify_inequality_no_constant(const exprt &expr)
1589
1584
1590
1585
// / \par expr: an inequality where the RHS is a constant
1591
1586
// / and the LHS is not
1592
- simplify_exprt::resultt<>
1593
- simplify_exprt::simplify_inequality_rhs_is_constant ( const exprt &expr)
1587
+ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant (
1588
+ const binary_relation_exprt &expr)
1594
1589
{
1595
1590
// the constant is always on the RHS
1596
1591
PRECONDITION (expr.op1 ().is_constant ());
1597
1592
1598
1593
if (expr.op0 ().id ()==ID_if && expr.op0 ().operands ().size ()==3 )
1599
1594
{
1600
1595
if_exprt if_expr=lift_if (expr, 0 );
1601
- if_expr.true_case () =
1602
- simplify_inequality_rhs_is_constant (if_expr.true_case ());
1603
- if_expr.false_case () =
1604
- simplify_inequality_rhs_is_constant (if_expr.false_case ());
1596
+ if_expr.true_case () = simplify_inequality_rhs_is_constant (
1597
+ to_binary_relation_expr (if_expr.true_case () ));
1598
+ if_expr.false_case () = simplify_inequality_rhs_is_constant (
1599
+ to_binary_relation_expr (if_expr.false_case () ));
1605
1600
return changed (simplify_if (if_expr));
1606
1601
}
1607
1602
@@ -1610,9 +1605,9 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1610
1605
{
1611
1606
if (expr.id ()==ID_notequal)
1612
1607
{
1613
- auto new_expr = expr;
1614
- new_expr .id (ID_equal);
1615
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1608
+ auto new_rel_expr = expr;
1609
+ new_rel_expr .id (ID_equal);
1610
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1616
1611
return changed (simplify_not (not_exprt (new_expr)));
1617
1612
}
1618
1613
@@ -1822,9 +1817,9 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1822
1817
1823
1818
if (expr.id ()==ID_notequal)
1824
1819
{
1825
- auto new_expr = expr;
1826
- new_expr .id (ID_equal);
1827
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1820
+ auto new_rel_expr = expr;
1821
+ new_rel_expr .id (ID_equal);
1822
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1828
1823
return changed (simplify_not (not_exprt (new_expr)));
1829
1824
}
1830
1825
else if (expr.id ()==ID_gt)
@@ -1844,9 +1839,9 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1844
1839
}
1845
1840
else if (expr.id ()==ID_lt)
1846
1841
{
1847
- auto new_expr = expr;
1848
- new_expr .id (ID_ge);
1849
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1842
+ auto new_rel_expr = expr;
1843
+ new_rel_expr .id (ID_ge);
1844
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1850
1845
return changed (simplify_not (not_exprt (new_expr)));
1851
1846
}
1852
1847
else if (expr.id ()==ID_le)
@@ -1858,11 +1853,11 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1858
1853
return true_exprt ();
1859
1854
}
1860
1855
1861
- auto new_expr = expr;
1862
- new_expr .id (ID_ge);
1856
+ auto new_rel_expr = expr;
1857
+ new_rel_expr .id (ID_ge);
1863
1858
++i;
1864
- new_expr .op1 () = from_integer (i, new_expr .op1 ().type ());
1865
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1859
+ new_rel_expr .op1 () = from_integer (i, new_rel_expr .op1 ().type ());
1860
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1866
1861
return changed (simplify_not (not_exprt (new_expr)));
1867
1862
}
1868
1863
}
0 commit comments