match.pd: Canonicalize (x + (x << cst)) into (x * cst2) [PR94800]
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 May 2020 09:36:47 +0000 (11:36 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 5 May 2020 09:36:47 +0000 (11:36 +0200)
commit144aee70b80de50f96a97ee64edd2f1c237c4906
treea0b80710604088be014e425ee8ef0cb9a64cf5bc
parent7f916201ac390a5e1c88562bb91b1b4ab2852f22
match.pd: Canonicalize (x + (x << cst)) into (x * cst2) [PR94800]

The popcount* testcases show yet another creative way to write popcount,
but rather than adjusting the popcount matcher to deal with it, I think
we just should canonicalize those (X + (X << C) to X * (1 + (1 << C))
and (X << C1) + (X << C2) to X * ((1 << C1) + (1 << C2)), because for
multiplication we already have simplification rules that can handle nested
multiplication (X * CST1 * CST2), while the the shifts and adds we have
nothing like that.  And user could have written the multiplication anyway,
so if we don't emit the fastest or smallest code for the multiplication by
constant, we should improve that.  At least on the testcases seems the
emitted code is reasonable according to cost, except that perhaps we could
in some cases try to improve expansion of vector multiplication by
uniform constant.

2020-05-05  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/94800
* match.pd (X + (X << C) to X * (1 + (1 << C)),
(X << C1) + (X << C2) to X * ((1 << C1) + (1 << C2))): New
canonicalizations.

* gcc.dg/tree-ssa/pr94800.c: New test.
* gcc.dg/tree-ssa/popcount5.c: New test.
* gcc.dg/tree-ssa/popcount5l.c: New test.
* gcc.dg/tree-ssa/popcount5ll.c: New test.
gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/popcount5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/popcount5l.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/popcount5ll.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr94800.c [new file with mode: 0644]