summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/builtins-27.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-01 00:36:53 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-01 00:36:53 +0000
commit8c5cac787cdc66bd8a9ada6ed38c8093500e9106 (patch)
treea842e3f3e11953156cef321cf6510aeed77635b1 /gcc/testsuite/gcc.dg/builtins-27.c
parentc787204033c5fce87bbf38dd45561974f8cfab9c (diff)
downloadgcc-8c5cac787cdc66bd8a9ada6ed38c8093500e9106.tar.gz
* fold-const.c (fold <MULT_EXPR>): Optimize both x*pow(x,c) and
pow(x,c)*x as pow(x,c+1) for constant values c. Optimize x*x as pow(x,2.0) when the latter will be expanded back into x*x. (fold <RDIV_EXPR>): Optimize pow(x,c)/x as pow(x,c-1). * builtins.c (expand_builtin_pow): Ignore flag_errno_math as pow can never set errno when used with an integer exponent. Always use expand_powi when exponent is -1, 0, 1 or 2. (fold_builtin): Don't rewrite pow(x,2.0) as x*x nor pow(x,-2.0) as 1.0/(x*x). This avoids unbounded recursion as we now prefer the pow forms of these expressions. * gcc.dg/builtins-27.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70030 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/builtins-27.c')
-rw-r--r--gcc/testsuite/gcc.dg/builtins-27.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/builtins-27.c b/gcc/testsuite/gcc.dg/builtins-27.c
new file mode 100644
index 00000000000..69d8f994481
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtins-27.c
@@ -0,0 +1,47 @@
+/* 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, 29th July 2003. */
+
+/* { dg-do link } */
+/* { dg-options "-O2 -ffast-math" } */
+
+extern void link_error(void);
+
+extern double pow(double,double);
+
+void test(double x)
+{
+ if (pow(x,2.0) != x*x)
+ link_error ();
+
+ if (x*pow(x,2.0) != pow(x,3.0))
+ link_error ();
+
+ if (pow(x,2.0)*x != pow(x,3.0))
+ link_error ();
+
+ if (pow(x,3.0) != x*x*x)
+ link_error ();
+
+ if (pow(x,2.0)*x != x*x*x)
+ link_error ();
+
+ if (x*pow(x,2.0) != x*x*x)
+ link_error ();
+
+ if (pow(x,3.0)/x != pow(x,2.0))
+ link_error ();
+
+ if (pow(x,3.0)/x != x*x)
+ link_error ();
+}
+
+int main()
+{
+ test (2.0);
+ return 0;
+}
+