public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple
@ 2021-10-25 12:53 jengelh at inai dot de
  2021-10-25 22:11 ` [Bug tree-optimization/102929] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jengelh at inai dot de @ 2021-10-25 12:53 UTC (permalink / raw)
  To: gcc-bugs

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).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/102929] [missed optimization] two ways to rounddown-to-next-multiple
  2021-10-25 12:53 [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple jengelh at inai dot de
@ 2021-10-25 22:11 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-25 22:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/102929] [missed optimization] two ways to rounddown-to-next-multiple
  2021-10-25 12:53 [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple jengelh at inai dot de
  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
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-26  7:00 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-10-26

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  I do remember patches flowing by for x/y*y -> x - x%y.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/102929] [missed optimization] two ways to rounddown-to-next-multiple
  2021-10-25 12:53 [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple jengelh at inai dot de
  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
  2 siblings, 0 replies; 4+ messages in thread
From: navidrahimi at microsoft dot com @ 2021-11-17  0:55 UTC (permalink / raw)
  To: gcc-bugs

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

Navid Rahimi <navidrahimi at microsoft dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |navidrahimi at microsoft dot com

--- Comment #2 from Navid Rahimi <navidrahimi at microsoft dot com> ---
https://compiler-explorer.com/z/rMKnddh3G

Seems the patch has been landed. We can close this bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-17  0:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 12:53 [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple jengelh at inai dot de
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

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).