]> git.ipfire.org Git - thirdparty/gcc.git/commit
middle-end: refactory vect_recog_absolute_difference to simplify flow [PR114769]
authorTamar Christina <tamar.christina@arm.com>
Fri, 19 Apr 2024 14:22:13 +0000 (15:22 +0100)
committerTamar Christina <tamar.christina@arm.com>
Fri, 19 Apr 2024 14:22:13 +0000 (15:22 +0100)
commit1216460e7023cd8ec49933866107417c70e933c9
tree31fc8d36b5804f0ea38cc451d0909fa018800e52
parent9451b6c0a941dc44ca6f14ff8565d74fe56cca59
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.
gcc/tree-vect-patterns.cc