public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations
@ 2005-04-14 21:52 bagnara at cs dot unipr dot it
  2005-04-14 22:01 ` [Bug middle-end/21032] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: bagnara at cs dot unipr dot it @ 2005-04-14 21:52 UTC (permalink / raw)
  To: gcc-bugs

If you compile the function

void assign2(float* a, double b) {
  volatile float v = -b;
  *a = -v;
}

you will see that GCC 3.4.3, e.g., at -O2, produces

        fldl    12(%ebp)
        fstps   -20(%ebp)
        movl    8(%ebp), %eax
        flds    -20(%ebp)
        fchs
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fchs
        fstps   (%eax)

where the first sign change is performed /after/ reducing the
precision and not /before/, as I believe it should (according
to ISO/IEC 9899, 5.1.2.3#13, 6.3.1.5#2 and 6.3.1.8#2).
The produced code seems also very badly optimized, considering
that something like

	fldl	12(%ebp)
	fchs
	fstps	-4(%ebp)
	flds	-4(%ebp)
	fchs
	fstps	(%eax)

would be significantly more efficient (besides being correct).
The same problem can be seen with gcc-4.0.0 20050406 (Fedora Core 3).

    Roberto Bagnara

-- 
           Summary: GCC 3.4.3 wrongly reorders floating-point operations
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bagnara at cs dot unipr dot it
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
  2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
@ 2005-04-14 22:01 ` pinskia at gcc dot gnu dot org
  2005-04-15  7:01 ` bagnara at cs dot unipr dot it
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-14 22:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-14 22:01 -------
Note neg just flips a bit so it is correct anyways and there is no loss of precession.

This also happens on ppc darwin, I don't know what to make of this.  A C person has to comment to say 
something about this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
  2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
  2005-04-14 22:01 ` [Bug middle-end/21032] " pinskia at gcc dot gnu dot org
@ 2005-04-15  7:01 ` bagnara at cs dot unipr dot it
  2005-04-16 12:27 ` bagnara at cs dot unipr dot it
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: bagnara at cs dot unipr dot it @ 2005-04-15  7:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bagnara at cs dot unipr dot it  2005-04-15 07:01 -------
Subject: Re:  GCC 3.4.3 wrongly reorders floating-point
 operations

pinskia at gcc dot gnu dot org wrote:
> Note neg just flips a bit so it is correct anyways
 > and there is no loss of precession.

Can you please clarify what do you mean by "correct"?
I believe that:

1) The produced code is incorrect, since operations cannot
    be reordered that way.  Notice that the compiler cannot
    prove that the result is the same (in fact it is not,
    in general, as it depends on the rounding direction).

2) A piece of standard C that, when correctly compiled,
    performs a double to float conversion rounding up, when
    the rounding mode is downward, or rounding down, when
    the rounding mode is upward, no longer works when
    compiled with GCC.  So the produced code is incorrect
    not only from a language-lawyer point of view: I am
    actually obtaining the wrong results.

All the best,

     Roberto Bagnara



-- 


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
  2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
  2005-04-14 22:01 ` [Bug middle-end/21032] " pinskia at gcc dot gnu dot org
  2005-04-15  7:01 ` bagnara at cs dot unipr dot it
@ 2005-04-16 12:27 ` bagnara at cs dot unipr dot it
  2005-06-15 16:49 ` vincent at vinc17 dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: bagnara at cs dot unipr dot it @ 2005-04-16 12:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bagnara at cs dot unipr dot it  2005-04-16 12:27 -------
I can add the following:

1) the bug was not present in GCC 3.3.3 and is present since version 3.4.0, so I
think it qualifies as a regression;

2) the bug is also present in GCC 4.0.0 20050226 (prerelease), which compiles
the code even worse than done by GCC 3.4.3 (for whatever optimization level and
-march option one gives).

-- 


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
  2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
                   ` (2 preceding siblings ...)
  2005-04-16 12:27 ` bagnara at cs dot unipr dot it
@ 2005-06-15 16:49 ` vincent at vinc17 dot org
  2005-06-15 17:08 ` vincent at vinc17 dot org
  2005-06-15 17:27 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 9+ messages in thread
From: vincent at vinc17 dot org @ 2005-06-15 16:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vincent at vinc17 dot org  2005-06-15 16:49 -------
I think that this is just bug 323 (which is a real bug, not invalid). Version
3.4 added other regressions related to this bug (e.g. when one has function
calls), and this is not specific to the negate operation.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vincent at vinc17 dot org


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
  2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
                   ` (3 preceding siblings ...)
  2005-06-15 16:49 ` vincent at vinc17 dot org
@ 2005-06-15 17:08 ` vincent at vinc17 dot org
  2005-06-15 17:27 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 9+ messages in thread
From: vincent at vinc17 dot org @ 2005-06-15 17:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vincent at vinc17 dot org  2005-06-15 17:08 -------
Oops, forget my comment. There is a bug, but 5.1.2.3#13 / 6.3.1.5#2 / 6.3.1.8#2
is not related to it if gcc does reduce the precision (due to the "volatile",
that in fact prevents bug 323 from occurring here, right?).

Well, if gcc assumes more or less that all the types have the same range and
precision when doing optimization, then this could indeed be seen as bug 323. It
would be interesting to know how gcc deduced (wrongly) that it could do the
change concerning the neg.

-- 


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
  2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
                   ` (4 preceding siblings ...)
  2005-06-15 17:08 ` vincent at vinc17 dot org
@ 2005-06-15 17:27 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-15 17:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-15 17:26 -------
This is unrelated to 323.  The problem is that GCC does not implement a rounding modes correctly for 
C99 and therefor defines it as aways "normal" rounding mode and implements this transformation.

-- 


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
       [not found] <bug-21032-1710@http.gcc.gnu.org/bugzilla/>
  2005-12-20  7:49 ` bagnara at cs dot unipr dot it
@ 2006-10-21 20:17 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-21 20:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2006-10-21 20:17 -------
*** Bug 29538 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |guillaume dot melquiond at
                   |                            |ens-lyon dot fr


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


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

* [Bug middle-end/21032] GCC 3.4.3 wrongly reorders floating-point operations
       [not found] <bug-21032-1710@http.gcc.gnu.org/bugzilla/>
@ 2005-12-20  7:49 ` bagnara at cs dot unipr dot it
  2006-10-21 20:17 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 9+ messages in thread
From: bagnara at cs dot unipr dot it @ 2005-12-20  7:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from bagnara at cs dot unipr dot it  2005-12-20 07:49 -------
I can confirm both problems (incorrect reordering and performance regression)
are present in GCC version 4.0.2 and version 4.2.0 20051209 (experimental).


-- 


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


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

end of thread, other threads:[~2006-10-21 20:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 21:52 [Bug c/21032] New: GCC 3.4.3 wrongly reorders floating-point operations bagnara at cs dot unipr dot it
2005-04-14 22:01 ` [Bug middle-end/21032] " pinskia at gcc dot gnu dot org
2005-04-15  7:01 ` bagnara at cs dot unipr dot it
2005-04-16 12:27 ` bagnara at cs dot unipr dot it
2005-06-15 16:49 ` vincent at vinc17 dot org
2005-06-15 17:08 ` vincent at vinc17 dot org
2005-06-15 17:27 ` pinskia at gcc dot gnu dot org
     [not found] <bug-21032-1710@http.gcc.gnu.org/bugzilla/>
2005-12-20  7:49 ` bagnara at cs dot unipr dot it
2006-10-21 20:17 ` pinskia at gcc dot gnu dot 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).