[PATCH] match.pd: undistribute (a << s) & C, when C = (M << s) and exact_log2(M - 1)

Jakub Jelinek jakub@redhat.com
Wed Nov 11 10:55:08 GMT 2020


On Wed, Nov 11, 2020 at 11:43:34AM +0100, Philipp Tomsich wrote:
> The patch addresses this by disallowing that rule, if an exact power-of-2 is
> seen as C1.  The reason why I would prefer to have this canonicalised the
> same way the (X & C1) * C2 is canonicalised, is that cleaning this up during
> combine is more difficult on some architectures that require multiple insns
> to represent the shifted constant (i.e. C1 << C2).

It is bad to have many exceptions for the canonicalization
and it is unclear why exactly these were chosen, and it doesn't really deal
with say:
(x & 0xabcdef12ULL) << 13
being less expensive on some targets than
(x << 13) & (0xabcdef12ULL << 13).
(x & 0x7ffff) << 3 vs. (x << 3) & 0x3ffff8 on the other side is a wash on
many targets.
As I said, it is better to decide which one is better before or during
expansion based on target costs, sure, combine can't catch everything.

Also, the patch formatting was incorrect in several ways (indentation,
missing space before ( when calling functions, etc.).

	Jakub



More information about the Gcc-patches mailing list