https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89847

--- Comment #2 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Interestingly, while this gives optimal code for power8 and power9, we still
get an unnecessary mulli for power10.  This is because multiplication by 31
is expanded to a multiplication on power10 (just like on older PowerPCs, I
tested power4), but to a shift/subtract sequence on these two.

Combine does not know mul-by-15-and-then-add-something is the same as
negate-and-then-add-something, masked to the low 4 bits.  But worse, even
without the addition it just comes up with
(set (reg:SI 120)
    (and:SI (mult:SI (reg:SI 122)
            (const_int 15 [0xf]))
        (const_int 15 [0xf])))
and it also does not if you use 15 instead of 31:

int f3 (int x) { return (15 * x) & 15; }

Reply via email to