From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26EAE3858406; Fri, 1 Oct 2021 15:52:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26EAE3858406 From: "jschoen4 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/102554] New: [ 10/11/12 Regresion ] Inlining missed at -O3 with non-default --param=early-inlining-insns and pragma optimize Date: Fri, 01 Oct 2021 15:52:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jschoen4 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Oct 2021 15:52:18 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102554 Bug ID: 102554 Summary: [ 10/11/12 Regresion ] Inlining missed at -O3 with non-default --param=3Dearly-inlining-insns and pragma optimize Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: jschoen4 at gmail dot com CC: marxin at gcc dot gnu.org Target Milestone: --- GNU C++14 (GCC) version 10.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 10.2.0, GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1, isl version isl-0.16.1-GMP Target: x86_64-pc-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.2.0 (GCC) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3DTEST CODE=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D cat test.cpp #pragma GCC push_options #pragma GCC optimize ("no-lifetime-dse") class TestClass { public: static inline int should_inline() { return 10; } }; #pragma GCC pop_options int main() { return TestClass::should_inline() + 1; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3Dcmd =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D gcc-10 test.cpp -S --param=3Dearly-inlining-insns=3D30 -O3 -fno-lifetime-ds= e -Wall -Wextra =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3DBAD ASM =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D cat test.s .file "test.cpp" .text .section=20=20=20=20=20=20=20 .text._ZN9TestClass13should_inlineEv,"axG",@progbits,_ZN9TestClass13should_= inlineEv,comdat .p2align 4 .weak _ZN9TestClass13should_inlineEv .type _ZN9TestClass13should_inlineEv, @function _ZN9TestClass13should_inlineEv: .LFB0: .cfi_startproc movl $10, %eax ret .cfi_endproc .LFE0: .size _ZN9TestClass13should_inlineEv, .-_ZN9TestClass13should_inlineEv .section .text.startup,"ax",@progbits .p2align 4 .globl main .type main, @function main: .LFB1: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 call _ZN9TestClass13should_inlineEv addq $8, %rsp .cfi_def_cfa_offset 8 addl $1, %eax ret .cfi_endproc .LFE1: .size main, .-main .ident "GCC: (GNU) 10.2.0" .section .note.GNU-stack,"",@progbits =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3Dinfo =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D cat test.cpp.079i.inline ... Deciding on inlining of small functions. Starting with size 9. Enqueueing calls in int main()/1. test.cpp:13:34: missed: not inlinable: int main()/1 -> static int TestClass::should_inline()/0, optimization level attribute mismatch param_early_inlining_insns (0x1e/0xe) Enqueueing calls in static int TestClass::should_inline()/0. node context cache: 0 hits, 0 misses, 1 initializations ... =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3DGOOD ASM =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D gcc-10 test.cpp -S --param=3Dearly-inlining-insns=3D14 -O3 -fno-lifetime-ds= e -Wall -Wextra .file "test.cpp" .text .section .text.startup,"ax",@progbits .p2align 4 .globl main .type main, @function main: .LFB1: .cfi_startproc movl $11, %eax ret .cfi_endproc .LFE1: .size main, .-main .ident "GCC: (GNU) 10.2.0" .section .note.GNU-stack,"",@progbits =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3Dnotes=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Starting with gcc 10+ (gcc9 works correctly), the use of --param=3Dearly-inlining-insns=3D30 and -O3 on the command line combined wi= th using a "#pragma GCC optimize" in source code, even one that does not change the effective optimization attributes, causes "optimization level attribute mismatch" to occur in the inliner. In the example I placed both -fno-lifetime-dse on the command line and in t= he pragma gcc optimize ("no-lifetime-dse"), so it has no impact at all to the effective optimization attributes.=20=20 The issue is not specific to using just pragma GCC optimize "no-lifetime-ds= e", any pragma gcc optimize line will have this effect. Even "unrecognized" one= s.=20 i.e. #pragma GCC optimize ("fake_attribute") Any value OTHER THAN --param=3Dearly-inlining-insns=3D14 on the command lin= e when used with -O3 and pragma optimize will trigger this. .. i.e. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3Doptimize correctly =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D gcc-10 test.cpp -S --param=3Dearly-inlining-insns=3D14 -O3 -fno-lifetime-ds= e -Wall -Wextra gcc-10 test.cpp -S --param=3Dearly-inlining-insns=3D30 -O2 -fno-lifetime-ds= e -Wall -Wextra gcc-9 test.cpp -S --param=3Dearly-inlining-insns=3D30 -O3 -fno-lifetime-dse= -Wall -Wextra =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3Dmissed optimize =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D gcc-10 test.cpp -S --param=3Dearly-inlining-insns=3D12 -O3 -fno-lifetime-ds= e -Wall -Wextra gcc-10 test.cpp -S --param=3Dearly-inlining-insns=3D17 -O3 -fno-lifetime-ds= e -Wall -Wextra etc. gcc-11 test.cpp -S --param=3Dearly-inlining-insns=3D30 -O3 -fno-lifetime-ds= e -Wall -Wextra gcc-12 test.cpp -S --param=3Dearly-inlining-insns=3D30 -O3 -fno-lifetime-ds= e -Wall -Wextra gcc-trunk test.cpp -S --param=3Dearly-inlining-insns=3D30 -O3 -fno-lifetime= -dse -Wall -Wextra Code path where CIF_OPTIMIZATION_MISMATCH is being set. gcc/ipa-inline.c: 568 can_early_inline_edge_p (struct cgraph_edge *e) ... 593 if (!can_inline_edge_p (e, true, true) 594 || !can_inline_edge_by_limits_p (e, true, false, true)) --------> 428 can_inline_edge_by_limits_p (struct cgraph_edge *e, bool report, 429 bool disregard_limits =3D false, bool = early =3D false) ... 524 /* When user added an attribute to the callee honor it. */ 525 else if (lookup_attribute ("optimize", DECL_ATTRIBUTES (callee->decl)) 526 && opts_for_fn (caller->decl) !=3D opts_for_fn (callee->decl)) 527 { 528 e->inline_failed =3D CIF_OPTIMIZATION_MISMATCH; 529 inlinable =3D false; 530 } I suspect the change that moved the --params=3D options into the cl_optimiz= ation struct is related to this misssed optimization.=