public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lh_mouse at 126 dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-114262-4-aB2a6FFnur@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114262-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114262

--- Comment #4 from LIU Hao <lh_mouse at 126 dot com> ---
(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 = 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.

  parent reply	other threads:[~2024-03-07  3:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07  2:00 [Bug tree-optimization/114262] New: Over-inlining when optimizing for size? lh_mouse at 126 dot com
2024-03-07  2:07 ` [Bug tree-optimization/114262] " pinskia at gcc dot gnu.org
2024-03-07  2:33 ` [Bug ipa/114262] Over-inlining when optimizing for size with gnu_inline function lh_mouse at 126 dot com
2024-03-07  2:57 ` pinskia at gcc dot gnu.org
2024-03-07  3:20 ` lh_mouse at 126 dot com [this message]
2024-03-07  3:25 ` pinskia at gcc dot gnu.org
2024-03-07 15:55   ` Jan Hubicka
2024-03-07 15:55 ` hubicka at ucw dot cz
2024-03-07 17:08 ` lh_mouse at 126 dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114262-4-aB2a6FFnur@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).