This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/78821] New: GCC7: Copying whole 32 bits structure field by field not optimised into copying whole 32 bits at once


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

            Bug ID: 78821
           Summary: GCC7: Copying whole 32 bits structure field by field
                    not optimised into copying whole 32 bits at once
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: etienne_lorrain at yahoo dot fr
  Target Milestone: ---

Compiling (ia32, -O2) a function to copy whole structure is optimised on GCC7
pre-release (g++ (GCC-Explorer-Build) 7.0.0 20161113 (experimental)):

struct S
{
  char a, b, c, d;
} u, v;

void fct (void) {
  u = v;
}

leads to:
fct():
        movl    v, %eax
        movl    %eax, u
        ret

But other ways to copy the structure are not optimised, both:
void fct (void) {
  u = (struct S){v.a, v.b, v.c, v.d};
}
and:
void fct (void) {
  u.a = v.a;
  u.b = v.b;
  u.c = v.c;
  u.d = v.d;
}

leads to:
        movzbl  v, %eax
        movb    %al, u
        movzbl  v+1, %eax
        movb    %al, u+1
        movzbl  v+2, %eax
        movb    %al, u+2
        movzbl  v+3, %eax
        movb    %al, u+3

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]