public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/86011] Inefficient code generated for ldivmod with constant value
Date: Tue, 21 Dec 2021 11:39:23 +0000	[thread overview]
Message-ID: <bug-86011-4-baR7LqSLbS@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-86011-4@http.gcc.gnu.org/bugzilla/>

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.

           reply	other threads:[~2021-12-21 11:39 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <bug-86011-4@http.gcc.gnu.org/bugzilla/>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-86011-4-baR7LqSLbS@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).