From f20a6c57f0f26d9c60d6d6182f1e2181f727c834 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Mon, 26 Oct 2020 18:19:48 +0100 Subject: Implement three-level optimize_for_size predicates this patch implements thre two-state optimize_for_size predicates, so with -Os and with profile feedback for never executed code it returns OPTIMIZE_SIZE_MAX while in cases we decide to optimize for size based on branch prediction logic it return OPTIMIZE_SIZE_BALLANCED. The idea is that for places where we guess that code is unlikely we do not want to do extreme optimizations for size that leads to many fold slowdowns (using idiv rather than few shigts or using rep based inlined stringops). I will update RTL handling code to also support this with BB granuality (which we don't currently). LLVM has -Os and -Oz levels where -Oz is our -Os and LLVM's -Os would ocrrespond to OPTIMIZE_SIZE_BALLANCED. I wonder if we want to export this to command line somehow? For me it would be definitly useful to test things, I am not sure how "weaker" -Os is desired in practice. gcc/ChangeLog: * cgraph.h (cgraph_node::optimize_for_size_p): Return optimize_size_level. (cgraph_node::optimize_for_size_p): Update. * coretypes.h (enum optimize_size_level): New enum. * predict.c (unlikely_executed_edge_p): Microoptimize. (optimize_function_for_size_p): Return optimize_size_level. (optimize_bb_for_size_p): Likewise. (optimize_edge_for_size_p): Likewise. (optimize_insn_for_size_p): Likewise. (optimize_loop_nest_for_size_p): Likewise. * predict.h (optimize_function_for_size_p): Update declaration. (optimize_bb_for_size_p): Update declaration. (optimize_edge_for_size_p): Update declaration. (optimize_insn_for_size_p): Update declaration. (optimize_loop_for_size_p): Update declaration. (optimize_loop_nest_for_size_p): Update declaration. --- gcc/cgraph.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'gcc/cgraph.h') diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 65e4646..fb3ad95 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -1279,7 +1279,7 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node bool check_calls_comdat_local_p (); /* Return true if function should be optimized for size. */ - bool optimize_for_size_p (void); + enum optimize_size_level optimize_for_size_p (void); /* Dump the callgraph to file F. */ static void dump_cgraph (FILE *f); @@ -3315,15 +3315,17 @@ cgraph_node::mark_force_output (void) /* Return true if function should be optimized for size. */ -inline bool +inline enum optimize_size_level cgraph_node::optimize_for_size_p (void) { if (opt_for_fn (decl, optimize_size)) - return true; + return OPTIMIZE_SIZE_MAX; + if (count == profile_count::zero ()) + return OPTIMIZE_SIZE_MAX; if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED) - return true; + return OPTIMIZE_SIZE_BALANCED; else - return false; + return OPTIMIZE_SIZE_NO; } /* Return symtab_node for NODE or create one if it is not present -- cgit v1.1