From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D23CF3857C4A; Thu, 7 Mar 2024 02:00:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D23CF3857C4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709776838; bh=9E4j7L3LuMe5+yRI4s3Ndd35jzOew6ET2+DbOUkokMw=; h=From:To:Subject:Date:From; b=YD6ZU4Kkr6f5C5eTPbH676lzffo0JobHF6Qvj1idrauT3EW2X3LkNCzY19IZVLMME wPJQg7nazgrv8w/A3yrOMbsYI5W5OWasWdaJS21tjeh2Yq1LK+CIrQgqT7EnKrqsz8 dsoZ4dgwMiK8AOCNwXQn/w9uYzL2e7BMux1LzAl8= From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114262] New: Over-inlining when optimizing for size? Date: Thu, 07 Mar 2024 02:00:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114262 Bug ID: 114262 Summary: Over-inlining when optimizing for size? Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- (https://gcc.godbolt.org/z/a4ox6oEfT) ``` struct impl; struct impl* get_impl(int key); int get_value(struct impl* p); extern __inline__ __attribute__((__gnu_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); } ``` This is actually two functions, one is `gnu_inline` and the other is a non-inline one. It looks to me that if I mark a function `gnu_inline`, I as= sert that 'somewhere I shall provide an external definition for you' so when optimizing for size, GCC may generate a call instead of using the more comp= lex inline definition. The `real_get_value_by_key` function is made a deliberate sibling call, so ideally this should be ``` real_get_value_by_key: jmp get_value_by_key ``` and not=20 ``` real_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 ``` It still gets inlined with `-finline-limit=3D0` and can only be disabled by `-fno-inline`. I have no idea how it is controlled. --------------------------- # Trivia These are two `gnu_inline` functions from the same library. Most of the time they should both be inlined in user code. However, external definitions are required when optimization is not turned on, or when their addresses are ta= ken, so they must still exist. As they are unlikely to be used anyway, optimizi= ng for size makes much more sense.=