Skip to content

Commit f91f60a

Browse files
committed
Simplify byte extract: use lowering when expression is a constant
When none of the earlier simplification rules apply, rewrite the expression to to apply simplification rules for arithmetic and logic expressions.
1 parent b5a0aec commit f91f60a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

regression/cbmc-library/memcpy-01/constant-propagation.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--show-vcc
4-
main::1::m!0@1#2 = .*byte_extract_(big|little)_endian\(cast\(44, signedbv\[\d+\]\*\), 0, signedbv\[\d+\]\).*
4+
main::1::m!0@1#2 = byte_extract_(big|little)_endian\(\{ .*cast\(44, signedbv\[\d+\]\*\).*\}, 0, struct tag-with_int_ptr\)$
55
^EXIT=0$
66
^SIGNAL=0$
77
--

src/util/simplify_expr.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,10 +1976,13 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
19761976
// try to refine it down to extracting from a member or an index in an array
19771977
auto subexpr =
19781978
get_subexpression_at_offset(expr.op(), *offset, expr.type(), ns);
1979-
if(!subexpr.has_value() || subexpr.value() == expr)
1980-
return unchanged(expr);
1979+
if(subexpr.has_value() && subexpr.value() != expr)
1980+
return changed(simplify_rec(subexpr.value())); // recursive call
1981+
1982+
if(is_constantt(ns)(expr))
1983+
return changed(simplify_rec(lower_byte_extract(expr, ns)));
19811984

1982-
return changed(simplify_rec(subexpr.value())); // recursive call
1985+
return unchanged(expr);
19831986
}
19841987

19851988
simplify_exprt::resultt<>

0 commit comments

Comments
 (0)