* [PATCH] New tests for sibling call optimisation
@ 2002-11-03 19:51 Andreas Bauer
2002-11-03 20:39 ` Fergus Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Bauer @ 2002-11-03 19:51 UTC (permalink / raw)
To: gcc-patches
Hi All,
For my personal use, I have added two further tests to the existing
sibcall tests created by Hans-Peter Nilsson. The two add-ons are checking
whether targets that are capable of optimising indirect calls are doing the
right thing, especially when the callee contains an attribute `noreturn'.
The tests are not huge, but have been useful to me in the past (and may be
useful to others, especially now that x86_64 is becoming capable of doing
indirect sibcalls as well). I hope you include them to 3.4 bib, or let me
know if there's a problem with them, so I can fix it.
Looking forward to your feedback,
Andi.
2002-11-04 Andreas Bauer <baueran@in.tum.de>
gcc.dg/sibcall-6: New test for indirect sibcalls.
gcc.dg/sibcall-7: New test for indirect sibcalls with
attribute `noreturn'.
--- /dev/null Sun Jul 14 11:06:13 2002
+++ sibcall-6.c Mon Nov 4 14:48:12 2002
@@ -0,0 +1,23 @@
+/* A simple check to see whether indirect calls are
+ being sibcall optimized on targets that do support
+ this notion, i.e. have the according call patterns
+ in place.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Andreas Bauer <baueran@in.tum.de> */
+
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+int (*ptr) (int);
+extern int bar (int);
+
+int
+foo (f)
+ int f;
+{
+ ptr = bar;
+ return (*ptr)(f);
+}
+
+/* { dg-final { scan-assembler "jmp" } } */
--- /dev/null Sun Jul 14 11:06:13 2002
+++ sibcall-7.c Mon Nov 4 14:48:39 2002
@@ -0,0 +1,22 @@
+/* A simple check to make sure that indirect calls to
+ functions which do not return are not being sibcall
+ optimized. Works only on targets that have the
+ according call patterns for indirect sibcalls in
+ place.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Andreas Bauer <baueran@in.tum.de> */
+
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+typedef void noreturnfunc (void);
+noreturnfunc *ptr __attribute((noreturn));
+
+int
+foo (void)
+{
+ (*ptr) ();
+}
+
+/* { dg-final { scan-assembler-not "jmp" } } */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] New tests for sibling call optimisation
2002-11-03 19:51 [PATCH] New tests for sibling call optimisation Andreas Bauer
@ 2002-11-03 20:39 ` Fergus Henderson
2002-11-04 0:21 ` Andreas Bauer
0 siblings, 1 reply; 5+ messages in thread
From: Fergus Henderson @ 2002-11-03 20:39 UTC (permalink / raw)
To: Andreas Bauer; +Cc: gcc-patches
On 04-Nov-2002, Andreas Bauer <baueran@in.tum.de> wrote:
> --- /dev/null Sun Jul 14 11:06:13 2002
> +++ sibcall-6.c Mon Nov 4 14:48:12 2002
> @@ -0,0 +1,23 @@
> +/* A simple check to see whether indirect calls are
> + being sibcall optimized on targets that do support
> + this notion, i.e. have the according call patterns
> + in place.
> +
> + Copyright (C) 2002 Free Software Foundation Inc.
> + Contributed by Andreas Bauer <baueran@in.tum.de> */
> +
> +/* { dg-do compile { target i?86-*-* } } */
> +/* { dg-options "-O2 -foptimize-sibling-calls" } */
> +
> +int (*ptr) (int);
> +extern int bar (int);
> +
> +int
> +foo (f)
> + int f;
> +{
> + ptr = bar;
> + return (*ptr)(f);
> +}
> +
> +/* { dg-final { scan-assembler "jmp" } } */
This is not a very good test, since it is likely that a future version
of gcc will optimize this to just a direct (tail)call to bar(); at that
point, the test will continue to succeed, but will no longer be testing
what it is supposed to be testing.
It would be better to delete the assignment "ptr = bar;"
(and the declaration of "bar").
> +++ sibcall-7.c Mon Nov 4 14:48:39 2002
> @@ -0,0 +1,22 @@
> +/* A simple check to make sure that indirect calls to
> + functions which do not return are not being sibcall
> + optimized.
It would be helpful if the comments in this test case
explained why such calls should not be optimized.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] New tests for sibling call optimisation
2002-11-03 20:39 ` Fergus Henderson
@ 2002-11-04 0:21 ` Andreas Bauer
2002-11-04 9:36 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Bauer @ 2002-11-04 0:21 UTC (permalink / raw)
To: Fergus Henderson; +Cc: gcc-patches
> This is not a very good test, since it is likely that a future version
> of gcc will optimize this to just a direct (tail)call to bar(); at that
> point, the test will continue to succeed, but will no longer be testing
> what it is supposed to be testing.
>
> It would be better to delete the assignment "ptr = bar;"
> (and the declaration of "bar").
I removed the declaration; thank you for the comment.
> > +++ sibcall-7.c Mon Nov 4 14:48:39 2002
> > @@ -0,0 +1,22 @@
> > +/* A simple check to make sure that indirect calls to
> > + functions which do not return are not being sibcall
> > + optimized.
>
> It would be helpful if the comments in this test case
> explained why such calls should not be optimized.
Have added it; thanks again. :-)
OK, to commit?
Andi.
2002-11-04 Andreas Bauer <baueran@in.tum.de>
gcc.dg/sibcall-6: New test for indirect sibcalls.
gcc.dg/sibcall-7: New test for indirect sibcalls with
attribute `noreturn'.
--- /dev/null Sun Jul 14 11:06:13 2002
+++ sibcall-6.c Mon Nov 4 18:45:15 2002
@@ -0,0 +1,21 @@
+/* A simple check to see whether indirect calls are
+ being sibcall optimized on targets that do support
+ this notion, i.e. have the according call patterns
+ in place.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Andreas Bauer <baueran@in.tum.de> */
+
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+int (ptr) (int);
+
+int
+foo (f)
+ int f;
+{
+ return (*ptr)(f);
+}
+
+/* { dg-final { scan-assembler "jmp" } } */
--- /dev/null Sun Jul 14 11:06:13 2002
+++ sibcall-7.c Mon Nov 4 19:26:17 2002
@@ -0,0 +1,25 @@
+/* A simple check to make sure that indirect calls to functions
+ which do not return are not being sibcall optimized. The
+ problem is that sibcalls to noreturn functions would no longer
+ have an edge to the EXIT-block, which means that the code
+ intended to insert sibcall_epilogue patterns doesn't.
+ This test works only with targets that have the according call
+ patterns for indirect sibcalls in place.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Andreas Bauer <baueran@in.tum.de> */
+
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+typedef void noretfunc (void);
+noretfunc *ptr __attribute((noreturn));
+
+int
+foo (void)
+{
+ (*ptr) ();
+}
+
+/* { dg-final { scan-assembler-not "jmp" } } */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] New tests for sibling call optimisation
2002-11-04 0:21 ` Andreas Bauer
@ 2002-11-04 9:36 ` Richard Henderson
2002-11-04 16:02 ` Andreas Bauer
0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2002-11-04 9:36 UTC (permalink / raw)
To: Andreas Bauer; +Cc: Fergus Henderson, gcc-patches
On Mon, Nov 04, 2002 at 07:31:54PM +1100, Andreas Bauer wrote:
> gcc.dg/sibcall-6: New test for indirect sibcalls.
I'd much rather you tested this in some machine independant way,
so that all that is needed for new architectures is to add them
to the target list.
Hint: use __builtin_return_address(0).
> gcc.dg/sibcall-7: New test for indirect sibcalls with
> attribute `noreturn'.
This is pointless. The restriction is partly due to a
representation problem in the compiler. The only thing
that we ought to be verifying is that we don't ICE and
don't generate incorrect code.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] New tests for sibling call optimisation
2002-11-04 9:36 ` Richard Henderson
@ 2002-11-04 16:02 ` Andreas Bauer
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Bauer @ 2002-11-04 16:02 UTC (permalink / raw)
To: Richard Henderson, Fergus Henderson, gcc-patches
> I'd much rather you tested this in some machine independant way,
> so that all that is needed for new architectures is to add them
> to the target list.
>
> Hint: use __builtin_return_address(0).
I did not know about the function before. But, here is an updated
version of the test. Hope it can be used by people and be applied
now.
> > gcc.dg/sibcall-7: New test for indirect sibcalls with
> > attribute `noreturn'.
>
> This is pointless. The restriction is partly due to a
> representation problem in the compiler. The only thing
> that we ought to be verifying is that we don't ICE and
> don't generate incorrect code.
OK, will skip the test then. Personally, I found it useful while
extending the sibcall optimisation on x86 platforms, but I respect
your intention to not test a compiler shortcoming; we rather test
compiler features.
Thanks for feedback.
Looking forward to further comments,
Andi.
2002-11-04 Andreas Bauer <baueran@in.tum.de>
* gcc.dg/sibcall-6: New test for indirect sibcalls.
--- /dev/null Sun Jul 14 11:06:13 2002
+++ sibcall-6.c Tue Nov 5 11:03:03 2002
@@ -0,0 +1,42 @@
+/* A simple check to see whether indirect calls are
+ being sibcall optimized on targets that do support
+ this notion, i.e. have the according call patterns
+ in place.
+
+ Copyright (C) 2002 Free Software Foundation Inc.
+ Contributed by Andreas Bauer <baueran@in.tum.de> */
+
+/* { dg-do run { target i?86-*-* x86_64-*-*} } */
+/* { dg-options "-O2 -foptimize-sibling-calls" } */
+
+int foo (int);
+int bar (int);
+
+int (*ptr) (int);
+int *f_addr;
+
+int
+main ()
+{
+ ptr = bar;
+ foo (7);
+ exit (0);
+}
+
+int
+bar (b)
+ int b;
+{
+ if (f_addr == (int*) __builtin_return_address (0))
+ return b;
+ else
+ abort ();
+}
+
+int
+foo (f)
+ int f;
+{
+ f_addr = (int*) __builtin_return_address (0);
+ return (*ptr)(f);
+}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-11-05 0:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-03 19:51 [PATCH] New tests for sibling call optimisation Andreas Bauer
2002-11-03 20:39 ` Fergus Henderson
2002-11-04 0:21 ` Andreas Bauer
2002-11-04 9:36 ` Richard Henderson
2002-11-04 16:02 ` Andreas Bauer
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).