-
Notifications
You must be signed in to change notification settings - Fork 273
Optimize loop of phi_function #3522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize loop of phi_function #3522
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The performance improvement is of course desirable, but could the changes please be done in a way so that the diff (when switching on skip-whitespace) is readable?
src/goto-symex/symex_goto.cpp
Outdated
/// second one then j is 0, and when the first map has no entry for k then i = 0 | ||
static void for_each2( | ||
std::map<irep_idt, std::pair<ssa_exprt, unsigned>> first_map, | ||
std::map<irep_idt, std::pair<ssa_exprt, unsigned>> second_map, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these maps passed by value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's a mistake
171afa9
to
bafafeb
Compare
9c3ea08
to
c796942
Compare
@tautschnig this is ready for re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: c796942).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/93674773
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of suggestions left, I think we should be good to go once these are in.
src/goto-symex/symex_goto.cpp
Outdated
{ | ||
diff_guard=goto_state.guard; | ||
if(all_current_names_range.empty()) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but then you don't need the declaration above either. Could you make the first definition below also be the declaration?
src/goto-symex/symex_goto.cpp
Outdated
symex_config.simplify_opt, | ||
target, | ||
l1_identifier, | ||
ssa); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pass in ssa
anyway, then l1_identifier
should be computed from that in the body of merge_names
.
src/goto-symex/symex_goto.cpp
Outdated
// once the thread is executed) | ||
if( | ||
!ssa.get_level_0().empty() && | ||
ssa.get_level_0() != std::to_string(dest_state.source.thread_nr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding an extra commit that avoids this duplicate call to get_level_0()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
The clang-format commit should be merged into the relevant earlier commits. |
This will allow to more easily extract the code in the loop into a new function.
This simplifies phi_function which was too long.
Since these are used several times in the function we can avoid some lookups by pre-computing it. We make them parameters to allow later commits to give them without lookup.
Inside phi_function we can avoid a lot of lookups if we iterate over the two maps at the same time, since they are ordered.
c796942
to
bbec003
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: bbec003).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/93783524
This function was performing unnecessary lookups (even after
ranget
), we avoid this by introducing a function which goes through both maps and use the fact that they are ordered.I tested this optimization on 73 methods from tika which where taking between 600ms and 30s with --show-vcc and --verbosity 0, the total time was improved by 20% (from 229s to 185s). Here is a comparison of the execution times
