public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/105034] New: [10/11/12 regression]Suboptimal codegen for min/max with -Os
@ 2022-03-23  6:50 crazylht at gmail dot com
  2022-03-23 11:01 ` [Bug target/105034] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: crazylht at gmail dot com @ 2022-03-23  6:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105034
           Summary: [10/11/12 regression]Suboptimal codegen for min/max
                    with -Os
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---

#define max(a,b) (((a) > (b))? (a) : (b))
#define min(a,b) (((a) < (b))? (a) : (b))

int foo(int x)
{
  return max(x,0);
}

int bar(int x)
{
  return min(x,0);
}

unsigned int baz(unsigned int x)
{
  return min(x,1);
}

gcc10/11/12 -Os -msse4.1

foo(int):
        movd    xmm0, edi
        xorps   xmm1, xmm1
        pmaxsd  xmm0, xmm1
        movd    eax, xmm0
        ret
bar(int):
        movd    xmm0, edi
        xorps   xmm1, xmm1
        pminsd  xmm0, xmm1
        movd    eax, xmm0
        ret
baz(unsigned int):
        xor     eax, eax
        test    edi, edi
        setne   al
        ret

gcc9.4 -Os -msse4.1

foo(int):
        test    edi, edi
        mov     eax, 0
        cmovns  eax, edi
        ret
bar(int):
        test    edi, edi
        mov     eax, 0
        cmovle  eax, edi
        ret
baz(unsigned int):
        xor     eax, eax
        test    edi, edi
        setne   al
        ret

Os size 
   text    data     bss     dec     hex filename
    178       0       0     178      b2 Os.o


O2 size
   text    data     bss     dec     hex filename
    176       0       0     176      b0 O2.o

https://godbolt.org/z/1sYxdTcKz

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

end of thread, other threads:[~2023-11-01  3:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23  6:50 [Bug target/105034] New: [10/11/12 regression]Suboptimal codegen for min/max with -Os crazylht at gmail dot com
2022-03-23 11:01 ` [Bug target/105034] " rguenth at gcc dot gnu.org
2022-03-28  2:49 ` wwwhhhyyy333 at gmail dot com
2022-04-14  8:38 ` roger at nextmovesoftware dot com
2022-04-14  9:00 ` rguenth at gcc dot gnu.org
2022-04-14  9:20 ` roger at nextmovesoftware dot com
2022-06-28 10:48 ` [Bug target/105034] [10/11/12/13 " jakub at gcc dot gnu.org
2023-07-07 10:42 ` [Bug target/105034] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-11-01  3:54 ` crazylht at gmail 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).