public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v5 1/5] Improve must tail in RTL backend
@ 2024-05-05 18:14 Andi Kleen
  2024-05-05 18:14 ` [PATCH v5 2/5] C++: Support clang compatible [[musttail]] (PR83324) Andi Kleen
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Andi Kleen @ 2024-05-05 18:14 UTC (permalink / raw)
  To: gcc-patches; +Cc: nathan, josmyers, richard.sandiford, jason, Andi Kleen

- Give error messages for all causes of non sibling call generation
- Don't override choices of other non sibling call checks with
must tail. This causes ICEs. The must tail attribute now only
overrides flag_optimize_sibling_calls locally.
- Error out when tree-tailcall failed to mark a must-tail call
sibcall. In this case it doesn't know the true reason and only gives
a vague message (this could be improved, but it's already useful without
that) tree-tailcall usually fails without optimization, so must
adjust the existing must-tail plugin test to specify -O2.

	PR83324

gcc/ChangeLog:

	* calls.cc (expand_call): Fix mustcall implementation.

gcc/testsuite/ChangeLog:

	* gcc.dg/plugin/must-tail-call-1.c: Adjust.
---
 gcc/calls.cc                                  | 30 ++++++++++++-------
 .../gcc.dg/plugin/must-tail-call-1.c          |  1 +
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 21d78f9779fe..a6b8ee44cc29 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -2650,7 +2650,9 @@ expand_call (tree exp, rtx target, int ignore)
   /* The type of the function being called.  */
   tree fntype;
   bool try_tail_call = CALL_EXPR_TAILCALL (exp);
-  bool must_tail_call = CALL_EXPR_MUST_TAIL_CALL (exp);
+  /* tree-tailcall decided not to do tail calls. Error for the musttail case.  */
+  if (!try_tail_call)
+      maybe_complain_about_tail_call (exp, "other reasons");
   int pass;
 
   /* Register in which non-BLKmode value will be returned,
@@ -3022,10 +3024,22 @@ expand_call (tree exp, rtx target, int ignore)
      pushed these optimizations into -O2.  Don't try if we're already
      expanding a call, as that means we're an argument.  Don't try if
      there's cleanups, as we know there's code to follow the call.  */
-  if (currently_expanding_call++ != 0
-      || (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp))
-      || args_size.var
-      || dbg_cnt (tail_call) == false)
+  if (currently_expanding_call++ != 0)
+    {
+      maybe_complain_about_tail_call (exp, "inside another call");
+      try_tail_call = 0;
+    }
+  if (!flag_optimize_sibling_calls
+	&& !CALL_FROM_THUNK_P (exp)
+	&& !CALL_EXPR_MUST_TAIL_CALL (exp))
+    try_tail_call = 0;
+  if (args_size.var)
+    {
+      /* ??? correct message?  */
+      maybe_complain_about_tail_call (exp, "stack space needed");
+      try_tail_call = 0;
+    }
+  if (dbg_cnt (tail_call) == false)
     try_tail_call = 0;
 
   /* Workaround buggy C/C++ wrappers around Fortran routines with
@@ -3046,15 +3060,11 @@ expand_call (tree exp, rtx target, int ignore)
 	    if (MEM_P (*iter))
 	      {
 		try_tail_call = 0;
+		maybe_complain_about_tail_call (exp, "hidden string length argument");
 		break;
 	      }
 	}
 
-  /* If the user has marked the function as requiring tail-call
-     optimization, attempt it.  */
-  if (must_tail_call)
-    try_tail_call = 1;
-
   /*  Rest of purposes for tail call optimizations to fail.  */
   if (try_tail_call)
     try_tail_call = can_implement_as_sibling_call_p (exp,
diff --git a/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c b/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c
index 3a6d4cceaba7..44af361e2925 100644
--- a/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c
@@ -1,4 +1,5 @@
 /* { dg-do compile { target tail_call } } */
+/* { dg-options "-O2" } */
 /* { dg-options "-fdelayed-branch" { target sparc*-*-* } } */
 
 extern void abort (void);
-- 
2.44.0


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

end of thread, other threads:[~2024-05-21 21:45 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-05 18:14 [PATCH v5 1/5] Improve must tail in RTL backend Andi Kleen
2024-05-05 18:14 ` [PATCH v5 2/5] C++: Support clang compatible [[musttail]] (PR83324) Andi Kleen
2024-05-07  3:02   ` Jason Merrill
2024-05-14 17:24     ` Andi Kleen
2024-05-14 21:52       ` Jason Merrill
2024-05-14 23:23         ` Andi Kleen
2024-05-21 18:02           ` Jason Merrill
2024-05-05 18:14 ` [PATCH v5 3/5] C: Implement musttail attribute for returns Andi Kleen
2024-05-05 18:14 ` [PATCH v5 4/5] Add tests for C/C++ musttail attributes Andi Kleen
2024-05-05 18:14 ` [PATCH v5 5/5] Add documentation for musttail attribute Andi Kleen
2024-05-14 14:21   ` Richard Biener
2024-05-14 16:30     ` Andi Kleen
2024-05-14 17:08       ` Richard Biener
2024-05-14 14:15 ` [PATCH v5 1/5] Improve must tail in RTL backend Richard Biener
2024-05-14 17:19   ` Andi Kleen
2024-05-20  4:53   ` Andi Kleen
2024-05-21  8:31     ` Richard Biener
2024-05-21 13:35       ` Andi Kleen
2024-05-21 16:41         ` Richard Biener
2024-05-21 21:45           ` Andi Kleen

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).