public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114262] New: Over-inlining when optimizing for size?
@ 2024-03-07  2:00 lh_mouse at 126 dot com
  2024-03-07  2:07 ` [Bug tree-optimization/114262] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: lh_mouse at 126 dot com @ 2024-03-07  2:00 UTC (permalink / raw)
  To: gcc-bugs

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

            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 = 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 assert
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 complex
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 
```
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=0` 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 taken,
so they must still exist. As they are unlikely to be used  anyway, optimizing
for size makes much more sense.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-07 17:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).