@@ -1562,29 +1562,35 @@ bool simplify_exprt::simplify_floatbv_typecast(exprt &expr)
1562
1562
exprt op0=expr.op0 ();
1563
1563
exprt op1=expr.op1 (); // rounding mode
1564
1564
1565
- // We can soundly re-write (float)(x op y)
1566
- // to (float)x op (float)y. True for any rounding mode!
1567
-
1565
+ // We can soundly re-write (float)((double)x op (double)y)
1566
+ // to x op y. True for any rounding mode!
1567
+
1568
+ #if 0
1568
1569
if(op0.id()==ID_floatbv_div ||
1569
1570
op0.id()==ID_floatbv_mult ||
1570
1571
op0.id()==ID_floatbv_plus ||
1571
1572
op0.id()==ID_floatbv_minus)
1572
1573
{
1573
- if (op0.operands ().size ()==3 )
1574
+ if(op0.operands().size()==3 &&
1575
+ op0.op0().id()==ID_typecast &&
1576
+ op0.op1().id()==ID_typecast &&
1577
+ op0.op0().operands().size()==1 &&
1578
+ op0.op1().operands().size()==1 &&
1579
+ ns.follow(op0.op0().type())==dest_type &&
1580
+ ns.follow(op0.op1().type())==dest_type)
1574
1581
{
1575
1582
exprt result(op0.id(), expr.type());
1576
1583
result.operands().resize(3);
1577
- result.op0 ()=binary_exprt ( op0.op0 (), ID_floatbv_typecast, op1, expr. type () );
1578
- result.op1 ()=binary_exprt ( op0.op1 (), ID_floatbv_typecast, op1, expr. type () );
1579
- result.op2 ()=op1; // ?
1584
+ result.op0()=op0.op0().op0( );
1585
+ result.op1()=op0.op1().op0( );
1586
+ result.op2()=op1;
1580
1587
1581
- simplify_node (result.op0 ());
1582
- simplify_node (result.op1 ());
1583
1588
simplify_node(result);
1584
1589
expr.swap(result);
1585
1590
return false;
1586
1591
}
1587
1592
}
1593
+ #endif
1588
1594
1589
1595
// constant folding
1590
1596
if (op0.is_constant () && op1.is_constant ())
@@ -1619,7 +1625,8 @@ bool simplify_exprt::simplify_floatbv_typecast(exprt &expr)
1619
1625
1620
1626
#if 0
1621
1627
// (T)(a?b:c) --> a?(T)b:(T)c
1622
- if(expr.op0().id()==ID_if && expr.op0().operands().size()==3)
1628
+ if(expr.op0().id()==ID_if &&
1629
+ expr.op0().operands().size()==3)
1623
1630
{
1624
1631
exprt tmp_op1=binary_exprt(expr.op0().op1(), ID_floatbv_typecast, expr.op1(), dest_type);
1625
1632
exprt tmp_op2=binary_exprt(expr.op0().op2(), ID_floatbv_typecast, expr.op1(), dest_type);
@@ -2554,7 +2561,7 @@ bool simplify_exprt::simplify_if(exprt &expr)
2554
2561
}
2555
2562
}
2556
2563
2557
- #if 0
2564
+ #if 1
2558
2565
// a ? b : c --> a ? b[a/true] : c
2559
2566
exprt tmp_true=truevalue;
2560
2567
replace_expr (cond, true_exprt (), tmp_true);
@@ -3444,6 +3451,31 @@ bool simplify_exprt::simplify_inequality_constant(exprt &expr)
3444
3451
}
3445
3452
}
3446
3453
}
3454
+
3455
+ #if 1
3456
+ // (double)value REL const ---> value rel const
3457
+ // if 'const' can be represented exactly.
3458
+
3459
+ if (expr.op0 ().id ()==ID_typecast &&
3460
+ expr.op0 ().operands ().size ()==1 &&
3461
+ ns.follow (expr.op0 ().type ()).id ()==ID_floatbv &&
3462
+ ns.follow (expr.op0 ().op0 ().type ()).id ()==ID_floatbv)
3463
+ {
3464
+ ieee_floatt const_val (to_constant_expr (expr.op1 ()));
3465
+ ieee_floatt const_val_converted=const_val;
3466
+ const_val_converted.change_spec (to_floatbv_type (ns.follow (expr.op0 ().op0 ().type ())));
3467
+ ieee_floatt const_val_converted_back=const_val_converted;
3468
+ const_val_converted_back.change_spec (to_floatbv_type (ns.follow (expr.op0 ().type ())));
3469
+ if (const_val_converted_back==const_val)
3470
+ {
3471
+ exprt result=expr;
3472
+ result.op0 ()=expr.op0 ().op0 ();
3473
+ result.op1 ()=const_val_converted.to_expr ();
3474
+ expr.swap (result);
3475
+ return false ;
3476
+ }
3477
+ }
3478
+ #endif
3447
3479
3448
3480
// is the constant zero?
3449
3481
0 commit comments