public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack
@ 2004-05-17 22:20 uros at kss-loka dot si
  2004-05-17 22:21 ` [Bug rtl-optimization/15492] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: uros at kss-loka dot si @ 2004-05-17 22:20 UTC (permalink / raw)
  To: gcc-bugs

This testcase shows another problem with x87 stack:

double test (double a, double b) {
        return a*a +  b*b;
}

In this case, floating point arguments are loaded too early to x87 stack,
with 'gcc -O2', resulting asm is:
test:
        pushl   %ebp
        movl    %esp, %ebp
        fldl    8(%ebp)
        fldl    16(%ebp)
        fxch    %st(1)
        fmul    %st(0), %st
        fxch    %st(1)
        popl    %ebp
        fmul    %st(0), %st
        faddp   %st, %st(1)
        ret
 
The situation is a little better with '-O2 -fomit-frame-pointer':
test:
        fldl    4(%esp)
        fldl    12(%esp)
        fmul    %st(0), %st
        fxch    %st(1)
        fmul    %st(0), %st
        faddp   %st, %st(1)
        ret

But optimal code would look something like this (second arg should be loaded to
stack in some kind of 'just in time' fashion.
test:
        fldl    4(%esp)
        fmul    %st(0), %st
        fldl    12(%esp)
        fmul    %st(0), %st
        faddp   %st, %st(1)
        ret

-- 
           Summary: floating-point arguments are loaded too early to x87
                    stack
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: uros at kss-loka dot si
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug rtl-optimization/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
@ 2004-05-17 22:21 ` pinskia at gcc dot gnu dot org
  2004-08-17  8:00 ` [Bug target/15492] " uros at kss-loka dot si
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-17 22:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-17 13:18 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |pessimizes-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-05-17 13:18:50
               date|                            |


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
  2004-05-17 22:21 ` [Bug rtl-optimization/15492] " pinskia at gcc dot gnu dot org
@ 2004-08-17  8:00 ` uros at kss-loka dot si
  2004-08-17  8:58 ` uros at kss-loka dot si
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: uros at kss-loka dot si @ 2004-08-17  8:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From uros at kss-loka dot si  2004-08-17 08:00 -------
When testcase is compiled without optimizations (with gcc -fomit-frame-pointer),
following code is produced:

test:
        fldl    4(%esp)
        fmull   4(%esp)
        fldl    12(%esp)
        fmull   12(%esp)
        faddp   %st, %st(1)
        ret




-- 


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
  2004-05-17 22:21 ` [Bug rtl-optimization/15492] " pinskia at gcc dot gnu dot org
  2004-08-17  8:00 ` [Bug target/15492] " uros at kss-loka dot si
@ 2004-08-17  8:58 ` uros at kss-loka dot si
  2004-08-19  8:07 ` uros at kss-loka dot si
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: uros at kss-loka dot si @ 2004-08-17  8:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From uros at kss-loka dot si  2004-08-17 08:58 -------
A couple of other testcases (please note the number of fxch isns!):

double test1 (double a, int x, double b, int y, double c)
{
        return sin (c) + tan (b) * sqrt (a) + x * fabs (b) + y;
}

with 'gcc -ffast-math -fomit-frame-pointer':
test1:
        fldl    28(%esp)
        fsin
        fldl    16(%esp)
        fptan
        fstp    %st(0)
        fldl    4(%esp)
        fsqrt
        fmulp   %st, %st(1)
        faddp   %st, %st(1)
        fildl   12(%esp)
        fldl    16(%esp)
        fabs
        fmulp   %st, %st(1)
        faddp   %st, %st(1)
        fildl   24(%esp)
        faddp   %st, %st(1)
        ret

with 'gcc -O2 -ffast-math -fomit-frame-pointer':
test1:
        fldl    16(%esp)
        fldl    4(%esp)
        fld     %st(1)
        fptan
        fstp    %st(0)
        fldl    28(%esp)
        fxch    %st(3)
        fabs
        fxch    %st(2)
        fsqrt
        fxch    %st(3)
        fsin
        fxch    %st(1)
        fmulp   %st, %st(3)
        faddp   %st, %st(2)
        fildl   12(%esp)
        fmulp   %st, %st(1)
        faddp   %st, %st(1)
        fildl   24(%esp)
        faddp   %st, %st(1)
        ret

The shortest testcase could be:
double test1 (double y, double x)
{
        return atan2(x, y);
}

with 'gcc -ffast-math -fomit-frame-pointer':
test1:
        fldl    12(%esp)
        fldl    4(%esp)
        fpatan
        ret


with 'gcc -O2 -ffast-math -fomit-frame-pointer':
test1:
        fldl    4(%esp)
        fldl    12(%esp)
        fxch    %st(1)
        fpatan
        ret


-- 


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (2 preceding siblings ...)
  2004-08-17  8:58 ` uros at kss-loka dot si
@ 2004-08-19  8:07 ` uros at kss-loka dot si
  2004-08-19 13:12 ` bangerth at dealii dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: uros at kss-loka dot si @ 2004-08-19  8:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From uros at kss-loka dot si  2004-08-19 08:07 -------
According to "How to optimize for the Pentium family of microprocessors" by
Agner Fog, "fld r/m32/m64" consumes one clock cycle on P1, PMMX, PPRO, P2, P3
and P4, and "fld m80" consumes 3 cycles on P1, PMMX and P4 and two cycles on
PPRO, P2 and P3.

This means, that code in all examples will be faster, because there is less fxch
instructions. Also, more fp-stack could be used to store temporary variables if
arguments are taken from stack when needed instead of copying their value
between fp stack registers.

There is a question if it is worth to special-case "fld m80" instructions to use
fp register copies instead of memory load. Again, a lot of fxch instructions
would be needed and fp stack space could be wasted with register copies.



-- 


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (3 preceding siblings ...)
  2004-08-19  8:07 ` uros at kss-loka dot si
@ 2004-08-19 13:12 ` bangerth at dealii dot org
  2004-09-13 13:06 ` uros at kss-loka dot si
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2004-08-19 13:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-19 13:12 -------
Some discussion is here: 
  http://gcc.gnu.org/ml/gcc/2004-08/msg00939.html 

-- 


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (4 preceding siblings ...)
  2004-08-19 13:12 ` bangerth at dealii dot org
@ 2004-09-13 13:06 ` uros at kss-loka dot si
  2004-09-13 13:14 ` giovannibajo at libero dot it
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: uros at kss-loka dot si @ 2004-09-13 13:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From uros at kss-loka dot si  2004-09-13 13:06 -------
With a patch from Jan Hubicka:
http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01178.html

'gcc -O2 -ffast-math -S -march=pentium4 -fomit-frame-pointer' now produces:

test1:
        fldl    4(%esp)
        fldl    16(%esp)
        fldl    28(%esp)
        fsin
        fld     %st(1)
        fptan
        fstp    %st(0)
        fxch    %st(3)
        fsqrt
        fmulp   %st, %st(3)
        faddp   %st, %st(2)
        fabs
        fimull  12(%esp)
        faddp   %st, %st(1)
        fiaddl  24(%esp)
        ret


-- 


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (5 preceding siblings ...)
  2004-09-13 13:06 ` uros at kss-loka dot si
@ 2004-09-13 13:14 ` giovannibajo at libero dot it
  2004-09-13 14:49 ` uros at kss-loka dot si
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-13 13:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-09-13 13:13 -------
So, it looks like it's fixed?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at libero dot
                   |                            |it


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (6 preceding siblings ...)
  2004-09-13 13:14 ` giovannibajo at libero dot it
@ 2004-09-13 14:49 ` uros at kss-loka dot si
  2005-06-21 11:24 ` steven at gcc dot gnu dot org
  2005-06-21 11:31 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 13+ messages in thread
From: uros at kss-loka dot si @ 2004-09-13 14:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From uros at kss-loka dot si  2004-09-13 14:49 -------
(In reply to comment #7)
> So, it looks like it's fixed?

Hm, first testcase still produces (gcc -O2 -ffast-math -march=pentium4
-fomit-frame-pointer).
test:
        fldl    4(%esp)
        fldl    12(%esp)
        fxch    %st(1)
        fmul    %st(0), %st
        fxch    %st(1)
        fmul    %st(0), %st
        faddp   %st, %st(1)
        ret

It looks that gcc does not know that arguments to add can be exchanged and is
emitting fxch insns to get arguments in the top stack position.

-- 


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (7 preceding siblings ...)
  2004-09-13 14:49 ` uros at kss-loka dot si
@ 2005-06-21 11:24 ` steven at gcc dot gnu dot org
  2005-06-21 11:31 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-06-21 11:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-06-21 11:24 -------
reg-stack has been reworked quite a bit recently.  Where do we stand on 
this one now? 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
  2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
                   ` (8 preceding siblings ...)
  2005-06-21 11:24 ` steven at gcc dot gnu dot org
@ 2005-06-21 11:31 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-21 11:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-21 11:31 -------
The first one is still producing the same old stupid code.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
   Last reconfirmed|2005-06-20 02:33:16         |2005-06-21 11:31:39
               date|                            |


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


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
       [not found] <bug-15492-4@http.gcc.gnu.org/bugzilla/>
@ 2013-01-13 11:28 ` ubizjak at gmail dot com
  0 siblings, 0 replies; 13+ messages in thread
From: ubizjak at gmail dot com @ 2013-01-13 11:28 UTC (permalink / raw)
  To: gcc-bugs


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

Uros Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vhaisman at gmail dot com

--- Comment #12 from Uros Bizjak <ubizjak at gmail dot com> 2013-01-13 11:28:23 UTC ---
*** Bug 55952 has been marked as a duplicate of this bug. ***


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

* [Bug target/15492] floating-point arguments are loaded too early to x87 stack
       [not found] <bug-15492-1649@http.gcc.gnu.org/bugzilla/>
@ 2006-07-21 17:07 ` hubicka at gcc dot gnu dot org
  0 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2006-07-21 17:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from hubicka at gcc dot gnu dot org  2006-07-21 17:07 -------
Unless reg-stack is told how to reschedule the instructions to match register
stack constraints, I don't think we can get much closer to solving the problem
that some instruction orderings needs a lot more fxchs than others...

Honza


-- 


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


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

end of thread, other threads:[~2013-01-13 11:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-17 22:20 [Bug rtl-optimization/15492] New: floating-point arguments are loaded too early to x87 stack uros at kss-loka dot si
2004-05-17 22:21 ` [Bug rtl-optimization/15492] " pinskia at gcc dot gnu dot org
2004-08-17  8:00 ` [Bug target/15492] " uros at kss-loka dot si
2004-08-17  8:58 ` uros at kss-loka dot si
2004-08-19  8:07 ` uros at kss-loka dot si
2004-08-19 13:12 ` bangerth at dealii dot org
2004-09-13 13:06 ` uros at kss-loka dot si
2004-09-13 13:14 ` giovannibajo at libero dot it
2004-09-13 14:49 ` uros at kss-loka dot si
2005-06-21 11:24 ` steven at gcc dot gnu dot org
2005-06-21 11:31 ` pinskia at gcc dot gnu dot org
     [not found] <bug-15492-1649@http.gcc.gnu.org/bugzilla/>
2006-07-21 17:07 ` hubicka at gcc dot gnu dot org
     [not found] <bug-15492-4@http.gcc.gnu.org/bugzilla/>
2013-01-13 11:28 ` ubizjak 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).