Hi, this patch makes inliner to not inline functions with -O0 optimization attribute and also to not inline into functions.
Bootstrapped/regtested x86_64-linux, comitted. PR middle-end/58332 * gcc.c-torture/compile/pr58332.c: New testcase. * cif-code.def (FUNCTION_NOT_OPTIMIZED): New CIF code. * ipa-inline.c (can_inline_edge_p): Do not downgrade FUNCTION_NOT_OPTIMIZED. * ipa-inline-analysis.c (compute_inline_parameters): Function not optimized is not inlinable unless it is alwaysinline. (inline_analyze_function): Force calls in not optimized function not inlinable. Index: testsuite/gcc.c-torture/compile/pr58332.c =================================================================== --- testsuite/gcc.c-torture/compile/pr58332.c (revision 0) +++ testsuite/gcc.c-torture/compile/pr58332.c (revision 0) @@ -0,0 +1,2 @@ +static inline int foo (int x) { return x + 1; } +__attribute__ ((__optimize__ (0))) int bar (void) { return foo (100); } Index: cif-code.def =================================================================== --- cif-code.def (revision 202656) +++ cif-code.def (working copy) @@ -37,6 +37,9 @@ DEFCIFCODE(UNSPECIFIED , "") functions that have not been rejected for inlining yet. */ DEFCIFCODE(FUNCTION_NOT_CONSIDERED, N_("function not considered for inlining")) +/* Caller is compiled with optimizations disabled. */ +DEFCIFCODE(FUNCTION_NOT_OPTIMIZED, N_("caller is not optimized")) + /* Inlining failed owing to unavailable function body. */ DEFCIFCODE(BODY_NOT_AVAILABLE, N_("function body not available")) Index: ipa-inline.c =================================================================== --- ipa-inline.c (revision 202656) +++ ipa-inline.c (working copy) @@ -275,7 +275,8 @@ can_inline_edge_p (struct cgraph_edge *e } else if (e->call_stmt_cannot_inline_p) { - e->inline_failed = CIF_MISMATCHED_ARGUMENTS; + if (e->inline_failed != CIF_FUNCTION_NOT_OPTIMIZED) + e->inline_failed = CIF_MISMATCHED_ARGUMENTS; inlinable = false; } /* Don't inline if the functions have different EH personalities. */ Index: ipa-inline-analysis.c =================================================================== --- ipa-inline-analysis.c (revision 202656) +++ ipa-inline-analysis.c (working copy) @@ -2664,7 +2664,11 @@ compute_inline_parameters (struct cgraph info->stack_frame_offset = 0; /* Can this function be inlined at all? */ - info->inlinable = tree_inlinable_function_p (node->symbol.decl); + if (!optimize && !lookup_attribute ("always_inline", + DECL_ATTRIBUTES (node->symbol.decl))) + info->inlinable = false; + else + info->inlinable = tree_inlinable_function_p (node->symbol.decl); /* Type attributes can use parameter indices to describe them. */ if (TYPE_ATTRIBUTES (TREE_TYPE (node->symbol.decl))) @@ -3678,6 +3682,22 @@ inline_analyze_function (struct cgraph_n if (optimize && !node->thunk.thunk_p) inline_indirect_intraprocedural_analysis (node); compute_inline_parameters (node, false); + if (!optimize) + { + struct cgraph_edge *e; + for (e = node->callees; e; e = e->next_callee) + { + if (e->inline_failed == CIF_FUNCTION_NOT_CONSIDERED) + e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED; + e->call_stmt_cannot_inline_p = true; + } + for (e = node->indirect_calls; e; e = e->next_callee) + { + if (e->inline_failed == CIF_FUNCTION_NOT_CONSIDERED) + e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED; + e->call_stmt_cannot_inline_p = true; + } + } pop_cfun (); }