From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ABCDC3858D32; Thu, 7 Mar 2024 03:20:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABCDC3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709781638; bh=y2Cq2DRX0K3bkNtXE3PCcnsJ/x+Cc54/XX4aAnm2OpQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=u2U5pENBjd/1KpuGAo8XF5R/rJAZQ+EfOawHZq+KEYwlVXdSE/0Ura2dK7rTaQE3i tAclA/IS/0kIMn0Ts+dg1TkerlMJKaMNx2zyA9deUVab3i8c2z0CopiuyomdA3HuP9 yPyP6fpFqm+W0qIfH9T54gUJP7fedeRiA+waZHSM= From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/114262] Over-inlining when optimizing for size with gnu_inline function Date: Thu, 07 Mar 2024 03:20:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: documentation X-Bugzilla-Severity: normal X-Bugzilla-Who: lh_mouse at 126 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114262 --- Comment #4 from LIU Hao --- (In reply to Andrew Pinski from comment #3) > It looks like it has been this way since r0-37737-g4838c5ee553f06 (2001) = (or > rather that is when it was used by the tree inline; I don't want to dig > further back to understand the RTL inliner). So looks like this is just > missing documentation ... It's not just about `gnu_inline`. If we switch to C++ inline we get the same result: (https://gcc.godbolt.org/z/ehbjqj5xh) ``` struct impl; struct impl* get_impl(int key); int get_value(struct impl* p); extern inline int get_value_by_key(int key) { struct impl* p =3D get_impl(key); if(!p) return -1; return get_value(p); } int real_get_value_by_key(int key) { return get_value_by_key(key); } ``` GCC outputs: ``` real_get_value_by_key(int): push rsi call get_impl(int) test rax, rax je .L2 mov rdi, rax pop rcx jmp get_value(impl*) .L2: or eax, -1 pop rdx ret ``` If we switched to C99 `extern inline` then it would produce desired result: ``` get_value_by_key: push rsi call get_impl test rax, rax je .L2 mov rdi, rax pop rcx jmp get_value .L2: or eax, -1 pop rdx ret real_get_value_by_key: jmp get_value_by_key `` The only difference between the C99 `extern inline` and C++ `extern inline`= is that the C++ external definition is COMDAT.=