public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/49583] New: Reloading stack operands in the wrong order, so needs to insert fxch
@ 2011-06-29 18:18 sgunderson at bigfoot dot com
  2011-06-30 10:08 ` [Bug target/49583] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sgunderson at bigfoot dot com @ 2011-06-29 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Reloading stack operands in the wrong order, so needs
                    to insert fxch
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sgunderson@bigfoot.com


Created attachment 24638
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24638
Minimal testcase

Hi,

It seems that when generating x87 code, GCC sometimes reloads items from the
stack in the wrong order, and then goes to great lengths to swap them around. I
have an example with six loads and six fxch instructions, but attached is a
minimal example. Compiling with "gcc version 4.6.1 (Debian 4.6.1-1)" as
follows:

pannekake:~> gcc-4.6 -m32 -Wall -O2 -march=pentium3 -c fxch.c

The odd sequence is around this:

  41:    d9 44 24 48              flds   0x48(%esp)
  45:    dd 5c 24 08              fstpl  0x8(%esp)
  49:    dd 14 24                 fstl   (%esp)
  4c:    d9 5c 24 10              fstps  0x10(%esp)
  50:    e8 fc ff ff ff           call   51 <process+0x51>
  55:    d9 5c 24 1c              fstps  0x1c(%esp)
  59:    d9 44 24 1c              flds   0x1c(%esp)
  5d:    d9 44 24 10              flds   0x10(%esp)
  61:    d9 c9                    fxch   %st(1)
  63:    d9 1c b7                 fstps  (%edi,%esi,4)
  66:    46                       inc    %esi
  67:    39 ee                    cmp    %ebp,%esi

In particular, why did it use fstps immediately followed by flds of the same
value? And if it really wants to reload (in my more complex example, it really
needs to), why not just do the loads in the right order from the start instead
of doing the fxch?


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

* [Bug target/49583] Reloading stack operands in the wrong order, so needs to insert fxch
  2011-06-29 18:18 [Bug tree-optimization/49583] New: Reloading stack operands in the wrong order, so needs to insert fxch sgunderson at bigfoot dot com
@ 2011-06-30 10:08 ` rguenth at gcc dot gnu.org
  2011-07-03 14:39 ` ubizjak at gmail dot com
  2011-07-03 17:20 ` sgunderson at bigfoot dot com
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-30 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-30 10:07:40 UTC ---
Reload doesn't really know how to deal with the register stack.


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

* [Bug target/49583] Reloading stack operands in the wrong order, so needs to insert fxch
  2011-06-29 18:18 [Bug tree-optimization/49583] New: Reloading stack operands in the wrong order, so needs to insert fxch sgunderson at bigfoot dot com
  2011-06-30 10:08 ` [Bug target/49583] " rguenth at gcc dot gnu.org
@ 2011-07-03 14:39 ` ubizjak at gmail dot com
  2011-07-03 17:20 ` sgunderson at bigfoot dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ubizjak at gmail dot com @ 2011-07-03 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

Uros Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #2 from Uros Bizjak <ubizjak at gmail dot com> 2011-07-03 14:38:54 UTC ---
You should use powf instead of pow. Many of these moves are actually
double->float and float->double x87 conversion instructions.

You can use -ffast-math to avoid these conversions, but using powf on float
values is probably what you want.

Other moves are necessary to pass arguments to the function via stack and to
save live values from registers around the call.

Also, don't worry about fxch or two, these are extremely fast instructions.


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

* [Bug target/49583] Reloading stack operands in the wrong order, so needs to insert fxch
  2011-06-29 18:18 [Bug tree-optimization/49583] New: Reloading stack operands in the wrong order, so needs to insert fxch sgunderson at bigfoot dot com
  2011-06-30 10:08 ` [Bug target/49583] " rguenth at gcc dot gnu.org
  2011-07-03 14:39 ` ubizjak at gmail dot com
@ 2011-07-03 17:20 ` sgunderson at bigfoot dot com
  2 siblings, 0 replies; 4+ messages in thread
From: sgunderson at bigfoot dot com @ 2011-07-03 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from sgunderson at bigfoot dot com 2011-07-03 17:20:11 UTC ---
Hi,

My bug report was (as you can see in the title) not about the fstps/fld
sequence; it was about the extraneous fxch instructions. (My original code was
with -ffast-math, but I didn't want to burden the example with too many flags.)

In any case, even if I am to ignore “one or two”, how many fxch are too many? I
can give you can code where there are _five_ (in what is a tight inner loop for
me), just by expanding on the example in question.


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

end of thread, other threads:[~2011-07-03 17:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-29 18:18 [Bug tree-optimization/49583] New: Reloading stack operands in the wrong order, so needs to insert fxch sgunderson at bigfoot dot com
2011-06-30 10:08 ` [Bug target/49583] " rguenth at gcc dot gnu.org
2011-07-03 14:39 ` ubizjak at gmail dot com
2011-07-03 17:20 ` sgunderson at bigfoot 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).