[PATCH] Consistently gimplify all-zero CTORs to = {};

Richard Biener rguenther@suse.de
Thu Jun 21 10:20:00 GMT 2018


PR86223 points out that we currently gimplify the testcase inconsistently.
For the incomplete CTORs we use block-clearing while for the complete
one we emit initializations of the individual elements (up to the
limits imposed in following checks).

So the following makes us always use = {}; form for all-zero CTORs
which is most compact for GIMPLE IL and should only result in better
code (fingers crossing...) since but not only beacause SRA got the
ability to handle a = .LC0; style inits as well.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Richard.

2018-06-21  Richard Biener  <rguenther@suse.de>

	PR middle-end/86223
	* gimplify.c (gimplify_init_constructor): For an all-zero
	constructor emit a block-clear.

	* gcc.dg/pr86223-1.c: New testcase.

Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revision 261839)
+++ gcc/gimplify.c	(working copy)
@@ -4805,6 +4805,10 @@ gimplify_init_constructor (tree *expr_p,
 	     requires trickery to avoid quadratic compile-time behavior in
 	     large cases or excessive memory use in small cases.  */
 	  cleared = !CONSTRUCTOR_NO_CLEARING (ctor);
+	else if (num_nonzero_elements == 0)
+	  /* If all elements are zero it is most efficient to block-clear
+	     things.  */
+	  cleared = true;
 	else if (num_ctor_elements - num_nonzero_elements
 		 > CLEAR_RATIO (optimize_function_for_speed_p (cfun))
 		 && num_nonzero_elements < num_ctor_elements / 4)
Index: gcc/testsuite/gcc.dg/pr86223-1.c
===================================================================
--- gcc/testsuite/gcc.dg/pr86223-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pr86223-1.c	(working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+void f (int *);
+void g ()
+{
+  int a[3] = { 0, 0, 0 };
+  f (a);
+}
+void h ()
+{
+  int a[3] = { 0 };
+  f (a);
+}
+
+/* We should use block-clearing for the initializer of a in both cases.  */
+/* { dg-final { scan-tree-dump-times "a = {};" 2 "gimple" } } */



More information about the Gcc-patches mailing list