Bug 15134 - incorrect -ffast-math division simplification
Summary: incorrect -ffast-math division simplification
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-25 16:42 UTC by Laurent GUERBY
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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