Bug 33723 - [4.2 Regression] Inefficient code with compound literals
Summary: [4.2 Regression] Inefficient code with compound literals
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: 4.3.0
Assignee: Jakub Jelinek
URL:
Keywords: missed-optimization
Depends on:
Blocks: 34146
  Show dependency treegraph
 
Reported: 2007-10-10 10:31 UTC by Jakub Jelinek
Modified: 2009-03-30 22:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 4.0.2 4.0.4 4.1.0 4.1.2 4.2.0 4.2.5
Last reconfirmed: 2007-10-29 16:46:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2007-10-10 10:31:14 UTC
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.
Comment 1 Andrew Pinski 2007-10-28 00:44:01 UTC
Confirmed.
Comment 2 Jakub Jelinek 2007-10-29 22:27:12 UTC
Subject: Bug 33723

Author: jakub
Date: Mon Oct 29 22:26:59 2007
New Revision: 129743

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129743
Log:
	PR tree-optimization/33723
	* c-gimplify.c (c_gimplify_expr): Optimize INIT_EXPR or
	MODIFY_EXPR with non-addressable COMPOUND_LITERAL_EXPR as source.

	* gcc.c-torture/execute/20071029-1.c: New test.
	* gcc.dg/tree-ssa/pr33723.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/20071029-1.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr33723.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-gimplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Jakub Jelinek 2007-10-29 22:28:17 UTC
Fixed on the trunk so far.
Comment 4 Jakub Jelinek 2007-10-30 13:30:10 UTC
Subject: Bug 33723

Author: jakub
Date: Tue Oct 30 13:29:57 2007
New Revision: 129772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129772
Log:
	PR tree-optimization/33723
	* gcc.dg/tree-ssa/pr33723.c (T): Decrease size of field s.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr33723.c

Comment 5 Joseph S. Myers 2008-07-04 22:19:01 UTC
Closing 4.1 branch.
Comment 6 Joseph S. Myers 2009-03-30 22:31:29 UTC
Closing 4.2 branch, fixed in 4.3.