At -O2 we should IMNSHO generate the same code for all 3 functions:
typedef union
{
  struct
  {
    int f1, f2, f3, f4, f5, f6, f7, f8;
    long int f9, f10;
    int f11;
  } f;
  char s[56];
  long int a;
} T;

void
foo (void)
{
  T t;
  t = (T) { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
  test (&t);
}

void
bar (void)
{
  T t = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
  test (&t);
}

void
baz (void)
{
  T t;
  t = (const T) { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
  test (&t);
}

as nothing took the address of the compound literals, it was only used as
initializer to some other variable.  But instead foo/baz clear a temporary
(compound literal var) and then copy it over.  This is at least partly a
regression from 3.2.x which cleared both the compound literal variable (wasn't
able to DSE it) and the t variable.

Without a union we generate better code:
typedef struct
{
  int f1, f2, f3, f4, f5, f6, f7, f8;
  long int f9, f10;
  int f11;
} T;

void
foo (void)
{
  T t;
  t = (T) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  test (&t);
}

void
bar (void)
{
  T t = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  test (&t);
}

void
baz (void)
{
  T t;
  t = (const T) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  test (&t);
}
but still bar uses on x86_64-linux rep stosq, while the other functions
store it by pieces.


-- 
           Summary: [4.1/4.2/4.3 Regression] Inefficient code with compound
                    literals
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33723

Reply via email to