public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59424] New: Optimization issue on min/max
@ 2013-12-09  6:01 jmvalin at jmvalin dot ca
  2013-12-09 11:13 ` [Bug c/59424] " mpolacek at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jmvalin at jmvalin dot ca @ 2013-12-09  6:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59424

            Bug ID: 59424
           Summary: Optimization issue on min/max
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jmvalin at jmvalin dot ca

gcc seems to be having problems optimizing float min/max code and behaves
unpredictably. If I compile the following code on an x86-64 (SSE enabled):

#include <math.h>

float func1(float a, float b) {
  return (a < b ? a : b);
}

float func2(float a, float b) {
  return sqrtf(a < b ? a : b);
}

float func3(float a, float b) {
  return fabsf(a < b ? a : b);
}

I get the following disassembly:

0000000000000000 <func1>:
func1():
   0:   f3 0f 5d c1             minss  %xmm1,%xmm0
   4:   c3                      retq   
   5:   66 66 2e 0f 1f 84 00    data32 nopw %cs:0x0(%rax,%rax,1)
   c:   00 00 00 00 

0000000000000010 <func2>:
func2():
  10:   f3 0f 5d c1             minss  %xmm1,%xmm0
  14:   f3 0f 51 c0             sqrtss %xmm0,%xmm0
  18:   c3                      retq   
  19:   0f 1f 80 00 00 00 00    nopl   0x0(%rax)

0000000000000020 <func3>:
func3():
  20:   0f 2f c8                comiss %xmm0,%xmm1
  23:   77 13                   ja     38 <func3+0x18>
  25:   f3 0f 10 05 00 00 00    movss  0x0(%rip),%xmm0        # 2d <func3+0xd>
  2c:   00 
  2d:   0f 54 c1                andps  %xmm1,%xmm0
  30:   c3                      retq   
  31:   0f 1f 80 00 00 00 00    nopl   0x0(%rax)
  38:   f3 0f 10 0d 00 00 00    movss  0x0(%rip),%xmm1        # 40 <func3+0x20>
  3f:   00 
  40:   0f 54 c1                andps  %xmm1,%xmm0
  43:   c3                      retq   


So gcc is correctly using maxss in func1 and func2, but not in func2. In
practice, I'm using MIN/MAX macros extensively in libopus and gcc is missing
the optimization most of the time, slowing down the code.


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

end of thread, other threads:[~2023-05-08  7:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-09  6:01 [Bug c/59424] New: Optimization issue on min/max jmvalin at jmvalin dot ca
2013-12-09 11:13 ` [Bug c/59424] " mpolacek at gcc dot gnu.org
2013-12-09 14:49 ` rguenth at gcc dot gnu.org
2013-12-09 17:05 ` jmvalin at jmvalin dot ca
2021-07-06  8:18 ` [Bug middle-end/59424] " pinskia at gcc dot gnu.org
2023-05-08  7:38 ` cvs-commit at gcc dot gnu.org
2023-05-08  7:41 ` 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).