Skip to content

Commit 8579a00

Browse files
distribute concat over bvxor and bvor, #2470
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent e950453 commit 8579a00

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

src/ast/rewriter/bv_rewriter.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,9 @@ br_status bv_rewriter::mk_bv_or(unsigned num, expr * const * args, expr_ref & re
17371737
default:
17381738
if (m_bv_sort_ac)
17391739
std::sort(new_args.begin(), new_args.end(), ast_to_lt());
1740+
if (distribute_concat(OP_BOR, new_args.size(), new_args.c_ptr(), result)) {
1741+
return BR_REWRITE3;
1742+
}
17401743
result = m_util.mk_bv_or(new_args.size(), new_args.c_ptr());
17411744
return BR_DONE;
17421745
}
@@ -1863,8 +1866,12 @@ br_status bv_rewriter::mk_bv_xor(unsigned num, expr * const * args, expr_ref & r
18631866
}
18641867

18651868
if (!merged && !flattened && (num_coeffs == 0 || (num_coeffs == 1 && !v1.is_zero() && v1 != (rational::power_of_two(sz) - numeral(1)))) &&
1866-
(!m_bv_sort_ac || is_sorted(num, args)))
1869+
(!m_bv_sort_ac || is_sorted(num, args))) {
1870+
if (distribute_concat(OP_BXOR, num, args, result)) {
1871+
return BR_REWRITE3;
1872+
}
18671873
return BR_FAILED;
1874+
}
18681875

18691876
ptr_buffer<expr> new_args;
18701877
expr_ref c(m()); // may not be used
@@ -1906,11 +1913,35 @@ br_status bv_rewriter::mk_bv_xor(unsigned num, expr * const * args, expr_ref & r
19061913
default:
19071914
if (m_bv_sort_ac)
19081915
std::sort(new_args.begin(), new_args.end(), ast_to_lt());
1916+
if (distribute_concat(OP_BXOR, new_args.size(), new_args.c_ptr(), result)) {
1917+
return BR_REWRITE3;
1918+
}
19091919
result = m_util.mk_bv_xor(new_args.size(), new_args.c_ptr());
19101920
return BR_DONE;
19111921
}
19121922
}
19131923

1924+
bool bv_rewriter::distribute_concat(decl_kind k, unsigned n, expr* const* args, expr_ref& result) {
1925+
for (unsigned i = 0; i < n; ++i) {
1926+
expr* arg = args[i];
1927+
if (m_util.is_concat(arg)) {
1928+
expr* e = to_app(arg)->get_arg(0);
1929+
unsigned sz1 = get_bv_size(e);
1930+
unsigned sz2 = get_bv_size(arg);
1931+
ptr_buffer<expr> args1, args2;
1932+
for (unsigned j = 0; j < n; ++j) {
1933+
args1.push_back(m_mk_extract(sz2-1, sz1, args[j]));
1934+
args2.push_back(m_mk_extract(sz1-1,0, args[j]));
1935+
}
1936+
expr* arg1 = m().mk_app(get_fid(), k, args1.size(), args1.c_ptr());
1937+
expr* arg2 = m().mk_app(get_fid(), k, args2.size(), args2.c_ptr());
1938+
result = m_util.mk_concat(arg1, arg2);
1939+
return true;
1940+
}
1941+
}
1942+
return false;
1943+
}
1944+
19141945
br_status bv_rewriter::mk_bv_not(expr * arg, expr_ref & result) {
19151946
if (m_util.is_bv_not(arg)) {
19161947
result = to_app(arg)->get_arg(0);
@@ -1925,17 +1956,14 @@ br_status bv_rewriter::mk_bv_not(expr * arg, expr_ref & result) {
19251956
return BR_DONE;
19261957
}
19271958

1928-
#if 1
19291959
if (m_util.is_concat(arg)) {
19301960
ptr_buffer<expr> new_args;
1931-
unsigned num = to_app(arg)->get_num_args();
1932-
for (unsigned i = 0; i < num; i++) {
1933-
new_args.push_back(m_util.mk_bv_not(to_app(arg)->get_arg(i)));
1961+
for (expr* a : *to_app(arg)) {
1962+
new_args.push_back(m_util.mk_bv_not(a));
19341963
}
19351964
result = m_util.mk_concat(new_args.size(), new_args.c_ptr());
19361965
return BR_REWRITE2;
19371966
}
1938-
#endif
19391967

19401968
if (m_bvnot2arith) {
19411969
// (bvnot x) --> (bvsub -1 x)

src/ast/rewriter/bv_rewriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class bv_rewriter : public poly_rewriter<bv_rewriter_core> {
107107
br_status mk_bv_shl(expr * arg1, expr * arg2, expr_ref & result);
108108
br_status mk_bv_lshr(expr * arg1, expr * arg2, expr_ref & result);
109109
br_status mk_bv_ashr(expr * arg1, expr * arg2, expr_ref & result);
110+
bool distribute_concat(decl_kind op, unsigned n, expr* const* args, expr_ref& result);
110111
bool is_minus_one_core(expr * arg) const;
111112
bool is_x_minus_one(expr * arg, expr * & x);
112113
bool is_add_no_overflow(expr* e);

src/smt/theory_lra.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,29 +2015,16 @@ class theory_lra::imp {
20152015
}
20162016
while (m_asserted_qhead < m_asserted_atoms.size() && !ctx().inconsistent()) {
20172017
bool_var bv = m_asserted_atoms[m_asserted_qhead].m_bv;
2018-
bool is_true = m_asserted_atoms[m_asserted_qhead].m_is_true;
2019-
2020-
#if 1
2018+
bool is_true = m_asserted_atoms[m_asserted_qhead].m_is_true;
20212019
m_to_check.push_back(bv);
2022-
#else
2023-
propagate_bound(bv, is_true, b);
2024-
#endif
20252020
lp_api::bound& b = *m_bool_var2bound.find(bv);
2026-
assert_bound(bv, is_true, b);
2027-
2028-
2021+
assert_bound(bv, is_true, b);
20292022
++m_asserted_qhead;
20302023
}
20312024
if (ctx().inconsistent()) {
20322025
m_to_check.reset();
20332026
return;
20342027
}
2035-
/*for (; qhead < m_asserted_atoms.size() && !ctx().inconsistent(); ++qhead) {
2036-
bool_var bv = m_asserted_atoms[qhead].m_bv;
2037-
bool is_true = m_asserted_atoms[qhead].m_is_true;
2038-
lp_api::bound& b = *m_bool_var2bound.find(bv);
2039-
propagate_bound_compound(bv, is_true, b);
2040-
}*/
20412028

20422029
lbool lbl = make_feasible();
20432030

0 commit comments

Comments
 (0)