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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>Could be done in match.pd I suppose.


NO!  There are a lot of code in the expander to handle division and modulus by
a constant already.  If the division cost is high enough, then it is not used
directly and the multiply method is used as shown by what happens on aarch64:
f:
        mov     w1, 21846
        movk    w1, 0x5555, lsl 16
        smull   x1, w0, w1
        lsr     x1, x1, 32
        sub     w1, w1, w0, asr 31
        add     w1, w1, w1, lsl 1
        sub     w0, w0, w1
        ret

int f(int a)
{
  return a%3;
}

Reply via email to