This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix PR23477


by special casing all-zero constructor.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

:ADDPATCH middle-end:


2005-08-30  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 separate.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.809
diff -c -3 -p -r1.809 expr.c
*** expr.c	23 Aug 2005 07:28:06 -0000	1.809
--- expr.c	30 Aug 2005 11:46:44 -0000
*************** mostly_zeros_p (tree exp)
*** 4645,4650 ****
--- 4645,4668 ----
  
    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);
+ }
  
  /* Helper function for store_constructor.
     TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
*************** expand_expr_real_1 (tree exp, rtx target
*** 6843,6848 ****
--- 6861,6880 ----
  	  return const0_rtx;
  	}
  
+       /* Try to avoid creating a temporary at all.  This is possible
+ 	 if we can construct with a single memset, which store_constructor
+ 	 knows how to do.
+ 	 FIXME: exchange all_zeros_p for something that allows all
+ 	 [0..255] initializers.  */
+       else if (TREE_STATIC (exp)
+ 	       && !TREE_ADDRESSABLE (exp)
+ 	       && target != 0 && mode == BLKmode
+ 	       && all_zeros_p (exp))
+ 	{
+ 	  store_constructor (exp, target, 0, int_expr_size (exp));
+ 	  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]