public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/93487] Missed tail-call optimizations
       [not found] <bug-93487-4@http.gcc.gnu.org/bugzilla/>
@ 2020-04-20  6:07 ` pskocik at gmail dot com
  2021-08-22  0:16 ` pinskia at gcc dot gnu.org
  2024-05-26 20:41 ` pskocik at gmail dot com
  2 siblings, 0 replies; 3+ messages in thread
From: pskocik at gmail dot com @ 2020-04-20  6:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from pskocik at gmail dot com ---
The gist of this along with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93540
is "please make trivial aggregates (i.e., aggregates, which are ultimately a
native type) a true zero-cost abstraction".

I feel like we shouldn't have to pay for `struct Int { int _; };` (or a union
of int with some <= types) over `int`, but on gcc (contrast with clang), you
effectively have to:

/////////////////////
int intfunc(void);
int intfuncwrap(void) { return intfunc(); }

=>
jmp    5 <intfuncwrap+0x5>

/////////////////////
struct Int { int x; };
struct Int intfuncwrap2(void) { return (struct Int){intfunc()}; }

=>
push   rax
call   6 <intfuncwrap2+0x6>
pop    rdx
ret
/////////////////////

Clang has been doing this right since clang 3 (and Compiler Explorer doesn't
have an older version):  https://gcc.godbolt.org/z/VSUHs_ .

Here's a related, but opposite, example where a trivial (one-member) union gets
optimized better than its contained type when used directly: 
https://gcc.godbolt.org/z/egXRjJ . 

These trivial type wrappings shouldn't affect codegen positively or negatively,
but they do on gcc.

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

* [Bug middle-end/93487] Missed tail-call optimizations
       [not found] <bug-93487-4@http.gcc.gnu.org/bugzilla/>
  2020-04-20  6:07 ` [Bug middle-end/93487] Missed tail-call optimizations pskocik at gmail dot com
@ 2021-08-22  0:16 ` pinskia at gcc dot gnu.org
  2024-05-26 20:41 ` pskocik at gmail dot com
  2 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22  0:16 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-22
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
             Blocks|                            |101926

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101926
[Bug 101926] [meta-bug] struct/complex argument passing and return should be
improved

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

* [Bug middle-end/93487] Missed tail-call optimizations
       [not found] <bug-93487-4@http.gcc.gnu.org/bugzilla/>
  2020-04-20  6:07 ` [Bug middle-end/93487] Missed tail-call optimizations pskocik at gmail dot com
  2021-08-22  0:16 ` pinskia at gcc dot gnu.org
@ 2024-05-26 20:41 ` pskocik at gmail dot com
  2 siblings, 0 replies; 3+ messages in thread
From: pskocik at gmail dot com @ 2024-05-26 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Petr Skocik <pskocik at gmail dot com> ---
Another case of a missed tailcall which might warrant a separate mention:

    struct big{ long _[10]; };
    void takePtr(void *);
    void takeBigAndPassItsAddress(struct big X){ takePtr(&X); }

This should ideally compile to just `lea 8(%rsp), %rdi; jmp takePtr;`.

The compiler might be tempted here to use the taking of an address of a local
here
as a reason not to tail call, and clang misses this optimization too, probably
for this reason,
but tailcalling here is fine as the particular local here isn't
allocated by the function but rather the callee during the call.

Icc does do this optimization: https://godbolt.org/z/a6coTzPjz

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

end of thread, other threads:[~2024-05-26 20:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-93487-4@http.gcc.gnu.org/bugzilla/>
2020-04-20  6:07 ` [Bug middle-end/93487] Missed tail-call optimizations pskocik at gmail dot com
2021-08-22  0:16 ` pinskia at gcc dot gnu.org
2024-05-26 20:41 ` pskocik at gmail 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).