diff options
author | Pan Li <pan2.li@intel.com> | 2024-12-12 10:48:08 +0800 |
---|---|---|
committer | Pan Li <pan2.li@intel.com> | 2025-01-08 07:35:43 +0800 |
commit | cfe45ab382488313d8635ccaac970a11891a2c8c (patch) | |
tree | c4ae57902859d52284f9d3c7681a8c6fd86fd310 | |
parent | d20e9b7b5a4dd99f0486d2b0a946208a9563e196 (diff) | |
download | gcc-cfe45ab382488313d8635ccaac970a11891a2c8c.zip gcc-cfe45ab382488313d8635ccaac970a11891a2c8c.tar.gz gcc-cfe45ab382488313d8635ccaac970a11891a2c8c.tar.bz2 |
Match: Refactor the signed SAT_* match for saturated value [NFC]
This patch would like to refactor the all signed SAT_* patterns for
the saturated value. Aka, overflow to INT_MAX when > 0 and downflow
to INT_MIN when < 0. Thus, we can remove sorts of duplicated expression
in different patterns.
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:
* match.pd: Extract saturated value match for signed SAT_*.
Signed-off-by: Pan Li <pan2.li@intel.com>
-rw-r--r-- | gcc/match.pd | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 8b72eaf..cb48c8c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3331,6 +3331,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (wi::eq_p (trunc_max, int_cst_1) && wi::eq_p (max, int_cst_2))))))) (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)) + /* SAT_VAL = (-(T)(X < 0) ^ MAX) */ + (match (signed_integer_sat_val @0) + (bit_xor:c (nop_convert? (negate + (nop_convert? (convert (lt @0 integer_zerop))))) + max_value))) + +(if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)) (match (signed_integer_sat_add @0 @1) /* T SUM = (T)((UT)X + (UT)Y) SAT_S_ADD = (X ^ SUM) & !(X ^ Y) < 0 ? (-(T)(X < 0) ^ MAX) : SUM */ @@ -3338,7 +3345,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (nop_convert @1)))) (bit_not (bit_xor:c @0 @1))) integer_zerop) - (bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value) + (signed_integer_sat_val @0) @2)) (match (signed_integer_sat_add @0 @1) /* T SUM = (T)((UT)X + (UT)Y) @@ -3356,17 +3363,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (nop_convert @1)))) integer_zerop) (ge (bit_xor:c @0 @1) integer_zerop)) - (bit_xor:c (nop_convert (negate (nop_convert (convert - (lt @0 integer_zerop))))) - max_value) + (signed_integer_sat_val @0) @2)) (match (signed_integer_sat_add @0 @1) /* SUM = .ADD_OVERFLOW (X, Y) SAT_S_ADD = IMAGPART_EXPR (SUM) != 0 ? (-(T)(X < 0) ^ MAX) : SUM */ (cond^ (ne (imagpart (IFN_ADD_OVERFLOW:c@2 @0 @1)) integer_zerop) - (bit_xor:c (nop_convert? - (negate (nop_convert? (convert (lt @0 integer_zerop))))) - max_value) + (signed_integer_sat_val @0) (realpart @2))) (match (signed_integer_sat_add @0 @1) /* T SUM = (T)((UT)X + (UT)Y) @@ -3375,9 +3378,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (nop_convert @1)))) integer_zerop) (bit_not (lt (bit_xor:c @0 @1) integer_zerop))) - (bit_xor:c (nop_convert (negate (nop_convert (convert - (lt @0 integer_zerop))))) - max_value) + (signed_integer_sat_val @0) @2)) (match (signed_integer_sat_add @0 @1) /* T SUM = (T)((UT)X + (UT)IMM); @@ -3386,10 +3387,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond^ (lt (bit_and:c (bit_xor:c @0 (nop_convert@2 (plus (nop_convert @0) INTEGER_CST@1))) (bit_xor:c @0 INTEGER_CST@3)) integer_zerop) - (bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value) + (signed_integer_sat_val @0) @2) - (if (wi::bit_and (wi::to_wide (@1), wi::to_wide (@3)) == 0))) -) + (if (wi::bit_and (wi::to_wide (@1), wi::to_wide (@3)) == 0)))) (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)) (match (signed_integer_sat_sub @0 @1) @@ -3399,7 +3399,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_xor @0 (nop_convert@2 (minus (nop_convert @0) (nop_convert @1))))) integer_zerop) - (bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value) + (signed_integer_sat_val @0) @2)) (match (signed_integer_sat_sub @0 @1) /* T Z = (T)((UT)X - (UT)Y); @@ -3409,7 +3409,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (nop_convert @1))))) integer_zerop) @2 - (bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value))) + (signed_integer_sat_val @0))) (match (signed_integer_sat_sub @0 @1) /* T Z = (T)((UT)X - (UT)Y); SAT_S_SUB = (X ^ Y) < 0 & (X ^ Z) < 0 ? (-(T)(X < 0) ^ MAX) : Z */ @@ -3417,17 +3417,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (nop_convert @1)))) integer_zerop) (lt (bit_xor:c @0 @1) integer_zerop)) - (bit_xor:c (nop_convert (negate (nop_convert (convert - (lt @0 integer_zerop))))) - max_value) + (signed_integer_sat_val @0) @2)) (match (signed_integer_sat_sub @0 @1) /* Z = .SUB_OVERFLOW (X, Y) SAT_S_SUB = IMAGPART (Z) != 0 ? (-(T)(X < 0) ^ MAX) : REALPART (Z) */ (cond^ (ne (imagpart (IFN_SUB_OVERFLOW@2 @0 @1)) integer_zerop) - (bit_xor:c (nop_convert? - (negate (nop_convert? (convert (lt @0 integer_zerop))))) - max_value) + (signed_integer_sat_val @0) (realpart @2)) (if (types_match (type, @0, @1))))) |