[1/2] forwprop: Eliminate redundant calls to to_constant()

Message ID 20250115191740.1172965-1-christoph.muellner@vrull.eu
State Committed
Commit 57de373426e27395c0ef581c8a8300ec74c1bb59
Headers
Series [1/2] forwprop: Eliminate redundant calls to to_constant() |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Christoph Müllner Jan. 15, 2025, 7:17 p.m. UTC
  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.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (recognise_vec_perm_simplify_seq):
	Eliminate redundant calls to to_constant().

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
---
 gcc/tree-ssa-forwprop.cc | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
  

Comments

Richard Biener Jan. 16, 2025, 7:51 a.m. UTC | #1
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.muellner@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.  */
>
  

Patch

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.  */