Bug 15134

Summary: incorrect -ffast-math division simplification
Product: gcc Reporter: Laurent GUERBY <laurent>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs, laurent
Priority: P2    
Version: 4.0.0   
Target Milestone: ---   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed:

Description Laurent GUERBY 2004-04-25 16:42:12 UTC
The following trivial program fails with "-O1 -ffast-math" whereas
it works without -ffast-math. This comes from ACATS.

$ gnatmake -f -O1 -ffast-math c34003a
gcc -c -O1 -ffast-math c34003a.adb
gnatbind -x c34003a.ali
gnatlink c34003a.ali -ffast-math
$ ./c34003a
raised PROGRAM_ERROR : c34003a.adb:5 explicit raise
$ cat c34003a.adb
PROCEDURE C34003A IS
     procedure Do_Fail is
     begin
	raise Program_Error;
     end Do_Fail;
   
     X : Float        := 30.0;
BEGIN
     IF 90.0 / X /= 3.0 THEN
          Do_Fail;
     END IF;
END C34003A;
Comment 1 Andrew Pinski 2004-04-25 16:55:37 UTC
Simple C testcase:
float x = 30.0;

int main()
{
  if ( 90.0/x != 3.0)
    abort();
  return 0;
}

It works on PPC but not on i686 so this is a dup of bug 323 and invalid.

*** This bug has been marked as a duplicate of 323 ***
Comment 2 Andrew Pinski 2004-04-25 17:14:31 UTC
Note what -ffast-math does is converts:
90.0/x into 1/x *90.0, so there is a precision loss which causes 1./0f/30.0 * 90.0 != 3.0.  So this is still 
invalid.
Comment 3 Laurent GUERBY 2004-04-25 17:19:01 UTC
Ok I see, but then it's not really a dup of 323 which has
an incorrect program, here the program is correct and just broken
when we allow unsafe math optimizations :)

Laurent