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.

Reply via email to