2005-08-31 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 31 Aug 2005 11:20:38 +0000 (11:20 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 31 Aug 2005 11:20:38 +0000 (11:20 +0000)
PR middle-end/23477
* expr.c (all_zeros_p): New function.
(expand_expr_real_1): Handle the case of an all-zero
non-addressable constructor separately.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103670 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/expr.c

index 94a82fa..330db3e 100644 (file)
@@ -1,3 +1,10 @@
+2005-08-31  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/23477
+       * expr.c (all_zeros_p): New function.
+       (expand_expr_real_1): Handle the case of an all-zero
+       non-addressable constructor separately.
+
 2005-08-31  Adrian Straetling  <straetling@de.ibm.com>
 
        * builtins.c: (expand_builtin_strcpy, expand_builtin_strcat): Change
index e619808..e75d335 100644 (file)
@@ -4645,6 +4645,24 @@ mostly_zeros_p (tree exp)
 
   return initializer_zerop (exp);
 }
+
+/* Return 1 if EXP contains all zeros.  */
+
+static int
+all_zeros_p (tree exp)
+{
+  if (TREE_CODE (exp) == CONSTRUCTOR)
+
+    {
+      HOST_WIDE_INT nz_elts, nc_elts, count;
+      bool must_clear;
+
+      categorize_ctor_elements (exp, &nz_elts, &nc_elts, &count, &must_clear);
+      return nz_elts == 0;
+    }
+
+  return initializer_zerop (exp);
+}
 \f
 /* Helper function for store_constructor.
    TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
@@ -6843,6 +6861,19 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
          return const0_rtx;
        }
 
+      /* Try to avoid creating a temporary at all.  This is possible
+        if all of the initializer is zero.
+        FIXME: try to handle all [0..255] initializers we can handle
+        with memset.  */
+      else if (TREE_STATIC (exp)
+              && !TREE_ADDRESSABLE (exp)
+              && target != 0 && mode == BLKmode
+              && all_zeros_p (exp))
+       {
+         clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
+         return target;
+       }
+
       /* All elts simple constants => refer to a constant in memory.  But
         if this is a non-BLKmode mode, let it store a field at a time
         since that should make a CONST_INT or CONST_DOUBLE when we