@@ -1753,6 +1753,40 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
1753
1753
return changed (simplify_byte_extract (be));
1754
1754
}
1755
1755
1756
+ // update bits in a constant
1757
+ const auto offset_int = numeric_cast<mp_integer>(offset);
1758
+ if (
1759
+ root_size.has_value () && *root_size >= 0 && val_size.has_value () &&
1760
+ *val_size >= 0 && offset_int.has_value () && *offset_int >= 0 &&
1761
+ *offset_int + *val_size <= *root_size)
1762
+ {
1763
+ auto root_bits =
1764
+ expr2bits (root, expr.id () == ID_byte_update_little_endian, ns);
1765
+
1766
+ if (root_bits.has_value ())
1767
+ {
1768
+ const auto val_bits =
1769
+ expr2bits (value, expr.id () == ID_byte_update_little_endian, ns);
1770
+
1771
+ if (val_bits.has_value ())
1772
+ {
1773
+ root_bits->replace (
1774
+ numeric_cast_v<std::size_t >(*offset_int * 8 ),
1775
+ numeric_cast_v<std::size_t >(*val_size),
1776
+ *val_bits);
1777
+
1778
+ auto tmp = bits2expr (
1779
+ *root_bits,
1780
+ expr.type (),
1781
+ expr.id () == ID_byte_update_little_endian,
1782
+ ns);
1783
+
1784
+ if (tmp.has_value ())
1785
+ return std::move (*tmp);
1786
+ }
1787
+ }
1788
+ }
1789
+
1756
1790
/*
1757
1791
* byte_update(root, offset,
1758
1792
* extract(root, offset) WITH component:=value)
@@ -1836,7 +1870,6 @@ simplify_exprt::simplify_byte_update(const byte_update_exprt &expr)
1836
1870
}
1837
1871
1838
1872
// the following require a constant offset
1839
- const auto offset_int = numeric_cast<mp_integer>(offset);
1840
1873
if (!offset_int.has_value () || *offset_int < 0 )
1841
1874
return unchanged (expr);
1842
1875
0 commit comments