public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Add sibcall-{9,10}.c testcases
@ 2015-02-20 14:48 Jakub Jelinek
  2015-02-20 16:37 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2015-02-20 14:48 UTC (permalink / raw)
  To: Rainer Orth, Mike Stump; +Cc: gcc-patches

Hi!

As mentioned in PR63892, with the addition of ICF the sibcall-{3,4}.c tests
no longer test what they meant to test.  This patch duplicates the tests
and adds a volatile var bump in just one of the functions so that ICF can't
be performed and the tests really test sibcalls rather than say tail
recursion.

Regtested on x86_64-linux and i686-linux, ok for trunk?

2015-02-20  Jakub Jelinek  <jakub@redhat.com>

	* gcc.dg/sibcall-9.c: New test.
	* gcc.dg/sibcall-10.c: New test.

--- gcc/testsuite/gcc.dg/sibcall-9.c.jj	2015-02-20 13:18:23.235665924 +0100
+++ gcc/testsuite/gcc.dg/sibcall-9.c	2015-02-20 13:19:44.830335968 +0100
@@ -0,0 +1,82 @@
+/* Simple check that sibling calls are performed from a
+   void non-leaf-function taking one int argument calling a function which
+   is about the same as itself.
+
+   Copyright (C) 2002 Free Software Foundation Inc.
+   Contributed by Hans-Peter Nilsson  <hp@bitrange.com>  */
+
+/* { dg-do run { xfail { { cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */
+/* -mlongcall disables sibcall patterns.  */
+/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+/* The option -foptimize-sibling-calls is the default, but serves as
+   marker.  This test is xfailed on targets without sibcall patterns
+   (except targets where the test does not work due to the return address
+   not saved on the regular stack).  */
+
+extern void abort (void);
+extern void exit (int);
+
+/* Sibcalls are not supported in MIPS16 mode, which has direct calls but
+   not direct jumps.  */
+#ifdef __mips
+#define ATTR __attribute__((nomips16))
+#else
+#define ATTR
+#endif
+
+static ATTR void recurser_void1 (int);
+static ATTR void recurser_void2 (int);
+extern void track (int);
+volatile int v;
+
+int main ()
+{
+  recurser_void1 (0);
+  if (v != 5)
+    abort ();
+  exit (0);
+}
+
+/* The functions should get the same stack-frame, and best way to make it
+   reasonably sure is to make them have the same contents (regarding the
+   n tests).  */
+
+static void __attribute__((noinline)) ATTR
+recurser_void1 (int n)
+{
+  if (n == 0 || n == 7 || n == 8)
+    track (n);
+
+  if (n == 10)
+    return;
+
+  recurser_void2 (n + 1);
+}
+
+static void __attribute__((noinline)) ATTR
+recurser_void2 (int n)
+{
+  if (n == 0 || n == 7 || n == 8)
+    track (n);
+
+  if (n == 10)
+    return;
+
+  v++;
+  recurser_void1 (n + 1);
+}
+
+void *trackpoint;
+
+void __attribute__ ((noinline))
+track (int n)
+{
+  char stackpos[1];
+
+  if (n == 0)
+    trackpoint = stackpos;
+  else if ((n != 7 && n != 8) || trackpoint != stackpos)
+    abort ();
+}
--- gcc/testsuite/gcc.dg/sibcall-10.c.jj	2015-02-20 13:19:51.170232631 +0100
+++ gcc/testsuite/gcc.dg/sibcall-10.c	2015-02-20 13:20:50.570264437 +0100
@@ -0,0 +1,83 @@
+/* Simple check that sibling calls are performed from a
+   void non-leaf-function taking no arguments calling a function which
+   is about the same as itself.
+
+   Copyright (C) 2002 Free Software Foundation Inc.
+   Contributed by Hans-Peter Nilsson  <hp@bitrange.com>  */
+
+/* { dg-do run { xfail { { cris-*-* crisv32-*-* h8300-*-* hppa*64*-*-* m32r-*-* mcore-*-* mn10300-*-* msp430*-*-* nds32*-*-* xstormy16-*-* v850*-*-* vax-*-* xtensa*-*-* } || { arm*-*-* && { ! arm32 } } } } } */
+/* -mlongcall disables sibcall patterns.  */
+/* { dg-skip-if "" { powerpc*-*-* } { "-mlongcall" } { "" } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+/* The option -foptimize-sibling-calls is the default, but serves as
+   marker.  This test is xfailed on targets without sibcall patterns
+   (except targets where the test does not work due to the return address
+   not saved on the regular stack).  */
+
+extern void abort (void);
+extern void exit (int);
+
+/* Sibcalls are not supported in MIPS16 mode, which has direct calls but
+   not direct jumps.  */
+#ifdef __mips
+#define ATTR __attribute__((nomips16))
+#else
+#define ATTR
+#endif
+
+static ATTR void recurser_void1 (void);
+static ATTR void recurser_void2 (void);
+extern void track (void);
+volatile int v;
+
+int n = 0;
+int main ()
+{
+  recurser_void1 ();
+  if (v != 5)
+    abort ();
+  exit (0);
+}
+
+/* The functions should get the same stack-frame, and best way to make it
+   reasonably sure is to make them have the same contents (regarding the
+   n tests).  */
+
+static void __attribute__((noinline)) ATTR
+recurser_void1 (void)
+{
+  if (n == 0 || n == 7 || n == 8)
+    track ();
+
+  if (n == 10)
+    return;
+  n++;
+  recurser_void2 ();
+}
+
+static void __attribute__((noinline)) ATTR
+recurser_void2 (void)
+{
+  if (n == 0 || n == 7 || n == 8)
+    track ();
+
+  if (n == 10)
+    return;
+  n++;
+  v++;
+  recurser_void1 ();
+}
+
+void *trackpoint;
+
+void __attribute__ ((noinline))
+track ()
+{
+  char stackpos[1];
+
+  if (n == 0)
+    trackpoint = stackpos;
+  else if ((n != 7 && n != 8) || trackpoint != stackpos)
+    abort ();
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add sibcall-{9,10}.c testcases
  2015-02-20 14:48 [PATCH] Add sibcall-{9,10}.c testcases Jakub Jelinek
@ 2015-02-20 16:37 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2015-02-20 16:37 UTC (permalink / raw)
  To: Jakub Jelinek, Rainer Orth, Mike Stump; +Cc: gcc-patches

On 02/20/15 07:45, Jakub Jelinek wrote:
> Hi!
>
> As mentioned in PR63892, with the addition of ICF the sibcall-{3,4}.c tests
> no longer test what they meant to test.  This patch duplicates the tests
> and adds a volatile var bump in just one of the functions so that ICF can't
> be performed and the tests really test sibcalls rather than say tail
> recursion.
>
> Regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2015-02-20  Jakub Jelinek  <jakub@redhat.com>
>
> 	* gcc.dg/sibcall-9.c: New test.
> 	* gcc.dg/sibcall-10.c: New test.
OK.
Jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-20 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-20 14:48 [PATCH] Add sibcall-{9,10}.c testcases Jakub Jelinek
2015-02-20 16:37 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).