summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/builtins-10.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-08 23:24:38 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-08 23:24:38 +0000
commit2643011aed8692ce128b0bc8f78ad03d1a5661d3 (patch)
tree57e664d9c1807ff9f4b3bd4f3e4ddbb0c32619d0 /gcc/testsuite/gcc.dg/builtins-10.c
parent38c416603c656090e4f9a69b0a1450728aa247b8 (diff)
downloadgcc-2643011aed8692ce128b0bc8f78ad03d1a5661d3.tar.gz
* builtins.c (fold_builtin): Constant fold expressions as x*0.5
instead of x/2.0. Optimize sqrt(pow(x,y)) as pow(x,y*0.5), log(pow(x,y)) as y*log(x), pow(exp(x),y) as exp(x*y), pow(sqrt(x),y) as pow(x,y*0.5) and pow(pow(x,y),z) as pow(x,y*z). Delete function scope "fcode" variable to avoid shadowing. * gcc.dg/builtins-9.c: New test case. * gcc.dg/builtins-10.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65386 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/builtins-10.c')
-rw-r--r--gcc/testsuite/gcc.dg/builtins-10.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/builtins-10.c b/gcc/testsuite/gcc.dg/builtins-10.c
new file mode 100644
index 00000000000..9e5a4583fc3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtins-10.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2003 Free Software Foundation.
+
+ Check that constant folding of built-in math functions doesn't
+ break anything and produces the expected results.
+
+ Written by Roger Sayle, 2nd April 2003. */
+
+/* { dg-do link } */
+/* { dg-options "-O2 -ffast-math" } */
+
+extern void link_error(void);
+
+extern double exp(double);
+extern double log(double);
+extern double sqrt(double);
+extern double pow(double,double);
+
+void test(double x)
+{
+ if (sqrt(pow(x,4.0)) != x*x)
+ link_error ();
+
+ if (pow(sqrt(x),4.0) != x*x)
+ link_error ();
+
+ if (pow(pow(x,4.0),0.25) != x)
+ link_error ();
+}
+
+void test2(double x, double y, double z)
+{
+ if (sqrt(pow(x,y)) != pow(x,y*0.5))
+ link_error ();
+
+ if (log(pow(x,y)) != y*log(x))
+ link_error ();
+
+ if (pow(exp(x),y) != exp(x*y))
+ link_error ();
+
+ if (pow(sqrt(x),y) != pow(x,y*0.5))
+ link_error ();
+
+ if (pow(pow(x,y),z) != pow(x,y*z))
+ link_error ();
+}
+
+int main()
+{
+ test (2.0);
+ test2 (2.0, 3.0, 4.0);
+ return 0;
+}
+