[Bug target/93897] Poor trivial structure initialization code with -O3

hjl.tools at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jul 14 12:58:29 GMT 2021


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

--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> ---
Another testcase:

[hjl@gnu-cfl-1 tmp]$ cat x.c
extern int foo();
extern int bar();

typedef int (*func_t)(int);

struct test
{
        func_t func1;
        func_t func2;
};

void mainfunc (struct test *iface)
{
  iface->func1 = foo;
  iface->func2 = bar;
}
[hjl@gnu-cfl-1 tmp]$ gcc -S -O2 x.c
[hjl@gnu-cfl-1 tmp]$ cat x.s
        .file   "x.c"
        .text
        .p2align 4
        .globl  mainfunc
        .type   mainfunc, @function
mainfunc:
.LFB0:
        .cfi_startproc
        movq    $foo, (%rdi)
        movq    $bar, 8(%rdi)
        ret
        .cfi_endproc
.LFE0:
        .size   mainfunc, .-mainfunc
        .ident  "GCC: (GNU) 11.1.1 20210531 (Red Hat 11.1.1-3)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-1 tmp]$ gcc -S -O3 x.c -march=skylake
[hjl@gnu-cfl-1 tmp]$ cat x.s
        .file   "x.c"
        .text
        .p2align 4
        .globl  mainfunc
        .type   mainfunc, @function
mainfunc:
.LFB0:
        .cfi_startproc
        movl    $foo, %edx
        movl    $bar, %eax
        vmovq   %rdx, %xmm0
        vpinsrq $1, %rax, %xmm0, %xmm0
        vmovdqu %xmm0, (%rdi)
        ret
        .cfi_endproc
.LFE0:
        .size   mainfunc, .-mainfunc
        .ident  "GCC: (GNU) 11.1.1 20210531 (Red Hat 11.1.1-3)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-1 tmp]$


More information about the Gcc-bugs mailing list