On Wed, 15 Jan 2025, Christoph Müllner wrote: > When extracting the amount of vector elements, we currently > first check if the value is a contant with is_constant(), > followed by obtaining the value with to_constant(), > which internally calls is_constant() again. > We can address this by using is_constant (T*), which also > provides the constant value.
OK. Thanks, Richard. > gcc/ChangeLog: > > * tree-ssa-forwprop.cc (recognise_vec_perm_simplify_seq): > Eliminate redundant calls to to_constant(). > > Signed-off-by: Christoph Müllner <christoph.muell...@vrull.eu> > --- > gcc/tree-ssa-forwprop.cc | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc > index 0d62f2bf60d..2f82f063388 100644 > --- a/gcc/tree-ssa-forwprop.cc > +++ b/gcc/tree-ssa-forwprop.cc > @@ -3530,6 +3530,8 @@ fwprop_ssa_val (tree name) > static bool > recognise_vec_perm_simplify_seq (gassign *stmt, vec_perm_simplify_seq *seq) > { > + unsigned HOST_WIDE_INT nelts; > + > gcc_checking_assert (stmt); > gcc_checking_assert (gimple_assign_rhs_code (stmt) == VEC_PERM_EXPR); > basic_block bb = gimple_bb (stmt); > @@ -3539,15 +3541,13 @@ recognise_vec_perm_simplify_seq (gassign *stmt, > vec_perm_simplify_seq *seq) > tree v_y = gimple_assign_rhs2 (stmt); > tree sel = gimple_assign_rhs3 (stmt); > > - if (!VECTOR_CST_NELTS (sel).is_constant () > + if (!VECTOR_CST_NELTS (sel).is_constant (&nelts) > || TREE_CODE (v_x) != SSA_NAME > || TREE_CODE (v_y) != SSA_NAME > || !has_single_use (v_x) > || !has_single_use (v_y)) > return false; > > - unsigned int nelts = VECTOR_CST_NELTS (sel).to_constant (); > - > /* Don't analyse sequences with many lanes. */ > if (nelts > 4) > return false; > @@ -3614,12 +3614,12 @@ recognise_vec_perm_simplify_seq (gassign *stmt, > vec_perm_simplify_seq *seq) > || v_in != gimple_assign_rhs2 (v_2_stmt)) > return false; > > - if (!VECTOR_CST_NELTS (v_1_sel).is_constant () > - || !VECTOR_CST_NELTS (v_2_sel).is_constant ()) > + unsigned HOST_WIDE_INT v_1_nelts, v_2_nelts; > + if (!VECTOR_CST_NELTS (v_1_sel).is_constant (&v_1_nelts) > + || !VECTOR_CST_NELTS (v_2_sel).is_constant (&v_2_nelts)) > return false; > > - if (nelts != VECTOR_CST_NELTS (v_1_sel).to_constant () > - || nelts != VECTOR_CST_NELTS (v_2_sel).to_constant ()) > + if (nelts != v_1_nelts || nelts != v_2_nelts) > return false; > > /* Create the new selector. */ > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)