public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jengelh at inai dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple
Date: Mon, 25 Oct 2021 12:53:36 +0000	[thread overview]
Message-ID: <bug-102929-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102929
           Summary: [missed optimization] two ways to
                    rounddown-to-next-multiple
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jengelh at inai dot de
  Target Milestone: ---

Input
=====
unsigned long calc(unsigned long x, unsigned long y)
{
        return x/y*y;
}
unsigned long calc2(unsigned long x, unsigned long y)
{
        return x - x % y;
}

Observed
========
» g++ -O3 -c x.c; objdump -Mintel -d x.o
gcc version 11.2.1 20210816 [revision 056e324ce46a7924b5cf10f61010cf9dd2ca10e9]
(SUSE Linux) x86_64
0000000000000000 <_Z4calcmm>:
   0:   48 89 f8                mov    rax,rdi
   3:   31 d2                   xor    edx,edx
   5:   48 f7 f6                div    rsi
   8:   48 0f af c6             imul   rax,rsi
   c:   c3                      ret    
   d:   0f 1f 00                nop    DWORD PTR [rax]

0000000000000010 <_Z5calc2mm>:
  10:   48 89 f8                mov    rax,rdi
  13:   31 d2                   xor    edx,edx
  15:   48 f7 f6                div    rsi
  18:   48 89 f8                mov    rax,rdi
  1b:   48 29 d0                sub    rax,rdx
  1e:   c3                      ret    

Expected
========
I do not see any obvious differences in the outcome of the two C functions, so
I would expect that, ideally, both should lead to the same asm. (Either by
making calc use div-mov-sub, or by making calc2 using div-imul; whichever
happens to be determined more beneficial as per the machine descriptions).

             reply	other threads:[~2021-10-25 12:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 12:53 jengelh at inai dot de [this message]
2021-10-25 22:11 ` [Bug tree-optimization/102929] " pinskia at gcc dot gnu.org
2021-10-26  7:00 ` rguenth at gcc dot gnu.org
2021-11-17  0:55 ` navidrahimi at microsoft dot com

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-102929-4@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).