[Bug middle-end/82853] Optimize x % 3 == 0 without modulo

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Nov 5 20:15:00 GMT 2017


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |middle-end

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For your code aarch64 produces:
mod3:
        mov     w1, 43691
        movk    w1, 0xaaaa, lsl 16
        umull   x1, w0, w1
        lsr     x1, x1, 32
        lsr     w1, w1, 1
        add     w1, w1, w1, lsl 1
        cmp     w0, w1
        cset    w0, eq
        ret


Oh you mean not to produce a%3 followed by == part :).  Anyways this code
should go into the middle-end expanders and not be part of match.pd.


More information about the Gcc-bugs mailing list