diff mbox series

[v2,05/10] Match: Update the comments of unsigned integer SAT_ADD [NFC]

Message ID 20241031062742.2709845-5-pan2.li@intel.com
State New
Headers show
Series [v2,01/10] Match: Simplify branch form 4 of unsigned SAT_ADD into branchless | expand

Commit Message

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

Sorts of comments of unsigned integer SAT_ADD matching is not updated
to date.  This patch would like to refine it.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

gcc/ChangeLog:

	* match.pd: Update the comments of unsigned integer SAT_ADD.

Signed-off-by: Pan Li <pan2.li@intel.com>
---
 gcc/match.pd | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 94e9f094631..f6f55491b89 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3086,36 +3086,39 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        || POINTER_TYPE_P (itype))
       && wi::eq_p (wi::to_wide (int_cst), wi::max_value (itype))))))
 
-/* SAT_ADD = usadd_left_part_2 | usadd_right_part_2, aka:
-   SAT_ADD = REALPART_EXPR <.ADD_OVERFLOW> | (IMAGPART_EXPR <.ADD_OVERFLOW> != 0) */
+/* SAT_U_ADD = usadd_left_part_2 | usadd_right_part_2, aka:
+   SUM = ADD_OVERFLOW (X, Y)
+   SAT_U_ADD = REALPART_EXPR (SUM) | (IMAGPART_EXPR (SUM) != 0) */
 (match (usadd_left_part_2 @0 @1)
  (realpart (IFN_ADD_OVERFLOW:c @0 @1))
  (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
       && types_match (type, @0, @1))))
 
-/* SAT_ADD = (X + Y) | usadd_right_part_1, aka:
-   SAT_ADD = (X + Y) | -((type)(X + Y) < X)  */
+/* SAT_U_ADD = (X + Y) | usadd_right_part_1, aka:
+   SAT_U_ADD = (X + Y) | -((type)(X + Y) < X)  */
 (match (usadd_right_part_1 @0 @1)
  (negate (convert (lt (plus:c @0 @1) @0)))
  (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
       && types_match (type, @0, @1))))
 
-/* SAT_ADD = usadd_left_part_1 | usadd_right_part_1, aka:
-   SAT_ADD = (X + Y) | -(X > (X + Y))  */
+/* SAT_U_ADD = usadd_left_part_1 | usadd_right_part_1, aka:
+   SAT_U_ADD = (X + Y) | -(X > (X + Y))  */
 (match (usadd_right_part_1 @0 @1)
  (negate (convert (gt @0 (plus:c @0 @1))))
  (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
       && types_match (type, @0, @1))))
 
-/* SAT_ADD = usadd_left_part_2 | usadd_right_part_2, aka:
-   SAT_ADD = REALPART_EXPR <.ADD_OVERFLOW> | (IMAGPART_EXPR <.ADD_OVERFLOW> != 0) */
+/* SAT_U_ADD = usadd_left_part_2 | usadd_right_part_2, aka:
+   SUM = ADD_OVERFLOW (X, Y)
+   SAT_U_ADD = REALPART_EXPR (SUM) | (IMAGPART_EXPR (SUM) != 0) */
 (match (usadd_right_part_2 @0 @1)
  (negate (convert (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zerop)))
  (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
       && types_match (type, @0, @1))))
 
-/* SAT_ADD = usadd_left_part_2 | usadd_right_part_2, aka:
-   SAT_ADD = REALPART_EXPR <.ADD_OVERFLOW> | -IMAGPART_EXPR <.ADD_OVERFLOW> */
+/* SAT_U_ADD = usadd_left_part_2 | usadd_right_part_2, aka:
+   SUM = ADD_OVERFLOW (X, Y)
+   SAT_U_ADD = REALPART_EXPR (SUM) | -IMAGPART_EXPR (SUM) */
 (match (usadd_right_part_2 @0 @1)
  (negate (imagpart (IFN_ADD_OVERFLOW:c @0 @1)))
  (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
@@ -3133,8 +3136,9 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_ior:c (plus:c @0 @1) (usadd_right_part_1 @0 @1)))
 
 /* Unsigned saturation add, case 2 (branchless with .ADD_OVERFLOW):
-   SAT_ADD = REALPART_EXPR <.ADD_OVERFLOW> | -IMAGPART_EXPR <.ADD_OVERFLOW> or
-   SAT_ADD = REALPART_EXPR <.ADD_OVERFLOW> | (IMAGPART_EXPR <.ADD_OVERFLOW> != 0) */
+   SUM = ADD_OVERFLOW (X, Y)
+   SAT_U_ADD = REALPART_EXPR (SUM) | -IMAGPART_EXPR (SUM) or
+   SAT_U_ADD = REALPART_EXPR (SUM) | (IMAGPART_EXPR (SUM) != 0).  */
 (match (unsigned_integer_sat_add @0 @1)
  (bit_ior:c (usadd_left_part_2 @0 @1) (usadd_right_part_2 @0 @1)))
 
@@ -3159,13 +3163,15 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (bit_ior (plus@2 @0 @1) (negate (convert (lt @2 @0)))))))
 
 /* Unsigned saturation add, case 5 (branch with eq .ADD_OVERFLOW):
-   SAT_U_ADD = REALPART_EXPR <.ADD_OVERFLOW> == 0 ? .ADD_OVERFLOW : -1.  */
+   SUM = ADD_OVERFLOW (X, Y)
+   SAT_U_ADD = IMAGPART_EXPR (SUM) == 0 ? REALPART_EXPR (SUM) : -1.  */
 (match (unsigned_integer_sat_add @0 @1)
  (cond^ (eq (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zerop)
   (usadd_left_part_2 @0 @1) integer_minus_onep))
 
 /* Unsigned saturation add, case 6 (branch with ne .ADD_OVERFLOW):
-   SAT_U_ADD = REALPART_EXPR <.ADD_OVERFLOW> != 0 ? -1 : .ADD_OVERFLOW.  */
+   SUM = ADD_OVERFLOW (X, Y)
+   SAT_U_ADD = IMAGPART_EXPR (SUM) != 0 ? -1 : REALPART_EXPR (SUM).  */
 (match (unsigned_integer_sat_add @0 @1)
  (cond^ (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zerop)
   integer_minus_onep (usadd_left_part_2 @0 @1)))
@@ -3187,7 +3193,8 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (if (wi::eq_p (max, sum))))))
 
 /* Unsigned saturation add, case 10 (one op is imm):
-   SAT_U_ADD = __builtin_add_overflow (X, 3, &ret) == 0 ? ret : -1.  */
+   SUM = ADD_OVERFLOW (X, IMM)
+   SAT_U_ADD = IMAGPART_EXPR (SUM) == 0 ? REALPART_EXPR (SUM) : -1.  */
 (match (unsigned_integer_sat_add @0 @1)
  (cond^ (ne (imagpart (IFN_ADD_OVERFLOW@2 @0 INTEGER_CST@1)) integer_zerop)
   integer_minus_onep (realpart @2))