This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Split gcc.dg/builtins-20.c


My recent test case builtins-20.c is currently failing on sh-elf
and presumably several other non-linux platforms (thanks to Joern
Rennecke for bringing this to my attention).  The problem is that
this optimization/test case attempt to synthesize the use of a
C99 function that isn't guaranteed to be available on all platforms.

So although "sin(x)/cos(x) != tan(x)" should work everywhere, the
optimizer will only convert "sinf(x)/cosf(x)" into tanf(x) on platforms
where it is known this function will be present.  So this testcase
has been failing on those platforms where GCC can't guarantee a c99
library.

The following patch splits the original testcase gcc.dg/builtins-20.c
into two parts.  One test program for double functions that only
requires c90 functionality remains in builtins-20.c, and a second
test program builtins-22.c that contains the float and long double
tests, which is only executed on *-*-linux*.


[In practice, the test2f and test2l optimizations will be applied
everywhere, but the split below is much cleaner conceptually.]

Ok for mainline?


2003-06-13  Roger Sayle  <roger@eyesopen.com>

	* gcc.dg/builtins-20.c: Split c99 hosts out from here...
	* gcc.dg/builtins-22.c: ... to here.  New test case only tested
	on *-*-linux* targets known to have c99 library functions.


Index: builtins-20.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/builtins-20.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 builtins-20.c
*** builtins-20.c	10 Jun 2003 13:05:54 -0000	1.1
--- builtins-20.c	14 Jun 2003 03:27:31 -0000
*************** void test2(double x, double y)
*** 37,107 ****
      link_error ();
  }

- void test1f(float x)
- {
-   if (cosf(x) != cosf(-x))
-     link_error ();
-
-   if (sinf(x)/cosf(x) != tanf(x))
-     link_error ();
-
-   if (cosf(x)/sinf(x) != 1.0f/tanf(x))
-     link_error ();
-
-   if (tanf(x)*cosf(x) != sinf(x))
-     link_error ();
-
-   if (cosf(x)*tanf(x) != sinf(x))
-     link_error ();
- }
-
- void test2f(float x, float y)
- {
-   if (-tanf(x-y) != tanf(y-x))
-     link_error ();
-
-   if (-sinf(x-y) != sinf(y-x))
-     link_error ();
- }
-
-
- void test1l(long double x)
- {
-   if (cosl(x) != cosl(-x))
-     link_error ();
-
-   if (sinl(x)/cosl(x) != tanl(x))
-     link_error ();
-
-   if (cosl(x)/sinl(x) != 1.0l/tanl(x))
-     link_error ();
-
-   if (tanl(x)*cosl(x) != sinl(x))
-     link_error ();
-
-   if (cosl(x)*tanl(x) != sinl(x))
-     link_error ();
- }
-
- void test2l(long double x, long double y)
- {
-   if (-tanl(x-y) != tanl(y-x))
-     link_error ();
-
-   if (-sinl(x-y) != sinl(y-x))
-     link_error ();
- }
-
  int main()
  {
    test1 (1.0);
    test2 (1.0, 2.0);
-
-   test1f (1.0f);
-   test2f (1.0f, 2.0f);
-
-   test1l (1.0l);
-   test2l (1.0l, 2.0l);

    return 0;
  }
--- 37,46 ----


/* Copyright (C) 2003  Free Software Foundation.

   Verify that built-in math function constant folding doesn't break
   anything and produces the expected results.

   Written by Roger Sayle, 13th June 2003.  */

/* { dg-do link { target *-*-linux* } } */
/* { dg-options "-O2 -ffast-math" } */

extern void link_error(void);

void test1f(float x)
{
  if (cosf(x) != cosf(-x))
    link_error ();

  if (sinf(x)/cosf(x) != tanf(x))
    link_error ();

  if (cosf(x)/sinf(x) != 1.0f/tanf(x))
    link_error ();

  if (tanf(x)*cosf(x) != sinf(x))
    link_error ();

  if (cosf(x)*tanf(x) != sinf(x))
    link_error ();
}

void test2f(float x, float y)
{
  if (-tanf(x-y) != tanf(y-x))
    link_error ();

  if (-sinf(x-y) != sinf(y-x))
    link_error ();
}


void test1l(long double x)
{
  if (cosl(x) != cosl(-x))
    link_error ();

  if (sinl(x)/cosl(x) != tanl(x))
    link_error ();

  if (cosl(x)/sinl(x) != 1.0l/tanl(x))
    link_error ();

  if (tanl(x)*cosl(x) != sinl(x))
    link_error ();

  if (cosl(x)*tanl(x) != sinl(x))
    link_error ();
}

void test2l(long double x, long double y)
{
  if (-tanl(x-y) != tanl(y-x))
    link_error ();

  if (-sinl(x-y) != sinl(y-x))
    link_error ();
}

int main()
{
  test1f (1.0f);
  test2f (1.0f, 2.0f);

  test1l (1.0l);
  test2l (1.0l, 2.0l);

  return 0;
}


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]