@@ -1545,13 +1545,68 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
1545
1545
if (!operands_are_constant)
1546
1546
return expr; // give up
1547
1547
1548
+ auto make_all_ones = [](const typet &type) -> exprt
1549
+ {
1550
+ if (type.id () == ID_unsignedbv)
1551
+ {
1552
+ return from_integer (
1553
+ power (2 , to_unsignedbv_type (type).get_width ()) - 1 , type);
1554
+ }
1555
+ else if (type.id () == ID_signedbv)
1556
+ {
1557
+ return from_integer (-1 , type);
1558
+ }
1559
+ else if (type.id () == ID_bool)
1560
+ return true_exprt{};
1561
+ else
1562
+ PRECONDITION (false );
1563
+ };
1564
+
1548
1565
if (expr.id () == ID_reduction_or)
1549
1566
{
1550
1567
// The simplifier doesn't know how to simplify reduction_or
1551
1568
auto &reduction_or = to_unary_expr (expr);
1552
1569
expr = notequal_exprt (
1553
1570
reduction_or.op (), from_integer (0 , reduction_or.op ().type ()));
1554
1571
}
1572
+ else if (expr.id () == ID_reduction_nor)
1573
+ {
1574
+ // The simplifier doesn't know how to simplify reduction_nor
1575
+ auto &reduction_nor = to_unary_expr (expr);
1576
+ expr = equal_exprt (
1577
+ reduction_nor.op (), from_integer (0 , reduction_nor.op ().type ()));
1578
+ }
1579
+ else if (expr.id () == ID_reduction_and)
1580
+ {
1581
+ // The simplifier doesn't know how to simplify reduction_and
1582
+ auto &reduction_and = to_unary_expr (expr);
1583
+ expr = equal_exprt{
1584
+ reduction_and.op (), make_all_ones (reduction_and.op ().type ())};
1585
+ }
1586
+ else if (expr.id () == ID_reduction_nand)
1587
+ {
1588
+ // The simplifier doesn't know how to simplify reduction_nand
1589
+ auto &reduction_nand = to_unary_expr (expr);
1590
+ expr = notequal_exprt{
1591
+ reduction_nand.op (), make_all_ones (reduction_nand.op ().type ())};
1592
+ }
1593
+ else if (expr.id () == ID_reduction_xor)
1594
+ {
1595
+ // The simplifier doesn't know how to simplify reduction_xor
1596
+ // Lower to countones.
1597
+ auto &reduction_xor = to_unary_expr (expr);
1598
+ auto ones = countones (to_constant_expr (reduction_xor.op ()));
1599
+ expr = extractbit_exprt{ones, from_integer (0 , natural_typet{})};
1600
+ }
1601
+ else if (expr.id () == ID_reduction_xnor)
1602
+ {
1603
+ // The simplifier doesn't know how to simplify reduction_xnor
1604
+ // Lower to countones.
1605
+ auto &reduction_xnor = to_unary_expr (expr);
1606
+ auto ones = countones (to_constant_expr (reduction_xnor.op ()));
1607
+ expr =
1608
+ not_exprt{extractbit_exprt{ones, from_integer (0 , natural_typet{})}};
1609
+ }
1555
1610
else if (expr.id () == ID_replication)
1556
1611
{
1557
1612
auto &replication = to_replication_expr (expr);
0 commit comments