public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/86011] Inefficient code generated for ldivmod with constant value
       [not found] <bug-86011-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-21 11:39 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: pinskia at gcc dot gnu.org @ 2021-12-21 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |11.0
         Resolution|---                         |FIXED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 11:

        lsrs    r1, r2, #30
        push    {r4, lr}
        orr     r1, r1, r3, lsl #2
        bic     lr, r1, #-1073741824
        bic     r1, r2, #-1073741824
        add     r1, r1, lr
        asrs    r4, r3, #31
        add     r3, r1, r3, lsr #28
        and     r1, r4, #137
        add     r3, r3, r1
        movw    r1, #57025
        movt    r1, 13617
        bic     r4, r4, #75
        umull   lr, r1, r1, r3
        mov     lr, #77
        lsrs    r1, r1, #4
        mls     r3, lr, r1, r3
        movw    r1, #14469
        movt    r1, 16171
        add     r3, r3, r4
        str     r3, [r0, #4]
        subs    r2, r2, r3
        umull   r2, r1, r2, r1
        str     r2, [r0]
        pop     {r4, pc}

For:
#define N 7723
struct foo { long a, b; };
struct foo test(long long x)
{
        return (struct foo){x / N, x % N};
}
GCC 11+ Produces:

        push    {r4, lr}
        mov     r4, r0
        mov     r1, r3
        mov     r0, r2
        movs    r3, #0
        movw    r2, #7723
        bl      __aeabi_ldivmod
        strd    r0, r2, [r4]
        mov     r0, r4
        pop     {r4, pc}

Which is exactly what you want too.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-21 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-86011-4@http.gcc.gnu.org/bugzilla/>
2021-12-21 11:39 ` [Bug target/86011] Inefficient code generated for ldivmod with constant value pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).