Patchwork [10/10] -fuse-caller-save - Add test-case

login
register
mail settings
Submitter Tom de Vries
Date Dec. 6, 2013, 12:34 a.m.
Message ID <52A11B94.8000000@mentor.com>
Download mbox | patch
Permalink /patch/297498/
State New
Headers show

Comments

Tom de Vries - Dec. 6, 2013, 12:34 a.m.
On 27-04-13 12:01, Richard Sandiford wrote:
> Tom de Vries <tom@codesourcery.com> writes:
>> +/* { dg-do run } */
>> +/* { dg-options "-fuse-caller-save -save-temps" } */
>> +/* { dg-skip-if "" { *-*-* }  { "*" } { "-Os" } } */
>> +/* Testing -fuse-caller-save optimization option.  */
>> +
>> +static int __attribute__((noinline))
>> +bar (int x)
>> +{
>> +  return x + 3;
>> +}
>> +
>> +int __attribute__((noinline))
>> +foo (int y)
>> +{
>> +  return y + bar (y);
>> +}
>> +
>> +int
>> +main (void)
>> +{
>> +  return !(foo (5) == 13);
>> +}
>> +
>> +/* Check that there are only 2 stack-saves: r31 in main and foo.  */
>> +
>> +/* Variant not mips16.  Check that there only 2 sw/sd.  */
>> +/* { dg-final { scan-assembler-times "(?n)s\[wd\]\t\\\$.*,.*\\(\\\$sp\\)" 2 { target { ! mips16 } } } } */
>> +
>> +/* Variant not mips16, Subvariant micromips.  Additionally check there's no
>> +   swm.  */
>> +/* { dg-final { scan-assembler-times "(?n)swm\t\\\$.*,.*\\(\\\$sp\\)" 0 {target micromips } } } */
>> +
>> +/* Variant mips16.  The save can save 1 or more registers, check that only 1 is
>> +   saved, twice in total.  */
>> +/* { dg-final { scan-assembler-times "(?n)save\t\[0-9\]*,\\\$\[^,\]*\$" 2 { target mips16 } } } */
>> +
>> +/* Check that the first caller-save register is unused.  */
>> +/* { dg-final { scan-assembler-not "(\\\$16)" } } */
>
> Sorry to ask, but I think it would be better to split this up into
> a compile test and a run test.  The run test shouldn't be skipped at -Os.
> It should probably also go somewhere more general than gcc.target/mips.
>

Richard,

Done. There's now run test gcc.dg/fuse-caller-save.c and compile test 
gcc.target/mips/fuse-caller-save.c.

> I've tried to avoid conditional scan-assemblers in gcc.target/mips
> whereever possible.  The directory has been set up so that you can force
> any subtarget you like, so that (for example) -mips16 output is tested
> by every run, not just things like mips-sim/-mips16.
>
> In this case I think that means using NOCOMPRESSION to force the
> functions to use the standard ISA encoding and making the scan-assemblers
> test only for that.

Done.

> Since you've already done the work :-), bonus points
> for creating two copies, one for micromips (dg-options "-micromips ...")
> and one for mips16 (dg-options "-mips16 ...").  That's certainly not a
> requirement though.
>

I've left that out for now.

OK for stage1?

Thanks,
- Tom

> Thanks,
> Richard
>
Richard Sandiford - Dec. 6, 2013, 8:51 a.m.
Tom de Vries <Tom_deVries@mentor.com> writes:
> On 27-04-13 12:01, Richard Sandiford wrote:
>> Tom de Vries <tom@codesourcery.com> writes:
>>> +/* { dg-do run } */
>>> +/* { dg-options "-fuse-caller-save -save-temps" } */
>>> +/* { dg-skip-if "" { *-*-* }  { "*" } { "-Os" } } */
>>> +/* Testing -fuse-caller-save optimization option.  */
>>> +
>>> +static int __attribute__((noinline))
>>> +bar (int x)
>>> +{
>>> +  return x + 3;
>>> +}
>>> +
>>> +int __attribute__((noinline))
>>> +foo (int y)
>>> +{
>>> +  return y + bar (y);
>>> +}
>>> +
>>> +int
>>> +main (void)
>>> +{
>>> +  return !(foo (5) == 13);
>>> +}
>>> +
>>> +/* Check that there are only 2 stack-saves: r31 in main and foo.  */
>>> +
>>> +/* Variant not mips16.  Check that there only 2 sw/sd.  */
>>> +/* { dg-final { scan-assembler-times
>>> "(?n)s\[wd\]\t\\\$.*,.*\\(\\\$sp\\)" 2 { target { ! mips16 } } } } */
>>> +
>>> +/* Variant not mips16, Subvariant micromips.  Additionally check there's no
>>> +   swm.  */
>>> +/* { dg-final { scan-assembler-times
>>> "(?n)swm\t\\\$.*,.*\\(\\\$sp\\)" 0 {target micromips } } } */
>>> +
>>> +/* Variant mips16.  The save can save 1 or more registers, check
>>> that only 1 is
>>> +   saved, twice in total.  */
>>> +/* { dg-final { scan-assembler-times
>>> "(?n)save\t\[0-9\]*,\\\$\[^,\]*\$" 2 { target mips16 } } } */
>>> +
>>> +/* Check that the first caller-save register is unused.  */
>>> +/* { dg-final { scan-assembler-not "(\\\$16)" } } */
>>
>> Sorry to ask, but I think it would be better to split this up into
>> a compile test and a run test.  The run test shouldn't be skipped at -Os.
>> It should probably also go somewhere more general than gcc.target/mips.
>>
>
> Richard,
>
> Done. There's now run test gcc.dg/fuse-caller-save.c and compile test 
> gcc.target/mips/fuse-caller-save.c.
>
>> I've tried to avoid conditional scan-assemblers in gcc.target/mips
>> whereever possible.  The directory has been set up so that you can force
>> any subtarget you like, so that (for example) -mips16 output is tested
>> by every run, not just things like mips-sim/-mips16.
>>
>> In this case I think that means using NOCOMPRESSION to force the
>> functions to use the standard ISA encoding and making the scan-assemblers
>> test only for that.
>
> Done.
>
>> Since you've already done the work :-), bonus points
>> for creating two copies, one for micromips (dg-options "-micromips ...")
>> and one for mips16 (dg-options "-mips16 ...").  That's certainly not a
>> requirement though.
>>
>
> I've left that out for now.

OK for the MIPS part, except:

> +/* Check that the first caller-save register is unused.  */
> +/* { dg-final { scan-assembler-not "(\\\$16)" } } */

the (...) regexp grouping seems redundant here.

Thanks,
Richard

Patch

2013-12-04  Radovan Obradovic  <robradovic@mips.com>
            Tom de Vries  <tom@codesourcery.com>

	* gcc.target/mips/mips.exp: Add use-caller-save to -ffoo/-fno-foo
	options.
	* gcc.dg/fuse-caller-save.c: New test.
	* gcc.target/mips/fuse-caller-save.c: Same.

diff --git a/gcc/testsuite/gcc.dg/fuse-caller-save.c b/gcc/testsuite/gcc.dg/fuse-caller-save.c
new file mode 100644
index 0000000..561a66d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fuse-caller-save.c
@@ -0,0 +1,21 @@ 
+/* { dg-do run } */
+/* { dg-options "-fuse-caller-save" } */
+/* Testing -fuse-caller-save optimization option.  */
+
+static int __attribute__((noinline))
+bar (int x)
+{
+  return x + 3;
+}
+
+int __attribute__((noinline))
+foo (int y)
+{
+  return y + bar (y);
+}
+
+int
+main (void)
+{
+  return !(foo (5) == 13);
+}
diff --git a/gcc/testsuite/gcc.target/mips/fuse-caller-save.c b/gcc/testsuite/gcc.target/mips/fuse-caller-save.c
new file mode 100644
index 0000000..212ca45
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/fuse-caller-save.c
@@ -0,0 +1,30 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fuse-caller-save" } */
+/* { dg-skip-if "" { *-*-* }  { "*" } { "-Os" } } */
+/* Testing -fuse-caller-save optimization option.  */
+
+static int __attribute__((noinline)) NOCOMPRESSION
+bar (int x)
+{
+  return x + 3;
+}
+
+int __attribute__((noinline)) NOCOMPRESSION
+foo (int y)
+{
+  return y + bar (y);
+}
+
+int NOCOMPRESSION
+main (void)
+{
+  return !(foo (5) == 13);
+}
+
+/* Check that there are only 2 stack-saves: r31 in main and foo.  */
+
+/* Check that there only 2 sw/sd.  */
+/* { dg-final { scan-assembler-times "(?n)s\[wd\]\t\\\$.*,.*\\(\\\$sp\\)" 2 } } */
+
+/* Check that the first caller-save register is unused.  */
+/* { dg-final { scan-assembler-not "(\\\$16)" } } */
diff --git a/gcc/testsuite/gcc.target/mips/mips.exp b/gcc/testsuite/gcc.target/mips/mips.exp
index 1f0d0d6..5bfadec 100644
--- a/gcc/testsuite/gcc.target/mips/mips.exp
+++ b/gcc/testsuite/gcc.target/mips/mips.exp
@@ -305,6 +305,7 @@  foreach option {
     tree-vectorize
     unroll-all-loops
     unroll-loops
+    use-caller-save
 } {
     lappend mips_option_groups $option "-f(no-|)$option"
 }