re PR c++/23372 (Temporary aggregate copy not elided when passing parameters by value)
authorRichard Guenther <rguenther@suse.de>
Mon, 30 Jan 2006 13:46:30 +0000 (13:46 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 30 Jan 2006 13:46:30 +0000 (13:46 +0000)
2006-01-30  Richard Guenther  <rguenther@suse.de>

PR c++/23372
* gimplify.c (gimplify_target_expr): Handle easy cases
without creating a temporary.

* gcc.dg/pr23372-1.C: New testcase.

From-SVN: r110396

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr23372-1.c [new file with mode: 0644]

index 99b6f9fb9e3000e41326d3a0626e9d96c6ada2d6..dcd3684c4f1f9fe6e8b63a9493db60b4368681a1 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-30  Richard Guenther  <rguenther@suse.de>
+
+       PR c++/23372
+       * gimplify.c (gimplify_target_expr): Handle easy cases
+       without creating a temporary.
+
 2006-01-30  Nathan Sidwell  <nathan@codesourcery.com>
 
        * vec.h (safe_grow): Remove duplicated line.
index cb1b95eebaa008ef3ff4daf89ae45288644709e9..876160955f56603ec3a166d41a3dc631bf0694b3 100644 (file)
@@ -4053,6 +4053,15 @@ gimplify_target_expr (tree *expr_p, tree *pre_p, tree *post_p)
 
   if (init)
     {
+      /* Try to avoid the temporary if possible.  */
+      if (TREE_CODE (init) == INDIRECT_REF
+         && !TREE_SIDE_EFFECTS (init)
+          && !TARGET_EXPR_CLEANUP (targ))
+        {
+          *expr_p = init;
+          return GS_OK;
+        }
+
       /* TARGET_EXPR temps aren't part of the enclosing block, so add it
         to the temps list.  */
       gimple_add_tmp_var (temp);
index 5d9b87bbc28328c7f962c73abb79a0cee93fd6b2..c7b641144d2f7741ae8fe2c68ec5763b32386c1e 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-30  Richard Guenther  <rguenther@suse.de>
+
+       PR c++/23372
+       * gcc.dg/pr23372-1.C: New testcase.
+
 2006-01-29  Diego Novillo  <dnovillo@redhat.com>
 
        * gcc.dg/gomp/pr25874.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr23372-1.c b/gcc/testsuite/gcc.dg/pr23372-1.c
new file mode 100644 (file)
index 0000000..1414947
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+
+struct A {
+  int a[1000];
+};
+void f(struct A);
+void g(struct A *a) { f(*a); }
+
+/* { dg-final { scan-assembler-times "memcpy" 1 } } */