File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1683,6 +1683,40 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
16831683 if (!offset.has_value () || *offset < 0 )
16841684 return unchanged (expr);
16851685
1686+ // byte_extract(byte_update(root, offset_u, value), offset_e) so that the
1687+ // update does not affect what is being extracted simplifies to
1688+ // byte_extract(root, offset_e)
1689+ if (
1690+ expr.op ().id () == ID_byte_update_big_endian ||
1691+ expr.op ().id () == ID_byte_update_little_endian)
1692+ {
1693+ const byte_update_exprt &bu = to_byte_update_expr (expr.op ());
1694+ const auto update_offset = numeric_cast<mp_integer>(bu.offset ());
1695+ if (update_offset.has_value ())
1696+ {
1697+ if (
1698+ *offset * expr.get_bits_per_byte () + *el_size <=
1699+ *update_offset * bu.get_bits_per_byte ())
1700+ {
1701+ auto tmp = expr;
1702+ tmp.op () = bu.op ();
1703+ return changed (simplify_byte_extract (tmp)); // recursive call
1704+ }
1705+ else
1706+ {
1707+ const auto update_size = pointer_offset_bits (bu.value ().type (), ns);
1708+ if (
1709+ update_size.has_value () &&
1710+ *offset >= *update_offset * bu.get_bits_per_byte () + *update_size)
1711+ {
1712+ auto tmp = expr;
1713+ tmp.op () = bu.op ();
1714+ return changed (simplify_byte_extract (tmp)); // recursive call
1715+ }
1716+ }
1717+ }
1718+ }
1719+
16861720 // don't do any of the following if endianness doesn't match, as
16871721 // bytes need to be swapped
16881722 if (
You can’t perform that action at this time.
0 commit comments