Skip to content

Commit 236cb6c

Browse files
committed
Avoid use of sort_and_join in guard operations
1 parent f63bec3 commit 236cb6c

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/goto-symex/goto_symex_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class goto_symex_statet
188188
level2t::current_namest level2_current_names;
189189
value_sett value_set;
190190
guardt guard;
191+
guardt guard_before_branch;
191192
propagationt propagation;
192193
unsigned atomic_section_id;
193194

src/goto-symex/symex_goto.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void goto_symext::symex_goto(statet &state)
158158
state.rename(guard_expr, ns);
159159
}
160160

161+
new_state.guard_before_branch=state.guard;
161162
if(forward)
162163
{
163164
new_state.guard.add(guard_expr);
@@ -366,11 +367,38 @@ void goto_symext::phi_function(
366367
else
367368
{
368369
guardt tmp_guard(goto_state.guard);
370+
guardt tmp_guard2(goto_state.guard);
369371

370372
// this gets the diff between the guards
371-
tmp_guard-=dest_state.guard;
372-
373-
rhs=if_exprt(tmp_guard.as_expr(), goto_state_rhs, dest_state_rhs);
373+
// tmp_guard-=dest_state.guard;
374+
if(!goto_state.guard_before_branch.is_constant())
375+
{
376+
assert(tmp_guard2.id()==ID_and);
377+
378+
if(goto_state.guard_before_branch.id()==ID_and)
379+
{
380+
assert(tmp_guard2.operands().size()>
381+
goto_state.guard_before_branch.operands().size());
382+
for(const auto & op : goto_state.guard_before_branch.operands())
383+
{
384+
// assert(tmp_guard2.operands().front()==op);
385+
(void)op;
386+
tmp_guard2.operands().erase(tmp_guard2.operands().begin());
387+
}
388+
}
389+
else
390+
{
391+
assert(tmp_guard2.operands().front()==
392+
goto_state.guard_before_branch);
393+
tmp_guard2.operands().erase(tmp_guard2.operands().begin());
394+
}
395+
396+
if(tmp_guard2.operands().size()==1)
397+
tmp_guard2=tmp_guard2.op0();
398+
}
399+
// assert(tmp_guard==tmp_guard2);
400+
401+
rhs=if_exprt(tmp_guard2.as_expr(), goto_state_rhs, dest_state_rhs);
374402
do_simplify(rhs);
375403
}
376404

src/util/guard.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ guardt& guardt::logical_or(const guardt &g2, const namespacet &ns)
187187
if(g2.is_false() || g1.is_true()) return g1;
188188
if(g1.is_false() || g2.is_true()) { g1=g2; return g1; }
189189

190+
{
191+
exprt tmp(g2);
192+
tmp.make_not();
193+
194+
if(tmp==g1)
195+
g1.make_true();
196+
else
197+
g1=or_exprt(g1, g2);
198+
199+
bdd_exprt t(ns);
200+
t.from_expr(g1);
201+
g1=t.as_expr();
202+
203+
return g1;
204+
}
205+
190206
if(g1.id()!=ID_and || g2.id()!=ID_and)
191207
{
192208
exprt tmp(g2);

0 commit comments

Comments
 (0)