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

            Bug ID: 95126
           Summary: Missed opportunity to turn static variables into
                    immediates
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pskocik at gmail dot com
  Target Milestone: ---

Example:

For:

struct small{ short a,b; signed char c; };

void call_func(void)
{
        extern int func(struct small X);
        static struct small const s = { 1,2,0 };
        func(s);
}

clang renders (x86_64):

0000000000000000 <call_func>:
   0:   bf 01 00 02 00          mov    edi,0x20001
   5:   e9 00 00 00 00          jmp    a <call_func+0xa>        6:
R_X86_64_PLT32       func-0x4

whereas gcc renders:

0000000000000000 <call_func>:
   0:   0f b7 3d 00 00 00 00    movzx  edi,WORD PTR [rip+0x0]        # 7
<call_func+0x7>        3: R_X86_64_PC32        .rodata-0x2
   7:   0f b7 05 00 00 00 00    movzx  eax,WORD PTR [rip+0x0]        # e
<call_func+0xe>        a: R_X86_64_PC32        .rodata-0x4
   e:   48 c1 e7 10             shl    rdi,0x10
  12:   48 09 f8                or     rax,rdi
  15:   0f b7 3d 00 00 00 00    movzx  edi,WORD PTR [rip+0x0]        # 1c
<call_func+0x1c>      18: R_X86_64_PC32       .rodata
  1c:   48 c1 e7 20             shl    rdi,0x20
  20:   48 09 c7                or     rdi,rax
  23:   e9 00 00 00 00          jmp    28 <call_func+0x28>      24:
R_X86_64_PLT32      func-0x4


https://gcc.godbolt.org/z/Qxq6Rh

Reply via email to