use *_grow_cleared rather than *_grow on vect_unpromoted_value

Message ID ZRaRXvGWkoPufmly@tucnak
State Unresolved
Headers
Series use *_grow_cleared rather than *_grow on vect_unpromoted_value |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Sept. 29, 2023, 8:57 a.m. UTC
  On Wed, Sep 27, 2023 at 11:15:26AM +0000, Richard Biener wrote:
> > tree-vect-patterns.cc:2947  unprom.quick_grow (nops);
> > T = vect_unpromoted_value
> > Go for quick_grow_cleared?  Something else?
> 
> The CTOR zero-initializes everything, so maybe it can go.  In theory
> .set_op could also be changed to .push_op ...

So, I had a look at this and I think using quick_grow_cleared is best choice
here.  The nops is 2 or 1 most of the time, worst case 3, so the price of
extra initialization of 4 pointer-sized-or-less members times 1, 2 or 3
doesn't seem worth bothering, it is similar to the bitmap_head case where
we already pay the price for just one structure anytime we do
  vect_unpromoted_value unprom_diff;
(and later set_op on it) or even
  vect_unpromoted_value unprom0[2];

With this patch and Richard S's poly_int_pod removal the static_assert can
be enabled as well and gcc builds.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

The second patch waits for the poly_int_pod removal commit and has been just
build tested but not bootstrapped yet.

2023-09-29  Jakub Jelinek  <jakub@redhat.com>

	* tree-vect-patterns.cc (vect_recog_over_widening_pattern): Use
	quick_grow_cleared method on unprom rather than quick_grow.



	Jakub
2023-09-29  Jakub Jelinek  <jakub@redhat.com>

	* vec.h (quick_grow): Uncomment static_assert.

--- gcc/vec.h.jj	2023-09-29 10:39:09.327223861 +0200
+++ gcc/vec.h	2023-09-29 10:44:03.764108443 +0200
@@ -1396,7 +1396,7 @@ inline void
 vec<T, A, vl_embed>::quick_grow (unsigned len)
 {
   gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc);
-//  static_assert (std::is_trivially_default_constructible <T>::value, "");
+  static_assert (std::is_trivially_default_constructible <T>::value, "");
   m_vecpfx.m_num = len;
 }
  

Comments

Richard Biener Sept. 29, 2023, 9:13 a.m. UTC | #1
On Fri, 29 Sep 2023, Jakub Jelinek wrote:

> On Wed, Sep 27, 2023 at 11:15:26AM +0000, Richard Biener wrote:
> > > tree-vect-patterns.cc:2947  unprom.quick_grow (nops);
> > > T = vect_unpromoted_value
> > > Go for quick_grow_cleared?  Something else?
> > 
> > The CTOR zero-initializes everything, so maybe it can go.  In theory
> > .set_op could also be changed to .push_op ...
> 
> So, I had a look at this and I think using quick_grow_cleared is best choice
> here.  The nops is 2 or 1 most of the time, worst case 3, so the price of
> extra initialization of 4 pointer-sized-or-less members times 1, 2 or 3
> doesn't seem worth bothering, it is similar to the bitmap_head case where
> we already pay the price for just one structure anytime we do
>   vect_unpromoted_value unprom_diff;
> (and later set_op on it) or even
>   vect_unpromoted_value unprom0[2];
> 
> With this patch and Richard S's poly_int_pod removal the static_assert can
> be enabled as well and gcc builds.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> The second patch waits for the poly_int_pod removal commit and has been just
> build tested but not bootstrapped yet.
> 
> 2023-09-29  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* tree-vect-patterns.cc (vect_recog_over_widening_pattern): Use
> 	quick_grow_cleared method on unprom rather than quick_grow.
> 
> --- gcc/tree-vect-patterns.cc.jj	2023-08-24 15:37:29.321410276 +0200
> +++ gcc/tree-vect-patterns.cc	2023-09-29 09:45:27.980168865 +0200
> @@ -2944,7 +2944,7 @@ vect_recog_over_widening_pattern (vec_in
>    /* Check the operands.  */
>    unsigned int nops = gimple_num_ops (last_stmt) - first_op;
>    auto_vec <vect_unpromoted_value, 3> unprom (nops);
> -  unprom.quick_grow (nops);
> +  unprom.quick_grow_cleared (nops);
>    unsigned int min_precision = 0;
>    bool single_use_p = false;
>    for (unsigned int i = 0; i < nops; ++i)
> 
> 
> 	Jakub
>
  

Patch

--- gcc/tree-vect-patterns.cc.jj	2023-08-24 15:37:29.321410276 +0200
+++ gcc/tree-vect-patterns.cc	2023-09-29 09:45:27.980168865 +0200
@@ -2944,7 +2944,7 @@  vect_recog_over_widening_pattern (vec_in
   /* Check the operands.  */
   unsigned int nops = gimple_num_ops (last_stmt) - first_op;
   auto_vec <vect_unpromoted_value, 3> unprom (nops);
-  unprom.quick_grow (nops);
+  unprom.quick_grow_cleared (nops);
   unsigned int min_precision = 0;
   bool single_use_p = false;
   for (unsigned int i = 0; i < nops; ++i)