public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-10040] middle-end: refactory vect_recog_absolute_difference to simplify flow [PR114769]
@ 2024-04-19 14:25 Tamar Christina
  0 siblings, 0 replies; only message in thread
From: Tamar Christina @ 2024-04-19 14:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1216460e7023cd8ec49933866107417c70e933c9

commit r14-10040-g1216460e7023cd8ec49933866107417c70e933c9
Author: Tamar Christina <tamar.christina@arm.com>
Date:   Fri Apr 19 15:22:13 2024 +0100

    middle-end: refactory vect_recog_absolute_difference to simplify flow [PR114769]
    
    Hi All,
    
    As the reporter in PR114769 points out the control flow for the abd detection
    is hard to follow.  This is because vect_recog_absolute_difference has two
    different ways it can return true.
    
    1. It can return true when the widening operation is matched, in which case
       unprom is set, half_type is not NULL and diff_stmt is not set.
    
    2. It can return true when the widening operation is not matched, but the stmt
       being checked is a minus.  In this case unprom is not set, half_type is set
       to NULL and diff_stmt is set.  This because to get to diff_stmt you have to
       dig through the abs statement and any possible promotions.
    
    This however leads to complicated uses of the function at the call sites as the
    exact semantic needs to be known to use it safely.
    
    vect_recog_absolute_difference has two callers:
    
    1. vect_recog_sad_pattern where if you return true with unprom not set, then
       *half_type will be NULL.  The call to vect_supportable_direct_optab_p will
       always reject it since there's no vector mode for NULL.  Note that if looking
       at the dump files, the convention in the dump files have always been that we
       first indicate that a pattern could possibly be recognize and then check that
       it's supported.
    
       This change somewhat incorrectly makes the diagnostic message get printed for
       "invalid" patterns.
    
    2. vect_recog_abd_pattern, where if half_type is NULL, it then uses diff_stmt to
       set them.
    
    This refactors the code, it now only has 1 success condition, and diff_stmt is
    always set to the minus statement in the abs if there is one.
    
    The function now only returns success if the widening minus is found, in which
    case unprom and half_type set.
    
    This then leaves it up to the caller to decide if they want to do anything with
    diff_stmt.
    
    Thanks,
    Tamar
    
    gcc/ChangeLog:
    
            PR tree-optimization/114769
            * tree-vect-patterns.cc:
            (vect_recog_absolute_difference): Have only one success condition.
            (vect_recog_abd_pattern): Handle further checks if
            vect_recog_absolute_difference fails.

Diff:
---
 gcc/tree-vect-patterns.cc | 43 ++++++++++++++++---------------------------
 1 file changed, 16 insertions(+), 27 deletions(-)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 4f491c6b833..87c2acff386 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -797,8 +797,7 @@ vect_split_statement (vec_info *vinfo, stmt_vec_info stmt2_info, tree new_rhs,
    HALF_TYPE and UNPROM will be set should the statement be found to
    be a widened operation.
    DIFF_STMT will be set to the MINUS_EXPR
-   statement that precedes the ABS_STMT unless vect_widened_op_tree
-   succeeds.
+   statement that precedes the ABS_STMT if it is a MINUS_EXPR..
  */
 static bool
 vect_recog_absolute_difference (vec_info *vinfo, gassign *abs_stmt,
@@ -843,6 +842,12 @@ vect_recog_absolute_difference (vec_info *vinfo, gassign *abs_stmt,
   if (!diff_stmt_vinfo)
     return false;
 
+  gassign *diff = dyn_cast <gassign *> (STMT_VINFO_STMT (diff_stmt_vinfo));
+  if (diff_stmt && diff
+      && gimple_assign_rhs_code (diff) == MINUS_EXPR
+      && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (abs_oprnd)))
+    *diff_stmt = diff;
+
   /* FORNOW.  Can continue analyzing the def-use chain when this stmt in a phi
      inside the loop (in case we are analyzing an outer-loop).  */
   if (vect_widened_op_tree (vinfo, diff_stmt_vinfo,
@@ -850,17 +855,6 @@ vect_recog_absolute_difference (vec_info *vinfo, gassign *abs_stmt,
 			    false, 2, unprom, half_type))
     return true;
 
-  /* Failed to find a widen operation so we check for a regular MINUS_EXPR.  */
-  gassign *diff = dyn_cast <gassign *> (STMT_VINFO_STMT (diff_stmt_vinfo));
-  if (diff_stmt && diff
-      && gimple_assign_rhs_code (diff) == MINUS_EXPR
-      && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (abs_oprnd)))
-    {
-      *diff_stmt = diff;
-      *half_type = NULL_TREE;
-      return true;
-    }
-
   return false;
 }
 
@@ -1499,27 +1493,22 @@ vect_recog_abd_pattern (vec_info *vinfo,
   tree out_type = TREE_TYPE (gimple_assign_lhs (last_stmt));
 
   vect_unpromoted_value unprom[2];
-  gassign *diff_stmt;
-  tree half_type;
-  if (!vect_recog_absolute_difference (vinfo, last_stmt, &half_type,
+  gassign *diff_stmt = NULL;
+  tree abd_in_type;
+  if (!vect_recog_absolute_difference (vinfo, last_stmt, &abd_in_type,
 				       unprom, &diff_stmt))
-    return NULL;
-
-  tree abd_in_type, abd_out_type;
-
-  if (half_type)
-    {
-      abd_in_type = half_type;
-      abd_out_type = abd_in_type;
-    }
-  else
     {
+      /* We cannot try further without having a non-widening MINUS.  */
+      if (!diff_stmt)
+	return NULL;
+
       unprom[0].op = gimple_assign_rhs1 (diff_stmt);
       unprom[1].op = gimple_assign_rhs2 (diff_stmt);
       abd_in_type = signed_type_for (out_type);
-      abd_out_type = abd_in_type;
     }
 
+  tree abd_out_type = abd_in_type;
+
   tree vectype_in = get_vectype_for_scalar_type (vinfo, abd_in_type);
   if (!vectype_in)
     return NULL;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-19 14:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 14:25 [gcc r14-10040] middle-end: refactory vect_recog_absolute_difference to simplify flow [PR114769] Tamar Christina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).