diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-08-14 16:44:36 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-08-14 16:44:36 +0000 |
commit | 63e8969836b3c9a5e0c843659bfcae2969218999 (patch) | |
tree | d56a6176a6e43d637f2ab3512ce5fd889d048d90 | |
parent | c937fbeaac7bffbf2f303022c416c8e0b63697fa (diff) | |
download | gcc-63e8969836b3c9a5e0c843659bfcae2969218999.tar.gz |
PR middle-end/30789
* builtins.c (do_mpc_arg2): Make extern, define for any MPC
version. Move declaration...
* real.h (do_mpc_arg2): ... here.
* fold-const.c (const_binop): Use MPC for complex MULT_EXPR
and RDIV_EXPR.
testsuite:
* gcc.dg/torture/builtin-math-7.c: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@150760 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/builtins.c | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 10 | ||||
-rw-r--r-- | gcc/real.h | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/builtin-math-7.c | 74 |
6 files changed, 103 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 207b1a6ccb0..f9b03235531 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2009-08-14 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + PR middle-end/30789 + + * builtins.c (do_mpc_arg2): Make extern, define for any MPC + version. Move declaration... + * real.h (do_mpc_arg2): ... here. + * fold-const.c (const_binop): Use MPC for complex MULT_EXPR + and RDIV_EXPR. + 2009-08-14 Rafael Avila de Espindola <espindola@google.com> * final.c (add_debug_prefix_map): Don't use GC memory for diff --git a/gcc/builtins.c b/gcc/builtins.c index 1349c33a128..025c1694e4c 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -60,9 +60,6 @@ along with GCC; see the file COPYING3. If not see #endif #ifdef HAVE_mpc static tree do_mpc_arg1 (tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_rnd_t)); -#ifdef HAVE_mpc_pow -static tree do_mpc_arg2 (tree, tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t)); -#endif #endif /* Define the names of the builtin function types and codes. */ @@ -13824,8 +13821,8 @@ do_mpc_arg1 (tree arg, tree type, int (*func)(mpc_ptr, mpc_srcptr, mpc_rnd_t)) TYPE. We assume that function FUNC returns zero if the result could be calculated exactly within the requested precision. */ -#ifdef HAVE_mpc_pow -static tree +#ifdef HAVE_mpc +tree do_mpc_arg2 (tree arg0, tree arg1, tree type, int (*func)(mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t)) { diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 803c7a549af..342e3760bdf 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -1972,6 +1972,11 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc) break; case MULT_EXPR: +#ifdef HAVE_mpc + if (COMPLEX_FLOAT_TYPE_P (type)) + return do_mpc_arg2 (arg1, arg2, type, mpc_mul); +#endif + real = const_binop (MINUS_EXPR, const_binop (MULT_EXPR, r1, r2, notrunc), const_binop (MULT_EXPR, i1, i2, notrunc), @@ -1983,6 +1988,11 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc) break; case RDIV_EXPR: +#ifdef HAVE_mpc + if (COMPLEX_FLOAT_TYPE_P (type)) + return do_mpc_arg2 (arg1, arg2, type, mpc_div); +#endif + { tree magsquared = const_binop (PLUS_EXPR, diff --git a/gcc/real.h b/gcc/real.h index 884a663c83f..c93435b2524 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -26,6 +26,9 @@ #include <mpfr.h> #ifdef HAVE_mpc #include <mpc.h> +# ifdef HAVE_mpc +extern tree do_mpc_arg2 (tree, tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t)); +# endif # if MPC_VERSION >= MPC_VERSION_NUM(0,6,1) # define HAVE_mpc_pow # endif diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 765ae6354cc..3ee655b45cf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-08-14 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * gcc.dg/torture/builtin-math-7.c: New. + 2009-08-14 Richard Guenther <rguenther@suse.de> * gcc.c-torture/execute/20090814-1.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/torture/builtin-math-7.c b/gcc/testsuite/gcc.dg/torture/builtin-math-7.c new file mode 100644 index 00000000000..37be4838005 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/builtin-math-7.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2009 Free Software Foundation. + + Verify that folding of complex mul and div work correctly. + + Origin: Kaveh R. Ghazi, August 13, 2009. */ + +/* { dg-do run } */ +/* { dg-require-effective-target mpc } */ + +extern void link_error(int); + +/* Evaluate this expression at compile-time. */ +#define COMPILETIME_TESTIT(TYPE,X,OP,Y,RES) do { \ + if ((_Complex TYPE)(X) OP (_Complex TYPE)(Y) != (_Complex TYPE)(RES)) \ + link_error(__LINE__); \ +} while (0) + +/* Evaluate this expression at runtime. */ +#define RUNTIME_TESTIT(TYPE,X,OP,Y,RES) do { \ + volatile _Complex TYPE foo = (_Complex TYPE)(X); \ + foo OP##= (_Complex TYPE)(Y); \ + if (foo != (_Complex TYPE)(RES)) __builtin_abort(); \ +} while (0) + +/* Evaluate this expression at compile-time and runtime. */ +#define TESTIT(TYPE,X,OP,Y,RES) do { \ + COMPILETIME_TESTIT(TYPE,X,OP,Y,RES); \ + RUNTIME_TESTIT(TYPE,X,OP,Y,RES); \ +} while (0) + +/* Either the real or imaginary parts should be infinity. */ +#define TEST_ONE_PART_INF(VAL) do { \ + if (! __builtin_isinf(__real (VAL)) \ + && ! __builtin_isinf(__imag (VAL))) \ + __builtin_abort(); \ +} while (0) + +int main() +{ + /* Test some regular finite values. */ + TESTIT (double, 3.+4.i, *, 2, 6+8i); + TESTIT (double, 3.+4.i, /, 2, 1.5+2i); + TESTIT (int, 3+4i, *, 2, 6+8i); + RUNTIME_TESTIT (int, 3+4i, /, 2, 1+2i); + + TESTIT (double, 3.+4.i, *, 2+5i, -14+23i); + TESTIT (double, 3.+4.i, /, 5i, .8-.6i); + TESTIT (int, 3+4i, *, 2+5i, -14+23i); + RUNTIME_TESTIT (int, 30+40i, /, 5i, 8-6i); + + /* Test that we don't overflow. */ + TESTIT (double, + (__DBL_MAX__ * 0.5 + __DBL_MAX__ * 0.5i), + /, + (__DBL_MAX__ * 0.25 + __DBL_MAX__ * 0.25i), + 2); + + /* Test for accuracy. */ + COMPILETIME_TESTIT (double, + (1 + __DBL_EPSILON__ + 1i), + *, + (1 - __DBL_EPSILON__ + 1i), + -4.93038065763132378382330353301741393545754021943139377981e-32+2i); + + /* This becomes (NaN + iInf). */ +#define VAL1 ((_Complex double)__builtin_inf() * 1i) + + /* Test some C99 Annex G special cases. */ + TEST_ONE_PART_INF ((VAL1) * (VAL1)); + TEST_ONE_PART_INF ((_Complex double)1 / (_Complex double)0); + TEST_ONE_PART_INF ((VAL1) / (_Complex double)1); + + return 0; +} |