Skip to content
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

either fix up or remove the constant-case multiplier #5512

Closed
wants to merge 1 commit into from

Conversation

jameysharp
Copy link
Contributor

There's been a mk_const_case_multiplier in the bit-blaster since 2015, but in all that time its output has never been used. With this PR I'm trying to give this multiplier the best opportunity to show its value over straightforward long multiplication. If it doesn't actually help, then instead of merging this PR I propose to remove the implementation.

@NikolajBjorner, would you mind running a performance comparison of this patch versus master?

This code executes every time a bvmul is bit-blasted and has exactly one
constant operand, but its output was always discarded because it
unconditionally returns `false`.

I'm trying to give this multiplier the best opportunity to show its
value over straightforward long multiplication with three changes:

- Try this variant even if some bits in both operands are not constant.
  If there are too many such bits it will still refuse to apply this
  potentially exponential-space transformation, though.

- Use bool_rewriter's mk_ite simplifications, instead of calling
  ast_manager's mk_ite directly.

- And, of course, return `true` if the transformation applied, so we can
  see what happens when it's actually used.
@NikolajBjorner
Copy link
Contributor

with the current branch I get

image

The trend seems to be very clearly in favor of this change.
We will need to merge with the master and I will retest to make sure there isn't something regressed from my changes.

GIven that this has the clearest signal, I would merge this first.

@@ -1247,20 +1253,16 @@ void bit_blaster_tpl<Cfg>::mk_const_case_multiplier(bool is_a, unsigned i, unsig

template<typename Cfg>
bool bit_blaster_tpl<Cfg>::mk_const_multiplier(unsigned sz, expr * const * a_bits, expr * const * b_bits, expr_ref_vector & out_bits) {
if (!m_use_bcm) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed m_use_bcm. It would always be false, but my change almost for sure changes the behavior which I would have to revise or check.

@@ -1212,7 +1216,7 @@ bool bit_blaster_tpl<Cfg>::mk_const_case_multiplier(unsigned sz, expr * const *
ptr_buffer<expr, 128> nb_bits;
nb_bits.append(sz, b_bits);
mk_const_case_multiplier(true, 0, sz, na_bits, nb_bits, out_bits);
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a terrible mistake

@NikolajBjorner
Copy link
Contributor

Since I introduced a bug in my previous push (a code path ignores that m_use_bcm is now false) I am porting your pull request directly and trying it out. There seems to be no longer a use for mk_const_multiplier either so this can be removed.
After testing I would push this today or tomorrow. No need to update this pull request but I will reference it on the push.

NikolajBjorner added a commit that referenced this pull request Aug 28, 2021
Pull request #5512 identifies a in line 1139 where the const-case-multiplier constructor returns false and does useless work.
In this update we also remove mk_const_multiplier because code path is subsumed by mk_const_case_multiplier.
@NikolajBjorner
Copy link
Contributor

The changes from this pull request have now been integrated.

@NikolajBjorner
Copy link
Contributor

image

@jameysharp
Copy link
Contributor Author

One note about the version you merged: you only need to call the const case multiplier once. If calling it with the arguments one way around returns false, the other way will too. In the previous version it had to be called twice just because it was called only when its first argument was entirely constant, but that's not true in the current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants