https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90864
Bug ID: 90864 Summary: Suboptimal codegen of structs in C/C++on x86_64 Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jaak at ristioja dot ee Target Milestone: --- I found two issues with handling of structures, which might be related. Given structures like this: struct X { char v; }; struct X2 { X x; char v; }; struct X3 { X2 x2; char v; }; The code generated for the following function: X3 id(X3 value) { return value; } with clang/clang++ (version 8.0.0) and -O2 is: 0: 89 f8 mov %edi,%eax 2: c3 but with gcc/g++ 9.1.0 and -O2 the generated code reads: 0: 89 f8 mov %edi,%eax 2: 0f b7 d7 movzwl %di,%edx 5: c1 e8 10 shr $0x10,%eax 8: 0f b6 c0 movzbl %al,%eax b: 48 c1 e0 10 shl $0x10,%rax f: 48 09 d0 or %rdx,%rax 12: c3 retq and with gcc/g++ 8.3.0 it was even worse: 0: 89 fa mov %edi,%edx 2: c1 ef 10 shr $0x10,%edi 5: 0f b6 c2 movzbl %dl,%eax 8: 40 0f b6 ff movzbl %dil,%edi c: 0f b6 d6 movzbl %dh,%edx f: 88 d4 mov %dl,%ah 11: 48 c1 e7 10 shl $0x10,%rdi 15: 48 09 f8 or %rdi,%rax 18: c3 retq I'm not sure whether this is a related issue or not, but something as simple as the following also fails to compile, even though the argument should be found in %rdi on x86_64: void test(X3 a) { __asm__ ("" :: "r" (a)); } With the output: warning: asm operand 0 probably doesn't match constraints __asm__ ("" :: "r" (a)); ^ error: impossible constraint in 'asm'