[15/61] Possible inlining improvements with -Os

Message ID 20250131171232.1018281-17-aleksandar.rakic@htecgroup.com
State New
Headers
Series Improve Mips target |

Commit Message

Aleksandar Rakic Jan. 31, 2025, 5:13 p.m. UTC
  From: Robert Suchanek <robert.suchanek@imgtec.com>

--param early-inlining-insns-cold=NUMBER
--param max-inline-insns-small-and-cold=NUMBER

Analysis shows that the main difference between -O2 and -Os goes down to
inlining of cold or unlikely functions. The new parameters (defaulted to
0) mean to disable these limitations with -Os. NUMBER could be set to
something like 4-32 to see the impact.

The main reason that smaller functions are treated as cold or unlikely
is the function cgraph_maybe_hot_edge_p () always returning FALSE for
-Os.

Cherry-picked c38d7e548cbb3defb141efb528cb356333e8eb7a
from https://github.com/MIPS/gcc

Signed-off-by: Robert Suchanek <robert.suchanek@imgtec.com>
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Aleksandar Rakic <aleksandar.rakic@htecgroup.com>
---
 gcc/ipa-inline.cc | 4 +++-
 gcc/params.opt    | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index fe8efa9a157..1a2a62b73cd 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -820,7 +820,8 @@  want_early_inline_function_p (struct cgraph_edge *e)
 
       if (!want_inline || growth <= param_max_inline_insns_size)
 	;
-      else if (!e->maybe_hot_p ())
+      else if (!e->maybe_hot_p ()
+	       && growth > param_early_inlining_insns_cold)
 	{
 	  if (dump_enabled_p ())
 	    dump_printf_loc (MSG_MISSED_OPTIMIZATION, e->call_stmt,
@@ -1060,6 +1061,7 @@  want_inline_small_function_p (struct cgraph_edge *e, bool report)
 	}
       /* If call is cold, do not inline when function body would grow. */
       else if (!e->maybe_hot_p ()
+	 && growth > param_max_inline_insns_small_and_cold
 	       && (growth >= inline_insns_single (e->caller, false, false)
 		   || growth_positive_p (callee, e, growth)))
 	{
diff --git a/gcc/params.opt b/gcc/params.opt
index 7c572774df2..edb62a221fb 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -130,6 +130,10 @@  Maximum size (in bytes) of objects tracked bytewise by dead store elimination.
 Common Joined UInteger Var(param_early_inlining_insns) Init(6) Optimization Param
 Maximal estimated growth of function body caused by early inlining of single call.
 
+-param=early-inlining-insns-cold=
+Common Joined UInteger Var(param_early_inlining_insns_cold) Init(0) Optimization Param
+Maximal estimated growth of function body caused by early inlining of cold call.
+
 -param=fsm-scale-path-stmts=
 Common Joined UInteger Var(param_fsm_scale_path_stmts) Init(2) IntegerRange(1, 10) Param Optimization
 Scale factor to apply to the number of statements in a threading path crossing a loop backedge when comparing to max-jump-thread-duplication-stmts.
@@ -573,6 +577,10 @@  The maximum number of instructions when inlining for size.
 Common Joined UInteger Var(param_max_inline_insns_small) Optimization Param
 The maximum number of instructions when automatically inlining small functions.
 
+-param=max-inline-insns-small-and-cold=
+Common Joined UInteger Var(param_max_inline_insns_small_and_cold) Optimization Init(0) Param
+The maximum number of instructions in a small and cold function eligible for inlining.
+
 -param=max-inline-recursive-depth=
 Common Joined UInteger Var(param_max_inline_recursive_depth) Optimization Init(8) Param
 The maximum depth of recursive inlining for inline functions.