Bug 19775 - [3.4/4.0 regression] sqrt(pow(x,y)) != pow(x,y*0.5) (with -ffast-math)
Summary: [3.4/4.0 regression] sqrt(pow(x,y)) != pow(x,y*0.5) (with -ffast-math)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.4.4
: P1 normal
Target Milestone: 3.4.4
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-02-03 09:28 UTC by Richard Biener
Modified: 2005-02-07 13:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.5
Known to fail: 3.4.4 4.0.0
Last reconfirmed: 2005-02-03 15:15:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2005-02-03 09:28:52 UTC
This one should not abort:

#include <math.h>
#include <stdlib.h>

int main()
{
        double x = -1.0;
        if (sqrt(pow(x,2)) != 1.0)
                abort();
        return 0;
}

but both, 3.4.4 and 4.0.0 do sqrt(pow(x,y)) -> pow(x,y*0.5)
which in this case means sqrt(1.0) -> -1.0.

Ouch.
Comment 1 Andrew Pinski 2005-02-03 15:14:59 UTC
Confirmed but you forgot the most important thing (even though you did say this on the mailing lists), 
the options you used to reproduce the failure.

 -funsafe-math-optimizations is needed to reproduce this.
Comment 2 GCC Commits 2005-02-03 17:47:48 UTC
Subject: Bug 19775

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rguenth@gcc.gnu.org	2005-02-03 17:47:33

Modified files:
	gcc            : ChangeLog builtins.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: builtins-10.c 
Added files:
	gcc/testsuite/gcc.dg: builtins-47.c 

Log message:
	PR middle-end/19775
	
	* builtins.c (fold_builtin_sqrt): Transform sqrt(pow(x,y))
	to pow(fabs(x),y*0.5), not pow(x,y*0.5).
	
	* gcc.dg/builtins-10.c: Disable test for invalid transformation
	and one test we no longer optimize.
	* gcc.dg/builtins-47.c: New testcase.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.791&r2=2.2326.2.792
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.275.2.5&r2=1.275.2.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.355&r2=1.3389.2.356
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/builtins-47.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/builtins-10.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1&r2=1.1.22.1

Comment 3 GCC Commits 2005-02-07 13:24:46 UTC
Subject: Bug 19775

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rguenth@gcc.gnu.org	2005-02-07 13:24:38

Modified files:
	gcc            : ChangeLog builtins.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg/torture: builtin-power-1.c 
	gcc/testsuite/gcc.dg: builtins-10.c 
Added files:
	gcc/testsuite/gcc.dg: builtins-47.c 

Log message:
	2005-02-07  Richard Guenther  <rguenth@gcc.gnu.org>
	
	PR middle-end/19775
	* builtins.c (fold_builtin_sqrt): Transform
	sqrt(pow(x,y)) to pow(fabs(x),y*0.5), not
	pow(x,y*0.5).
	
	* gcc.dg/torture/builtin-power-1.c: Disable test for
	invalid transformation.
	* gcc.dg/builtins-10.c: Likewise.  Disable one test we
	no longer optimize.
	* gcc.dg/builtins-47.c: New testcase.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7408&r2=2.7409
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&r1=1.415&r2=1.416
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4998&r2=1.4999
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/torture/builtin-power-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/builtins-47.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/builtins-10.c.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 4 Richard Biener 2005-02-07 13:25:55 UTC
Fixed.