Do not put incomplete CONSTRUCTORs into static memory
authorEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 5 May 2020 10:31:26 +0000 (12:31 +0200)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 5 May 2020 10:39:09 +0000 (12:39 +0200)
The CONSTRUCTOR_NO_CLEARING flag was invented to avoid generating a memset
for  CONSTRUCTORS that lack elements, but it turns out that the gimplifier
can generate a memcpy for them instead, which is worse performance-wise,
so this prevents it from doing that for them.

* gimplify.c (gimplify_init_constructor): Do not put the constructor
into static memory if it is not complete.

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/aggr29.adb [new file with mode: 0644]

index 2267a63bca13e7821ee2172bf1d019a04c5db21c..73634780e0f8bbc0dd3d81c14adba77a2ba2d0dc 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gimplify.c (gimplify_init_constructor): Do not put the constructor
+       into static memory if it is not complete.
+
 2020-05-05  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/94949
index 2f2c51b2d894e8070e4e62e014acf438e4be12cb..7807e30fb2e32b1f83832233400d41304da2f3e9 100644 (file)
@@ -4995,8 +4995,8 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
           all-zero initializers (which aren't big enough to merit
           clearing), and don't try to make bitwise copies of
           TREE_ADDRESSABLE types.  */
-
        if (valid_const_initializer
+           && complete_p
            && !(cleared || num_nonzero_elements == 0)
            && !TREE_ADDRESSABLE (type))
          {
index 2ffa0f8f43416fcc429c7babe41f3246b5c146df..7f973949a7fd31cefdf55881110d4058e96b0fcb 100644 (file)
@@ -1,3 +1,7 @@
+2020-05-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/aggr29.adb: New test.
+
 2020-05-05  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/94949
diff --git a/gcc/testsuite/gnat.dg/aggr29.adb b/gcc/testsuite/gnat.dg/aggr29.adb
new file mode 100644 (file)
index 0000000..c82a6f4
--- /dev/null
@@ -0,0 +1,12 @@
+-- { dg-do compile }
+-- { dg-options "-fdump-tree-gimple" }
+
+with Ada.Streams; use Ada.Streams;
+
+procedure Aggr29 is
+  A : aliased Stream_Element_Array := (1 .. 512 => <>);
+begin
+  null;
+end;
+
+-- { dg-final { scan-tree-dump-not "a___UNC = \\*" "gimple" } }