diff mbox series

Add an empty constructor shortcut to build_vector_from_ctor

Message ID mptlfsgylh9.fsf@arm.com
State New
Headers show
Series Add an empty constructor shortcut to build_vector_from_ctor | expand

Commit Message

Richard Sandiford Nov. 16, 2019, 1:55 p.m. UTC
Empty vector constructors are equivalent to zero vectors.  If we handle
that case directly, we can support it for variable-length vectors and
can hopefully make things more efficient for fixed-length vectors.

This is needed by a later C++ patch.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-11-16  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* tree.c (build_vector_from_ctor): Directly return a zero vector for
	empty constructors.

Comments

Jeff Law Nov. 16, 2019, 2:36 p.m. UTC | #1
On 11/16/19 6:55 AM, Richard Sandiford wrote:
> Empty vector constructors are equivalent to zero vectors.  If we handle
> that case directly, we can support it for variable-length vectors and
> can hopefully make things more efficient for fixed-length vectors.
> 
> This is needed by a later C++ patch.
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-11-16  Richard Sandiford  <richard.sandiford@arm.com>
> 
> gcc/
> 	* tree.c (build_vector_from_ctor): Directly return a zero vector for
> 	empty constructors.
OK
jeff
diff mbox series

Patch

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	2019-11-14 14:55:04.415447600 +0000
+++ gcc/tree.c	2019-11-16 13:53:28.609006588 +0000
@@ -1858,6 +1858,9 @@  make_vector (unsigned log2_npatterns,
 tree
 build_vector_from_ctor (tree type, vec<constructor_elt, va_gc> *v)
 {
+  if (vec_safe_length (v) == 0)
+    return build_zero_cst (type);
+
   unsigned HOST_WIDE_INT idx, nelts;
   tree value;