diff mbox series

[v1,2/4] Vect: Try the pattern of vector signed integer SAT_SUB

Message ID 20241011062245.2486653-2-pan2.li@intel.com
State New
Headers show
Series [v1,1/4] Match: Support form 1 for vector signed integer SAT_SUB | expand

Commit Message

Li, Pan2 Oct. 11, 2024, 6:22 a.m. UTC
From: Pan Li <pan2.li@intel.com>

Almost the same as vector unsigned integer SAT_SUB, try to match
the signed version during the vector pattern matching.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

	* tree-vect-patterns.cc (gimple_signed_integer_sat_sub): Add new
	func decl for signed SAT_SUB.
	(vect_recog_sat_sub_pattern_transform): Update comments.
	(vect_recog_sat_sub_pattern): Try the vector signed SAT_SUB
	pattern.

Signed-off-by: Pan Li <pan2.li@intel.com>
---
 gcc/tree-vect-patterns.cc | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

Comments

Richard Biener Oct. 11, 2024, 9:10 a.m. UTC | #1
On Fri, Oct 11, 2024 at 8:24 AM <pan2.li@intel.com> wrote:
>
> From: Pan Li <pan2.li@intel.com>
>
> Almost the same as vector unsigned integer SAT_SUB, try to match
> the signed version during the vector pattern matching.
>
> The below test suites are passed for this patch.
> * The rv64gcv fully regression test.
> * The x86 bootstrap test.
> * The x86 fully regression test.

OK.

> gcc/ChangeLog:
>
>         * tree-vect-patterns.cc (gimple_signed_integer_sat_sub): Add new
>         func decl for signed SAT_SUB.
>         (vect_recog_sat_sub_pattern_transform): Update comments.
>         (vect_recog_sat_sub_pattern): Try the vector signed SAT_SUB
>         pattern.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/tree-vect-patterns.cc | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
> index 9bf8526ac99..746f100a084 100644
> --- a/gcc/tree-vect-patterns.cc
> +++ b/gcc/tree-vect-patterns.cc
> @@ -4538,6 +4538,7 @@ extern bool gimple_unsigned_integer_sat_sub (tree, tree*, tree (*)(tree));
>  extern bool gimple_unsigned_integer_sat_trunc (tree, tree*, tree (*)(tree));
>
>  extern bool gimple_signed_integer_sat_add (tree, tree*, tree (*)(tree));
> +extern bool gimple_signed_integer_sat_sub (tree, tree*, tree (*)(tree));
>
>  static gimple *
>  vect_recog_build_binary_gimple_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
> @@ -4684,6 +4685,7 @@ vect_recog_sat_sub_pattern_transform (vec_info *vinfo,
>
>  /*
>   * Try to detect saturation sub pattern (SAT_ADD), aka below gimple:
> + * Unsigned:
>   *   _7 = _1 >= _2;
>   *   _8 = _1 - _2;
>   *   _10 = (long unsigned int) _7;
> @@ -4691,6 +4693,27 @@ vect_recog_sat_sub_pattern_transform (vec_info *vinfo,
>   *
>   * And then simplied to
>   *   _9 = .SAT_SUB (_1, _2);
> + *
> + * Signed:
> + *   x.0_4 = (unsigned char) x_16;
> + *   y.1_5 = (unsigned char) y_18;
> + *   _6 = x.0_4 - y.1_5;
> + *   minus_19 = (int8_t) _6;
> + *   _7 = x_16 ^ y_18;
> + *   _8 = x_16 ^ minus_19;
> + *   _44 = _7 < 0;
> + *   _23 = x_16 < 0;
> + *   _24 = (signed char) _23;
> + *   _58 = (unsigned char) _24;
> + *   _59 = -_58;
> + *   _25 = (signed char) _59;
> + *   _26 = _25 ^ 127;
> + *   _42 = _8 < 0;
> + *   _41 = _42 & _44;
> + *   iftmp.2_11 = _41 ? _26 : minus_19;
> + *
> + * And then simplied to
> + *   iftmp.2_11 = .SAT_SUB (x_16, y_18);
>   */
>
>  static gimple *
> @@ -4705,7 +4728,8 @@ vect_recog_sat_sub_pattern (vec_info *vinfo, stmt_vec_info stmt_vinfo,
>    tree ops[2];
>    tree lhs = gimple_assign_lhs (last_stmt);
>
> -  if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL))
> +  if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL)
> +      || gimple_signed_integer_sat_sub (lhs, ops, NULL))
>      {
>        vect_recog_sat_sub_pattern_transform (vinfo, stmt_vinfo, lhs, ops);
>        gimple *stmt = vect_recog_build_binary_gimple_stmt (vinfo, stmt_vinfo,
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 9bf8526ac99..746f100a084 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -4538,6 +4538,7 @@  extern bool gimple_unsigned_integer_sat_sub (tree, tree*, tree (*)(tree));
 extern bool gimple_unsigned_integer_sat_trunc (tree, tree*, tree (*)(tree));
 
 extern bool gimple_signed_integer_sat_add (tree, tree*, tree (*)(tree));
+extern bool gimple_signed_integer_sat_sub (tree, tree*, tree (*)(tree));
 
 static gimple *
 vect_recog_build_binary_gimple_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
@@ -4684,6 +4685,7 @@  vect_recog_sat_sub_pattern_transform (vec_info *vinfo,
 
 /*
  * Try to detect saturation sub pattern (SAT_ADD), aka below gimple:
+ * Unsigned:
  *   _7 = _1 >= _2;
  *   _8 = _1 - _2;
  *   _10 = (long unsigned int) _7;
@@ -4691,6 +4693,27 @@  vect_recog_sat_sub_pattern_transform (vec_info *vinfo,
  *
  * And then simplied to
  *   _9 = .SAT_SUB (_1, _2);
+ *
+ * Signed:
+ *   x.0_4 = (unsigned char) x_16;
+ *   y.1_5 = (unsigned char) y_18;
+ *   _6 = x.0_4 - y.1_5;
+ *   minus_19 = (int8_t) _6;
+ *   _7 = x_16 ^ y_18;
+ *   _8 = x_16 ^ minus_19;
+ *   _44 = _7 < 0;
+ *   _23 = x_16 < 0;
+ *   _24 = (signed char) _23;
+ *   _58 = (unsigned char) _24;
+ *   _59 = -_58;
+ *   _25 = (signed char) _59;
+ *   _26 = _25 ^ 127;
+ *   _42 = _8 < 0;
+ *   _41 = _42 & _44;
+ *   iftmp.2_11 = _41 ? _26 : minus_19;
+ *
+ * And then simplied to
+ *   iftmp.2_11 = .SAT_SUB (x_16, y_18);
  */
 
 static gimple *
@@ -4705,7 +4728,8 @@  vect_recog_sat_sub_pattern (vec_info *vinfo, stmt_vec_info stmt_vinfo,
   tree ops[2];
   tree lhs = gimple_assign_lhs (last_stmt);
 
-  if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL))
+  if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL)
+      || gimple_signed_integer_sat_sub (lhs, ops, NULL))
     {
       vect_recog_sat_sub_pattern_transform (vinfo, stmt_vinfo, lhs, ops);
       gimple *stmt = vect_recog_build_binary_gimple_stmt (vinfo, stmt_vinfo,