summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/torture/builtin-math-5.c46
-rw-r--r--gcc/testsuite/gcc.dg/torture/builtin-math-6.c151
-rw-r--r--gcc/testsuite/lib/target-supports.exp13
4 files changed, 216 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f1ff5d5c100..2f3cb4ec178 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-15 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * gcc.dg/torture/builtin-math-5.c: New.
+ * gcc.dg/torture/builtin-math-6.c: New.
+ * lib/target-supports.exp (check_effective_target_mpc): New.
+
2009-05-15 Jan Hubicka <jh@suse.cz>
* testsuite/gcc.dg/tree-ssa/inline-3.c: New testcase
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-math-5.c b/gcc/testsuite/gcc.dg/torture/builtin-math-5.c
new file mode 100644
index 00000000000..d266e50aff0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/builtin-math-5.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 2009 Free Software Foundation.
+
+ Test things that should block GCC from optimizing compile-time
+ constants passed to a builtin complex transcendental functions.
+
+ Origin: Kaveh R. Ghazi, January 28, 2009. */
+
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-original" } */
+
+extern void foof (_Complex float);
+extern void foo (_Complex double);
+extern void fool (_Complex long double);
+
+#define TESTIT(FUNC, ARG) do { \
+ foof (__builtin_##FUNC##f (ARG##F)); \
+ foo (__builtin_##FUNC (ARG)); \
+ fool (__builtin_##FUNC##l (ARG##L)); \
+} while (0)
+
+void bar()
+{
+ /* An argument of NaN is not evaluated at compile-time. */
+#ifndef __SPU__
+ foof (__builtin_csqrtf (__builtin_nanf("")));
+#endif
+ foo (__builtin_csqrt (__builtin_nan("")));
+ fool (__builtin_csqrtl (__builtin_nanl("")));
+
+ /* An argument of Inf/-Inf is not evaluated at compile-time. */
+#ifndef __SPU__
+ foof (__builtin_csqrtf (__builtin_inff()));
+#endif
+ foo (__builtin_csqrt (__builtin_inf()));
+ fool (__builtin_csqrtl (__builtin_infl()));
+#ifndef __SPU__
+ foof (__builtin_csqrtf (-__builtin_inff()));
+#endif
+ foo (__builtin_csqrt (-__builtin_inf()));
+ fool (__builtin_csqrtl (-__builtin_infl()));
+}
+
+/* { dg-final { scan-tree-dump-times "csqrtf" 3 "original" } } */
+/* { dg-final { scan-tree-dump-times "csqrt " 3 "original" } } */
+/* { dg-final { scan-tree-dump-times "csqrtl" 3 "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-math-6.c b/gcc/testsuite/gcc.dg/torture/builtin-math-6.c
new file mode 100644
index 00000000000..636381f5f2e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/builtin-math-6.c
@@ -0,0 +1,151 @@
+/* Copyright (C) 2009 Free Software Foundation.
+
+ Verify that folding of built-in complex math functions with
+ constant arguments is correctly performed by the compiler.
+
+ Origin: Kaveh R. Ghazi, January 28, 2009. */
+
+/* { dg-do link } */
+/* { dg-require-effective-target mpc } */
+
+/* All references to link_error should go away at compile-time. */
+extern void link_error(int);
+
+/* Return TRUE if the sign of X != sign of Y. This is important when
+ comparing signed zeros. */
+#define CKSGN_F(X,Y) \
+ (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
+#define CKSGN(X,Y) \
+ (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
+#define CKSGN_L(X,Y) \
+ (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
+
+/* For complex numbers, test that FUNC(ARG) == (RES). */
+#define TESTIT_COMPLEX(FUNC, ARG, RES) do { \
+ if (__builtin_##FUNC##f(ARG) != (RES) \
+ || CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \
+ || CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \
+ link_error(__LINE__); \
+ if (__builtin_##FUNC(ARG) != (RES) \
+ || CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \
+ || CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \
+ link_error(__LINE__); \
+ if (__builtin_##FUNC##l(ARG) != (RES) \
+ || CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \
+ || CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \
+ link_error(__LINE__); \
+ } while (0)
+
+/* Range test, for complex numbers check that FUNC(ARG) is within 1%
+ of RES. This is NOT a test for accuracy to the last-bit, we're
+ merely checking that we get relatively sane results. I.e. the GCC
+ builtin is hooked up to the correct MPC function call. We first
+ check the magnitude and then the sign. */
+#define TESTIT_COMPLEX_R(FUNC, ARG, RES) do { \
+ if (__builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__real__ (RES)) * 0.99F \
+ || __builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__real__ (RES)) * 1.01F \
+ || __builtin_fabsf(__imag__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__imag__ (RES)) * 0.99F \
+ || __builtin_fabsf(__imag__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__imag__ (RES)) * 1.01F \
+ || CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \
+ || CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \
+ link_error(__LINE__); \
+ if (__builtin_fabs(__real__ __builtin_##FUNC(ARG)) < __builtin_fabs(__real__ (RES)) * 0.99F \
+ || __builtin_fabs(__real__ __builtin_##FUNC(ARG)) > __builtin_fabs(__real__ (RES)) * 1.01F \
+ || __builtin_fabs(__imag__ __builtin_##FUNC(ARG)) < __builtin_fabs(__imag__ (RES)) * 0.99F \
+ || __builtin_fabs(__imag__ __builtin_##FUNC(ARG)) > __builtin_fabs(__imag__ (RES)) * 1.01F \
+ || CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \
+ || CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \
+ link_error(__LINE__); \
+ if (__builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__real__ (RES)) * 0.99F \
+ || __builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__real__ (RES)) * 1.01F \
+ || __builtin_fabsl(__imag__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__imag__ (RES)) * 0.99F \
+ || __builtin_fabsl(__imag__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__imag__ (RES)) * 1.01F \
+ || CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \
+ || CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \
+ link_error(__LINE__); \
+ } while (0)
+
+int main (void)
+{
+ TESTIT_COMPLEX (csin, 0.0F, 0.0F);
+ TESTIT_COMPLEX (csin, -0.0F, -0.0F);
+ TESTIT_COMPLEX (csin, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+ TESTIT_COMPLEX (csin, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+ TESTIT_COMPLEX_R (csin, 3.45678F + 2.34567FI, -1.633059F - 4.917448FI);
+ TESTIT_COMPLEX_R (csin, 3.45678F - 2.34567FI, -1.633059F + 4.917448FI);
+ TESTIT_COMPLEX_R (csin, -3.45678F + 2.34567FI, 1.633059F - 4.917448FI);
+ TESTIT_COMPLEX_R (csin, -3.45678F - 2.34567FI, 1.633059F + 4.917448FI);
+
+ TESTIT_COMPLEX (ccos, 0.0F, __builtin_conjf(1.0F));
+ TESTIT_COMPLEX (ccos, -0.0F, 1.0F);
+ TESTIT_COMPLEX (ccos, __builtin_conjf(0.0F), 1.0F);
+ TESTIT_COMPLEX (ccos, __builtin_conjf(-0.0F), __builtin_conjf(1.0F));
+
+ TESTIT_COMPLEX_R (ccos, 3.45678F + 2.34567FI, -5.008512F + 1.603367FI);
+ TESTIT_COMPLEX_R (ccos, 3.45678F - 2.34567FI, -5.008512F - 1.603367FI);
+ TESTIT_COMPLEX_R (ccos, -3.45678F + 2.34567FI, -5.008512F - 1.603367FI);
+ TESTIT_COMPLEX_R (ccos, -3.45678F - 2.34567FI, -5.008512F + 1.603367FI);
+
+ TESTIT_COMPLEX (ctan, 0.0F, 0.0F);
+ TESTIT_COMPLEX (ctan, -0.0F, -0.0F);
+ TESTIT_COMPLEX (ctan, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+ TESTIT_COMPLEX (ctan, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+ TESTIT_COMPLEX_R (ctan, 3.45678F + 2.34567FI, 0.010657F + 0.985230FI);
+ TESTIT_COMPLEX_R (ctan, 3.45678F - 2.34567FI, 0.010657F - 0.985230FI);
+ TESTIT_COMPLEX_R (ctan, -3.45678F + 2.34567FI, -0.010657F + 0.985230FI);
+ TESTIT_COMPLEX_R (ctan, -3.45678F - 2.34567FI, -0.010657F - 0.985230FI);
+
+ TESTIT_COMPLEX (csinh, 0.0F, 0.0F);
+ TESTIT_COMPLEX (csinh, -0.0F, -0.0F);
+ TESTIT_COMPLEX (csinh, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+ TESTIT_COMPLEX (csinh, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+ TESTIT_COMPLEX_R (csinh, 3.45678F + 2.34567FI, -11.083178F + 11.341487FI);
+ TESTIT_COMPLEX_R (csinh, 3.45678F - 2.34567FI, -11.083178F - 11.341487FI);
+ TESTIT_COMPLEX_R (csinh, -3.45678F + 2.34567FI, 11.083178F + 11.341487FI);
+ TESTIT_COMPLEX_R (csinh, -3.45678F - 2.34567FI, 11.083178F - 11.341487FI);
+
+ TESTIT_COMPLEX (ccosh, 0.0F, 1.0F);
+ TESTIT_COMPLEX (ccosh, -0.0F, __builtin_conjf(1.0F));
+ TESTIT_COMPLEX (ccosh, __builtin_conjf(0.0F), __builtin_conjf(1.0F));
+ TESTIT_COMPLEX (ccosh, __builtin_conjf(-0.0F), 1.0F);
+
+ TESTIT_COMPLEX_R (ccosh, 3.45678F + 2.34567FI, -11.105238F + 11.318958FI);
+ TESTIT_COMPLEX_R (ccosh, 3.45678F - 2.34567FI, -11.105238F - 11.318958FI);
+ TESTIT_COMPLEX_R (ccosh, -3.45678F + 2.34567FI, -11.105238F - 11.318958FI);
+ TESTIT_COMPLEX_R (ccosh, -3.45678F - 2.34567FI, -11.105238F + 11.318958FI);
+
+ TESTIT_COMPLEX (ctanh, 0.0F, 0.0F);
+ TESTIT_COMPLEX (ctanh, -0.0F, -0.0F);
+ TESTIT_COMPLEX (ctanh, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+ TESTIT_COMPLEX (ctanh, __builtin_conjf(-0.0F), __builtin_conjf(-0.0F));
+
+ TESTIT_COMPLEX_R (ctanh, 3.45678F + 2.34567FI, 1.000040F - 0.001988FI);
+ TESTIT_COMPLEX_R (ctanh, 3.45678F - 2.34567FI, 1.000040F + 0.001988FI);
+ TESTIT_COMPLEX_R (ctanh, -3.45678F + 2.34567FI, -1.000040F - 0.001988FI);
+ TESTIT_COMPLEX_R (ctanh, -3.45678F - 2.34567FI, -1.000040F + 0.001988FI);
+
+ TESTIT_COMPLEX (clog, 1.0F, 0.0F);
+ TESTIT_COMPLEX_R (clog, -1.0F, 3.141593FI);
+ TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), 0.0F);
+ TESTIT_COMPLEX_R (clog, __builtin_conjf(-1.0F), 3.141593FI);
+
+ TESTIT_COMPLEX_R (clog, 3.45678F + 2.34567FI, 1.429713F + 0.596199FI);
+ TESTIT_COMPLEX_R (clog, 3.45678F - 2.34567FI, 1.429713F - 0.596199FI);
+ TESTIT_COMPLEX_R (clog, -3.45678F + 2.34567FI, 1.429713F + 2.545394FI);
+ TESTIT_COMPLEX_R (clog, -3.45678F - 2.34567FI, 1.429713F - 2.545394FI);
+
+ TESTIT_COMPLEX (csqrt, 0.0F, 0.0F);
+ TESTIT_COMPLEX (csqrt, -0.0F, 0.0F);
+ TESTIT_COMPLEX (csqrt, __builtin_conjf(0.0F), __builtin_conjf(0.0F));
+ TESTIT_COMPLEX (csqrt, __builtin_conjf(-0.0F), __builtin_conjf(0.0F));
+
+ TESTIT_COMPLEX_R (csqrt, 3.45678F + 2.34567FI, 1.953750F + 0.600299FI);
+ TESTIT_COMPLEX_R (csqrt, 3.45678F - 2.34567FI, 1.953750F - 0.600299FI);
+ TESTIT_COMPLEX_R (csqrt, -3.45678F + 2.34567FI, 0.600299F + 1.953750FI);
+ TESTIT_COMPLEX_R (csqrt, -3.45678F - 2.34567FI, 0.600299F - 1.953750FI);
+
+ return 0;
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 56f7877dd18..3282d6d7b48 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2930,3 +2930,16 @@ proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
#endif
}]
}
+
+# Return 1 if the MPC library is integrated with GCC, 0 otherwise.
+
+proc check_effective_target_mpc { } {
+ return [check_no_compiler_messages mpc executable {
+ extern void link_error(void);
+ int main ()
+ {
+ if (__builtin_csin(0) != 0)
+ link_error();
+ }
+ }]
+}