tstellar / rpms / gcc

Forked from rpms/gcc 4 years ago
Clone
0d16b69
2007-10-29  Jakub Jelinek  <jakub@redhat.com>
0d16b69
0d16b69
	PR tree-optimization/33723
0d16b69
	* c-gimplify.c (c_gimplify_expr): Optimize INIT_EXPR or
0d16b69
	MODIFY_EXPR with non-addressable COMPOUND_LITERAL_EXPR as source.
0d16b69
0d16b69
2007-11-20  Jakub Jelinek  <jakub@redhat.com>
0d16b69
0d16b69
	PR testsuite/33978
0d16b69
	* gcc.dg/tree-ssa/pr33723.c: Adjust scan pattern to make it less
0d16b69
	dependent on target settings like move_by_pieces etc.
0d16b69
0d16b69
2007-10-30  Jakub Jelinek  <jakub@redhat.com>
0d16b69
0d16b69
	PR tree-optimization/33723
0d16b69
	* gcc.dg/tree-ssa/pr33723.c (T): Decrease size of field s.
0d16b69
0d16b69
2007-10-29  Jakub Jelinek  <jakub@redhat.com>
0d16b69
0d16b69
	PR tree-optimization/33723
0d16b69
	* gcc.c-torture/execute/20071029-1.c: New test.
0d16b69
	* gcc.dg/tree-ssa/pr33723.c: New test.
0d16b69
0d16b69
--- gcc/c-gimplify.c	(revision 129742)
0d16b69
+++ gcc/c-gimplify.c	(revision 129743)
0d16b69
@@ -233,6 +233,29 @@ c_gimplify_expr (tree *expr_p, tree *pre
0d16b69
     case COMPOUND_LITERAL_EXPR:
0d16b69
       return gimplify_compound_literal_expr (expr_p, pre_p);
0d16b69
 
0d16b69
+    case INIT_EXPR:
0d16b69
+    case MODIFY_EXPR:
0d16b69
+      if (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == COMPOUND_LITERAL_EXPR)
0d16b69
+	{
0d16b69
+	  tree complit = TREE_OPERAND (*expr_p, 1);
0d16b69
+	  tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (complit);
0d16b69
+	  tree decl = DECL_EXPR_DECL (decl_s);
0d16b69
+	  tree init = DECL_INITIAL (decl);
0d16b69
+
0d16b69
+	  /* struct T x = (struct T) { 0, 1, 2 } can be optimized
0d16b69
+	     into struct T x = { 0, 1, 2 } if the address of the
0d16b69
+	     compound literal has never been taken.  */
0d16b69
+	  if (!TREE_ADDRESSABLE (complit)
0d16b69
+	      && !TREE_ADDRESSABLE (decl)
0d16b69
+	      && init)
0d16b69
+	    {
0d16b69
+	      *expr_p = copy_node (*expr_p);
0d16b69
+	      TREE_OPERAND (*expr_p, 1) = init;
0d16b69
+	      return GS_OK;
0d16b69
+	    }
0d16b69
+	}
0d16b69
+      return GS_UNHANDLED;
0d16b69
+
0d16b69
     default:
0d16b69
       return GS_UNHANDLED;
0d16b69
     }
0d16b69
--- gcc/testsuite/gcc.c-torture/execute/20071029-1.c	(revision 0)
0d16b69
+++ gcc/testsuite/gcc.c-torture/execute/20071029-1.c	(revision 129743)
0d16b69
@@ -0,0 +1,56 @@
0d16b69
+extern void exit (int);
0d16b69
+extern void abort (void);
0d16b69
+
0d16b69
+typedef union
0d16b69
+{
0d16b69
+  struct
0d16b69
+  {
0d16b69
+    int f1, f2, f3, f4, f5, f6, f7, f8;
0d16b69
+    long int f9, f10;
0d16b69
+    int f11;
0d16b69
+  } f;
0d16b69
+  char s[56];
0d16b69
+  long int a;
0d16b69
+} T;
0d16b69
+
0d16b69
+__attribute__((noinline))
0d16b69
+void
0d16b69
+test (T *t)
0d16b69
+{
0d16b69
+  static int i = 11;
0d16b69
+  if (t->f.f1 != i++)
0d16b69
+    abort ();
0d16b69
+  if (t->f.f2 || t->f.f3 || t->f.f4 || t->f.f5 || t->f.f6
0d16b69
+      || t->f.f7 || t->f.f8 || t->f.f9 || t->f.f10 || t->f.f11)
0d16b69
+    abort ();
0d16b69
+  if (i == 20)
0d16b69
+    exit (0);
0d16b69
+}
0d16b69
+
0d16b69
+__attribute__((noinline))
0d16b69
+void
0d16b69
+foo (int i)
0d16b69
+{
0d16b69
+  T t;
0d16b69
+again:
0d16b69
+  t = (T) { { ++i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
0d16b69
+  test (&t);
0d16b69
+  goto again;
0d16b69
+}
0d16b69
+
0d16b69
+int
0d16b69
+main (void)
0d16b69
+{
0d16b69
+  T *t1, *t2;
0d16b69
+  int cnt = 0;
0d16b69
+  t1 = (T *) 0;
0d16b69
+loop:
0d16b69
+  t2 = t1;
0d16b69
+  t1 = & (T) { .f.f9 = cnt++ };
0d16b69
+  if (cnt < 3)
0d16b69
+    goto loop;
0d16b69
+  if (t1 != t2 || t1->f.f9 != 2)
0d16b69
+    abort ();
0d16b69
+  foo (10);
0d16b69
+  return 0;
0d16b69
+}
0d16b69
--- gcc/testsuite/gcc.dg/tree-ssa/pr33723.c	(revision 0)
0d16b69
+++ gcc/testsuite/gcc.dg/tree-ssa/pr33723.c	(revision 129743)
0d16b69
@@ -0,0 +1,72 @@
0d16b69
+/* PR tree-optimization/33723 */
0d16b69
+/* { dg-do compile } */
0d16b69
+/* { dg-options "-O2 -fdump-tree-gimple" } */
0d16b69
+
0d16b69
+typedef union
0d16b69
+{
0d16b69
+  struct
0d16b69
+  {
0d16b69
+    int f1, f2, f3, f4, f5, f6, f7, f8;
0d16b69
+    long int f9, f10;
0d16b69
+    int f11;
0d16b69
+  } f;
0d16b69
+  char s[4];
0d16b69
+  long int a;
0d16b69
+} T;
0d16b69
+
0d16b69
+void
0d16b69
+foo1 (void)
0d16b69
+{
0d16b69
+  T t;
0d16b69
+  t = (T) { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+void
0d16b69
+bar1 (void)
0d16b69
+{
0d16b69
+  T t = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+void
0d16b69
+baz1 (void)
0d16b69
+{
0d16b69
+  T t;
0d16b69
+  t = (const T) { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+void
0d16b69
+foo2 (void)
0d16b69
+{
0d16b69
+  T t;
0d16b69
+  t = (T) { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+void
0d16b69
+bar2 (void)
0d16b69
+{
0d16b69
+  T t = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+void
0d16b69
+baz2 (void)
0d16b69
+{
0d16b69
+  T t;
0d16b69
+  t = (const T) { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+void
0d16b69
+baz3 (void)
0d16b69
+{
0d16b69
+  T t;
0d16b69
+  t = (const T) (T) { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } };
0d16b69
+  test (&t);
0d16b69
+}
0d16b69
+
0d16b69
+/* { dg-final { scan-tree-dump-not "t = D" "gimple"} } */
0d16b69
+/* { dg-final { cleanup-tree-dump "gimple" } } */