]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
forwprop: Eliminate redundant calls to to_constant()
authorChristoph Müllner <christoph.muellner@vrull.eu>
Wed, 15 Jan 2025 13:53:27 +0000 (14:53 +0100)
committerChristoph Müllner <christoph.muellner@vrull.eu>
Thu, 16 Jan 2025 08:51:12 +0000 (09:51 +0100)
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

index 0d62f2bf60db029799712b744c70c4a1714494d2..2f82f0633883647ab28d6bd8e5869758d4e61639 100644 (file)
@@ -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.  */