Skip to content

Commit 7c2fa6f

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 7c2fa6f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
3-
--show-vcc
4-
main::1::m!0@1#2 = .*byte_extract_(big|little)_endian\(cast\(44, signedbv\[\d+\]\*\), 0, signedbv\[\d+\]\).*
3+
4+
^Generated 1\d* VCC\(s\), 0 remaining after simplification$
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)