public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Add -Wdisabled-optimization warning for not optimizing sibling calls
@ 2023-08-04 17:57 Bradley Lucier
  2023-08-05 20:58 ` Prathamesh Kulkarni
  0 siblings, 1 reply; 14+ messages in thread
From: Bradley Lucier @ 2023-08-04 17:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: lucier

The patch at the end adds a warning when a tail/sibling call cannot be 
optimized for various reasons.

I built and tested GCC with and without the patch with configuration

Configured with: ../../gcc-mainline/configure --enable-languages=c 
--disable-multilib --prefix=/pkgs/gcc-mainline --disable-werror

There were some changes in the test results, but I can't say that they 
look substantive:

diff -C 2 summary.log ../gcc-mainline
*** summary.log	Thu Aug  3 22:56:13 2023
--- ../gcc-mainline/summary.log	Thu Aug  3 19:42:33 2023
***************
*** 14,22 ****
   		=== g++ Summary ===

! # of expected passes		239234
   # of unexpected failures	5
   # of expected failures		2087
! # of unsupported tests		10566
! /home/lucier/programs/gcc/objdirs/gcc-mainline-new/gcc/xg++  version 
14.0.0 20230802 (experimental) (GCC)

   		=== gcc tests ===
--- 14,22 ----
   		=== g++ Summary ===

! # of expected passes		239262
   # of unexpected failures	5
   # of expected failures		2087
! # of unsupported tests		10562
! /home/lucier/programs/gcc/objdirs/gcc-mainline/gcc/xg++  version 
14.0.0 20230802 (experimental) (GCC)

   		=== gcc tests ===
***************
*** 155,164 ****
   		=== gcc Summary ===

! # of expected passes		192553
   # of unexpected failures	109
   # of unexpected successes	19
   # of expected failures		1506
! # of unsupported tests		2623
! /home/lucier/programs/gcc/objdirs/gcc-mainline-new/gcc/xgcc  version 
14.0.0 20230802 (experimental) (GCC)

   		=== libatomic tests ===
--- 155,164 ----
   		=== gcc Summary ===

! # of expected passes		192563
   # of unexpected failures	109
   # of unexpected successes	19
   # of expected failures		1506
! # of unsupported tests		2619
! /home/lucier/programs/gcc/objdirs/gcc-mainline/gcc/xgcc  version 
14.0.0 20230802 (experimental) (GCC)

   		=== libatomic tests ===

I then configured and built GCC with

  ../../gcc-mainline/configure CXX="/pkgs/gcc-mainline-new/bin/g++ 
-Wdisabled-optimization" --enable-languages=c --disable-multilib 
--prefix=/pkgs/gcc-mainline-test --disable-werror --disable-bootstrap

to test the new warning.  The warnings are of the form, e.g.,

../../../gcc-mainline/gcc/tree-vect-stmts.cc:11990:44: warning: cannot 
apply sibling-call optimization: callee required more stack slots than 
the caller [-Wdisabled-optimization]

These are the number of times this warning was triggered building stage1:

grep warning: build.log | grep sibling | sed 's/^.*://' | sort | uniq -c
     259  callee required more stack slots than the caller 
[-Wdisabled-optimization]
      43  callee returns a structure [-Wdisabled-optimization]

If this patch is OK, someone else will need to commit it for me.

Brad

gcc/Changelog

	* calls.cc (maybe_complain_about_tail_call) Add warning when
	tail or sibling call cannot be optimized.

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 1f3a6d5c450..b95c876fda8 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1242,10 +1242,12 @@ void
  maybe_complain_about_tail_call (tree call_expr, const char *reason)
  {
    gcc_assert (TREE_CODE (call_expr) == CALL_EXPR);
-  if (!CALL_EXPR_MUST_TAIL_CALL (call_expr))
-    return;
-
-  error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
+  if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
+    error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
+  else if (flag_optimize_sibling_calls)
+    warning (OPT_Wdisabled_optimization,
+             "cannot apply sibling-call optimization: %s", reason);
+  return;
  }

  /* Fill in ARGS_SIZE and ARGS array based on the parameters found in



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

end of thread, other threads:[~2023-08-21  7:48 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 17:57 [PATCH] Add -Wdisabled-optimization warning for not optimizing sibling calls Bradley Lucier
2023-08-05 20:58 ` Prathamesh Kulkarni
2023-08-05 21:37   ` Bradley Lucier
2023-08-05 21:41     ` Prathamesh Kulkarni
2023-08-05 21:53   ` David Malcolm
2023-08-06 18:29     ` Bradley Lucier
2023-08-07  7:18     ` Richard Biener
2023-08-07 19:04       ` Bradley Lucier
2023-08-08  6:05         ` Richard Biener
2023-08-08 16:54           ` David Malcolm
2023-08-15 22:47             ` Bradley Lucier
2023-08-17  7:54               ` Richard Biener
2023-08-18 17:13                 ` Bradley Lucier
2023-08-21  7:47                   ` Richard Biener

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