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]

Re: [PATCH] Recognize sqrt(1.0/x) as rsqrt.d on MIPS4


On Tue, 10 Aug 2004, Richard Sandiford wrote:
> > On balance, I think this patch (and its three new test cases)
>
> This probably shows I've not been paying attention, but which new test
> cases do you mean?  The MIPS patch itself didn't have any.

My apologies I was getting ahead of myself.  Eric requested that in
addition to my checking by hand, that I add a new testcase to the gcc
testsuite.  Indeed, I discovered that there are currently no tests
for the use of MIPS's rsqrt patterns, and the middle-end could have
changed the canonical form, invalidating the current mips.md patterns,
without causing any testsuite regressions.

I decided to add tests for both 1.0/sqrt(x) [and its float equivalent],
sqrt(1.0/x) [and its float equivalent], and a third test to check that
we don't emit an rsqrt instruction for any of these cases if the user
hasn't specified -ffast-math.  This checks that the existing uses of
flag_unsafe_math_optimization in mips.md (that you're rightly concerned
about) are functioning correctly.

I was about to commit my patch and these new testcases to mainline CVS
upon Eric's approval when I read your e-mail.  I didn't want to proceed
until I was sure that you weren't unhappy with the situation.


For the record, here are the new tests that I've just committed to CVS
along with the patch.  These tests were checked on mips-sgi-irix6.5 with a
"make check-gcc" in the tree used for testing the patch.  Hopefully, these
should ensure the expected behaviour when and if the middle-end switches
to a canonical form.

Thanks again,



2004-08-10  Roger Sayle  <roger@eyesopen.com>

        * config/mips/mips.md: New reciprocal square root patterns that
        match sqrt(1.0/x) in addition to the existing 1.0/sqrt(x) insns.

        * gcc.dg/mips-rsqrt-1.c: New test case.
        * gcc.dg/mips-rsqrt-2.c: New test case.
        * gcc.dg/mips-rsqrt-3.c: New test case.



/* { dg-do compile { target "mips*-*-*" } } */
/* { dg-options "-O2 -ffast-math -mips4" } */
/* { dg-final { scan-assembler "rsqrt.d" } } */
/* { dg-final { scan-assembler "rsqrt.s" } } */

extern double sqrt(double);
extern float sqrtf(float);

double foo(double x)
{
  return 1.0/sqrt(x);
}

float bar(float x)
{
  return 1.0f/sqrtf(x);
}


/* { dg-do compile { target "mips*-*-*" } } */
/* { dg-options "-O2 -ffast-math -mips4" } */
/* { dg-final { scan-assembler "rsqrt.d" } } */
/* { dg-final { scan-assembler "rsqrt.s" } } */

extern double sqrt(double);
extern float sqrtf(float);

double foo(double x)
{
  return sqrt(1.0/x);
}

float bar(float x)
{
  return sqrtf(1.0f/x);
}


/* { dg-do compile { target "mips*-*-*" } } */
/* { dg-options "-O2 -mips4" } */
/* { dg-final { scan-assembler-not "rsqrt.d" } } */
/* { dg-final { scan-assembler-not "rsqrt.s" } } */

extern double sqrt(double);
extern float sqrtf(float);

double foo(double x)
{
  return 1.0/sqrt(x);
}

double bar(double x)
{
  return sqrt(1.0/x);
}

float foof(float x)
{
  return 1.0f/sqrtf(x);
}

float barf(float x)
{
  return sqrtf(1.0f/x);
}


Roger
--


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