@@ -694,69 +694,80 @@ expr_ref bool_rewriter::simplify_eq_ite(expr* value, expr* ite) {
694
694
SASSERT (m ().is_value (value));
695
695
SASSERT (m ().is_ite (ite));
696
696
expr* c = nullptr , * t = nullptr , * e = nullptr ;
697
- ptr_buffer<expr> todo;
698
- ptr_vector<expr> values;
699
- expr_ref_vector pinned (m ());
700
697
expr_ref r (m ());
698
+ auto & todo = m_todo1;
699
+ 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
+
701
706
todo.push_back (ite);
702
707
while (!todo.empty ()) {
703
708
expr* arg = todo.back ();
709
+ unsigned id = arg->get_id ();
704
710
if (m ().is_value (arg)) {
705
- todo.pop_back ();
706
711
if (m ().are_equal (arg, value)) {
707
- values.setx (arg->get_id (), m ().mk_true (), nullptr );
712
+ todo.pop_back ();
713
+ values.setx (id, m ().mk_true (), nullptr );
714
+ indices.push_back (id);
708
715
continue ;
709
716
}
710
717
if (m ().are_distinct (arg, value)) {
711
- values.setx (arg->get_id (), m ().mk_false (), nullptr );
718
+ todo.pop_back ();
719
+ values.setx (id, m ().mk_false (), nullptr );
720
+ indices.push_back (id);
712
721
continue ;
713
722
}
714
- return expr_ref ( nullptr , m ()) ;
723
+ goto bail ;
715
724
}
716
725
if (m ().is_ite (arg, c, t, e)) {
717
726
unsigned sz = todo.size ();
718
- if (! values.get (t->get_id (), nullptr ))
719
- todo. push_back (t );
720
-
721
- if (!values. get (e-> get_id (), nullptr ))
722
- todo. push_back (e);
723
-
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);
724
733
if (sz < todo.size ())
725
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
+
726
755
todo.pop_back ();
727
- if (m ().is_true (values[t->get_id ()])) {
728
- r = m ().mk_or (c, values[e->get_id ()]);
729
- values.setx (arg->get_id (), r, nullptr );
730
- pinned.push_back (r);
731
- continue ;
732
- }
733
- if (m ().is_false (values[t->get_id ()])) {
734
- r = m ().mk_and (m ().mk_not (c), values[e->get_id ()]);
735
- values.setx (arg->get_id (), r, nullptr );
736
- pinned.push_back (r);
737
- continue ;
738
- }
739
- if (m ().is_false (values[e->get_id ()])) {
740
- r = m ().mk_and (c, values[t->get_id ()]);
741
- values.setx (arg->get_id (), r, nullptr );
742
- pinned.push_back (r);
743
- continue ;
744
- }
745
- if (m ().is_true (values[e->get_id ()])) {
746
- r = m ().mk_or (m ().mk_not (c), values[t->get_id ()]);
747
- values.setx (arg->get_id (), r, nullptr );
748
- pinned.push_back (r);
749
- continue ;
750
- }
751
- r = m ().mk_ite (c, values[t->get_id ()], values[e->get_id ()]);
752
- values.setx (arg->get_id (), r, nullptr );
756
+ values.setx (id, r, nullptr );
757
+ indices.push_back (id);
753
758
pinned.push_back (r);
754
759
continue ;
755
760
}
756
761
IF_VERBOSE (10 , verbose_stream () << " bail " << mk_bounded_pp (arg, m ()) << " \n " );
757
- return expr_ref (nullptr , m ());
758
- }
759
- return expr_ref (values[ite->get_id ()], m ());
762
+ goto bail;
763
+ }
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 ());
760
771
}
761
772
762
773
0 commit comments