On Wed, Jun 5, 2019 at 12:56 PM Martin Liška <mli...@suse.cz> wrote:
>
> Hi.
>
> I'm suggesting one multiplication simplification pattern.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

+  (if (INTEGRAL_TYPE_P (type)
+       && wi::eq_p (get_nonzero_bits (@1), wi::one (TYPE_PRECISION (type)))
+       && wi::eq_p (get_nonzero_bits (@2), wi::one (TYPE_PRECISION (type))))

  && wi::eq_p (wi::bit_or (get_nonzero_bits (@1), get_nonzero_bits  (@2)), 1))

(I think literal 1 still works)?  How does it behave for  singed/unsigned 1-bit
bitfields?  A gimple testcase maybe necessary to see.

Does this mean we want to turn plus into bit_ior when
get_nonzero_bits() & get_nonzero_bits() is zero?

X * [0, 1] -> X & sign-extend-from-bit-1 also works I guess, but multiplication
looks more canonical.

Thanks,
Richard.

> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> 2019-06-05  Martin Liska  <mli...@suse.cz>
>
>         PR tree-optimization/87954
>         * match.pd: Simplify mult where both arguments are 0 or 1.
>
> gcc/testsuite/ChangeLog:
>
> 2019-06-05  Martin Liska  <mli...@suse.cz>
>
>         PR tree-optimization/87954
>         * gcc.dg/pr87954.c: New test.
> ---
>  gcc/match.pd                   |  8 ++++++++
>  gcc/testsuite/gcc.dg/pr87954.c | 21 +++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/pr87954.c
>
>

Reply via email to