Skip to content

Commit 4fd6ba4

Browse files
replace costly ite reduction by disjointnes check
1 parent 392bc16 commit 4fd6ba4

File tree

2 files changed

+20
-69
lines changed

2 files changed

+20
-69
lines changed

src/ast/rewriter/bool_rewriter.cpp

+17-65
Original file line numberDiff line numberDiff line change
@@ -690,84 +690,36 @@ br_status bool_rewriter::try_ite_value(app * ite, app * val, expr_ref & result)
690690
return BR_FAILED;
691691
}
692692

693+
// check that all leaves are disjoint.
693694
expr_ref bool_rewriter::simplify_eq_ite(expr* value, expr* ite) {
694695
SASSERT(m().is_value(value));
695696
SASSERT(m().is_ite(ite));
696697
expr* c = nullptr, * t = nullptr, * e = nullptr;
697-
expr_ref r(m());
698698
auto& todo = m_todo1;
699699
todo.reset();
700-
auto& values = m_values;
701-
auto& pinned = m_pinned;
702-
auto& indices = m_indices;
703-
expr* result = nullptr;
704-
SASSERT(indices.empty());
705-
706700
todo.push_back(ite);
701+
bool is_disjoint = true;
707702
while (!todo.empty()) {
708703
expr* arg = todo.back();
709-
unsigned id = arg->get_id();
710-
if (m().is_value(arg)) {
711-
if (m().are_equal(arg, value)) {
712-
todo.pop_back();
713-
values.setx(id, m().mk_true(), nullptr);
714-
indices.push_back(id);
715-
continue;
716-
}
717-
if (m().are_distinct(arg, value)) {
718-
todo.pop_back();
719-
values.setx(id, m().mk_false(), nullptr);
720-
indices.push_back(id);
721-
continue;
722-
}
723-
goto bail;
724-
}
704+
todo.pop_back();
705+
if (m_marked.is_marked(arg))
706+
continue;
707+
m_marked.mark(arg, true);
708+
if (m().is_value(arg) && m().are_distinct(arg, value))
709+
continue;
725710
if (m().is_ite(arg, c, t, e)) {
726-
unsigned sz = todo.size();
727-
auto th = values.get(t->get_id(), nullptr);
728-
auto el = values.get(e->get_id(), nullptr);
729-
if (!th)
730-
todo.push_back(t);
731-
if (!el)
732-
todo.push_back(e);
733-
if (sz < todo.size())
734-
continue;
735-
736-
if (m().is_false(th) && m().is_false(el))
737-
r = m().mk_false();
738-
else if (m().is_true(th) && m().is_true(el))
739-
r = m().mk_true();
740-
else if (m().is_true(th) && m().is_false(el))
741-
r = c;
742-
else if (m().is_false(th) && m().is_true(el))
743-
r = m().mk_not(c);
744-
else if (m().is_true(th))
745-
r = m().mk_or(c, el);
746-
else if (m().is_false(th))
747-
r = m().mk_and(m().mk_not(c), el);
748-
else if (m().is_false(el))
749-
r = m().mk_and(c, th);
750-
else if (m().is_true(el))
751-
r = m().mk_or(m().mk_not(c), th);
752-
else
753-
r = m().mk_ite(c, th, el);
754-
755-
todo.pop_back();
756-
values.setx(id, r, nullptr);
757-
indices.push_back(id);
758-
pinned.push_back(r);
711+
if (!m_marked.is_marked(t))
712+
todo.push_back(t);
713+
if (!m_marked.is_marked(e))
714+
todo.push_back(e);
759715
continue;
760716
}
761-
IF_VERBOSE(10, verbose_stream() << "bail " << mk_bounded_pp(arg, m()) << "\n");
762-
goto bail;
717+
is_disjoint = false;
718+
break;
763719
}
764-
bail:
765-
if (todo.empty())
766-
result = values[ite->get_id()];
767-
for (auto idx : indices)
768-
values[idx] = nullptr;
769-
indices.reset();
770-
return expr_ref(result, m());
720+
m_marked.reset();
721+
todo.reset();
722+
return expr_ref(is_disjoint ? m().mk_false() : nullptr, m());
771723
}
772724

773725

src/ast/rewriter/bool_rewriter.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ class bool_rewriter {
6363
bool m_elim_ite;
6464
bool m_elim_ite_value_tree;
6565
ptr_vector<expr> m_todo1, m_todo2;
66-
unsigned_vector m_counts1, m_counts2, m_indices;
67-
ptr_vector<expr> m_values;
68-
expr_ref_vector m_pinned;
66+
unsigned_vector m_counts1, m_counts2;
67+
expr_fast_mark1 m_marked;
6968

7069
br_status mk_flat_and_core(unsigned num_args, expr * const * args, expr_ref & result);
7170
br_status mk_flat_or_core(unsigned num_args, expr * const * args, expr_ref & result);
@@ -89,7 +88,7 @@ class bool_rewriter {
8988
expr_ref simplify_eq_ite(expr* value, expr* ite);
9089

9190
public:
92-
bool_rewriter(ast_manager & m, params_ref const & p = params_ref()):m_manager(m), m_local_ctx_cost(0), m_pinned(m) {
91+
bool_rewriter(ast_manager & m, params_ref const & p = params_ref()):m_manager(m), m_local_ctx_cost(0) {
9392
updt_params(p);
9493
}
9594
ast_manager & m() const { return m_manager; }

0 commit comments

Comments
 (0)