This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/21067] New: Excessive optimization of floating point expression


Compiling the following with GCC 3.4.3 (with "gcc -O2 -S file.c")

float mul2(float a, float b) {
  float v = -a * b;
  return -v;
}

produce the erroneous code

	pushl	%ebp
	movl	%esp, %ebp
	flds	8(%ebp)
	fmuls	12(%ebp)
	popl	%ebp
	ret

where the sign changes have been erroneously elided.
Notice that, depending on the rounding mode in effect,
this produces the wrong results.

Strangely enough, the code produced for

float div2(float a, float b) {
  float v = -a / b;
  return -v;
}

is instead correct.

-- 
           Summary: Excessive optimization of floating point expression
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        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=21067


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]