@@ -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,38 +1474,37 @@ 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
new_expr = boolean_negate (new_expr);
1485
1481
return changed (simplify_node (new_expr));
1486
1482
}
1487
1483
else if (expr.id ()==ID_gt)
1488
1484
{
1489
- auto new_expr = expr;
1490
- new_expr .id (ID_ge);
1485
+ auto new_rel_expr = expr;
1486
+ new_rel_expr .id (ID_ge);
1491
1487
// swap operands
1492
- new_expr. op0 ().swap (new_expr. op1 ());
1493
- new_expr = simplify_inequality_no_constant (new_expr );
1488
+ new_rel_expr. lhs ().swap (new_rel_expr. rhs ());
1489
+ auto new_expr = simplify_inequality_no_constant (new_rel_expr );
1494
1490
new_expr = boolean_negate (new_expr);
1495
1491
return changed (simplify_node (new_expr));
1496
1492
}
1497
1493
else if (expr.id ()==ID_lt)
1498
1494
{
1499
- auto new_expr = expr;
1500
- new_expr .id (ID_ge);
1501
- new_expr = simplify_inequality_no_constant (new_expr );
1495
+ auto new_rel_expr = expr;
1496
+ new_rel_expr .id (ID_ge);
1497
+ auto new_expr = simplify_inequality_no_constant (new_rel_expr );
1502
1498
new_expr = boolean_negate (new_expr);
1503
1499
return changed (simplify_node (new_expr));
1504
1500
}
1505
1501
else if (expr.id ()==ID_le)
1506
1502
{
1507
- auto new_expr = expr;
1508
- new_expr .id (ID_ge);
1503
+ auto new_rel_expr = expr;
1504
+ new_rel_expr .id (ID_ge);
1509
1505
// swap operands
1510
- new_expr.op0 ().swap (new_expr.op1 ());
1511
- new_expr = simplify_inequality_no_constant (new_expr);
1512
- return std::move (new_expr);
1506
+ new_rel_expr.lhs ().swap (new_rel_expr.rhs ());
1507
+ return changed (simplify_inequality_no_constant (new_rel_expr));
1513
1508
}
1514
1509
1515
1510
// now we only have >=, =
@@ -1577,12 +1572,12 @@ simplify_exprt::simplify_inequality_no_constant(const exprt &expr)
1577
1572
// On bit-vectors, this is only sound on '='.
1578
1573
if (expr.id ()==ID_equal)
1579
1574
{
1580
- auto new_expr = expr;
1581
- if (!eliminate_common_addends (new_expr.op0 (), new_expr.op1 ()))
1575
+ auto new_expr = to_equal_expr ( expr) ;
1576
+ if (!eliminate_common_addends (new_expr.lhs (), new_expr.rhs ()))
1582
1577
{
1583
1578
// remove zeros
1584
- new_expr.op0 () = simplify_node (new_expr.op0 ());
1585
- new_expr.op1 () = simplify_node (new_expr.op1 ());
1579
+ new_expr.lhs () = simplify_node (new_expr.lhs ());
1580
+ new_expr.rhs () = simplify_node (new_expr.rhs ());
1586
1581
return changed (simplify_inequality (new_expr)); // recursive call
1587
1582
}
1588
1583
}
@@ -1592,19 +1587,19 @@ simplify_exprt::simplify_inequality_no_constant(const exprt &expr)
1592
1587
1593
1588
// / \par expr: an inequality where the RHS is a constant
1594
1589
// / and the LHS is not
1595
- simplify_exprt::resultt<>
1596
- simplify_exprt::simplify_inequality_rhs_is_constant ( const exprt &expr)
1590
+ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant (
1591
+ const binary_relation_exprt &expr)
1597
1592
{
1598
1593
// the constant is always on the RHS
1599
1594
PRECONDITION (expr.op1 ().is_constant ());
1600
1595
1601
1596
if (expr.op0 ().id ()==ID_if && expr.op0 ().operands ().size ()==3 )
1602
1597
{
1603
1598
if_exprt if_expr=lift_if (expr, 0 );
1604
- if_expr.true_case () =
1605
- simplify_inequality_rhs_is_constant (if_expr.true_case ());
1606
- if_expr.false_case () =
1607
- simplify_inequality_rhs_is_constant (if_expr.false_case ());
1599
+ if_expr.true_case () = simplify_inequality_rhs_is_constant (
1600
+ to_binary_relation_expr (if_expr.true_case () ));
1601
+ if_expr.false_case () = simplify_inequality_rhs_is_constant (
1602
+ to_binary_relation_expr (if_expr.false_case () ));
1608
1603
return changed (simplify_if (if_expr));
1609
1604
}
1610
1605
@@ -1613,9 +1608,9 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1613
1608
{
1614
1609
if (expr.id ()==ID_notequal)
1615
1610
{
1616
- auto new_expr = expr;
1617
- new_expr .id (ID_equal);
1618
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1611
+ auto new_rel_expr = expr;
1612
+ new_rel_expr .id (ID_equal);
1613
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1619
1614
new_expr = boolean_negate (new_expr);
1620
1615
return changed (simplify_node (new_expr));
1621
1616
}
@@ -1826,9 +1821,9 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1826
1821
1827
1822
if (expr.id ()==ID_notequal)
1828
1823
{
1829
- auto new_expr = expr;
1830
- new_expr .id (ID_equal);
1831
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1824
+ auto new_rel_expr = expr;
1825
+ new_rel_expr .id (ID_equal);
1826
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1832
1827
new_expr = boolean_negate (new_expr);
1833
1828
return changed (simplify_node (new_expr));
1834
1829
}
@@ -1849,9 +1844,9 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1849
1844
}
1850
1845
else if (expr.id ()==ID_lt)
1851
1846
{
1852
- auto new_expr = expr;
1853
- new_expr .id (ID_ge);
1854
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1847
+ auto new_rel_expr = expr;
1848
+ new_rel_expr .id (ID_ge);
1849
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1855
1850
new_expr = boolean_negate (new_expr);
1856
1851
return changed (simplify_node (new_expr));
1857
1852
}
@@ -1864,11 +1859,11 @@ simplify_exprt::simplify_inequality_rhs_is_constant(const exprt &expr)
1864
1859
return true_exprt ();
1865
1860
}
1866
1861
1867
- auto new_expr = expr;
1868
- new_expr .id (ID_ge);
1862
+ auto new_rel_expr = expr;
1863
+ new_rel_expr .id (ID_ge);
1869
1864
++i;
1870
- new_expr. op1 () = from_integer (i, new_expr. op1 ().type ());
1871
- new_expr = simplify_inequality_rhs_is_constant (new_expr );
1865
+ new_rel_expr. rhs () = from_integer (i, new_rel_expr. rhs ().type ());
1866
+ auto new_expr = simplify_inequality_rhs_is_constant (new_rel_expr );
1872
1867
new_expr = boolean_negate (new_expr);
1873
1868
return changed (simplify_node (new_expr));
1874
1869
}
0 commit comments