diff options
author | xuli <xuli1@eswincomputing.com> | 2024-11-06 01:56:09 +0000 |
---|---|---|
committer | xuli <xuli1@eswincomputing.com> | 2024-11-07 01:51:34 +0000 |
commit | da31786910f253bba062d8f7126b269c432083ff (patch) | |
tree | e7bbc0b822e5cd97e4be354496e5f266e1eec9d5 /gcc/match.pd | |
parent | 693b7700a7daa10a446e708124fc0dc46b1d256b (diff) | |
download | gcc-da31786910f253bba062d8f7126b269c432083ff.zip gcc-da31786910f253bba062d8f7126b269c432083ff.tar.gz gcc-da31786910f253bba062d8f7126b269c432083ff.tar.bz2 |
Match:Support signed imm SAT_ADD form1
This patch would like to support .SAT_ADD when one of the op
is singed IMM.
Form1:
T __attribute__((noinline)) \
sat_s_add_imm_##T##_fmt_1##_##INDEX (T x) \
{ \
T sum = (UT)x + (UT)IMM; \
return (x ^ IMM) < 0 \
? sum \
: (sum ^ x) >= 0 \
? sum \
: x < 0 ? MIN : MAX; \
}
Take below form1 as example:
DEF_SAT_S_ADD_IMM_FMT_1(0, int8_t, uint8_t, -10, INT8_MIN, INT8_MAX)
Before this patch:
__attribute__((noinline))
int8_t sat_s_add_imm_int8_t_fmt_1_0 (int8_t x)
{
int8_t sum;
unsigned char x.0_1;
unsigned char _2;
signed char _4;
int8_t _5;
_Bool _9;
signed char _10;
signed char _11;
signed char _12;
signed char _14;
signed char _16;
<bb 2> [local count: 1073741824]:
x.0_1 = (unsigned char) x_6(D);
_2 = x.0_1 + 246;
sum_7 = (int8_t) _2;
_4 = x_6(D) ^ sum_7;
_16 = x_6(D) ^ 9;
_14 = _4 & _16;
if (_14 < 0)
goto <bb 3>; [41.00%]
else
goto <bb 4>; [59.00%]
<bb 3> [local count: 259738147]:
_9 = x_6(D) < 0;
_10 = (signed char) _9;
_11 = -_10;
_12 = _11 ^ 127;
<bb 4> [local count: 1073741824]:
# _5 = PHI <sum_7(2), _12(3)>
return _5;
}
After this patch:
__attribute__((noinline))
int8_t sat_s_add_imm_int8_t_fmt_1_0 (int8_t x)
{
int8_t _5;
<bb 2> [local count: 1073741824]:
_5 = .SAT_ADD (x_6(D), -10); [tail call]
return _5;
}
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.
Signed-off-by: Li Xu <xuli1@eswincomputing.com>
gcc/ChangeLog:
* match.pd: Add the form1 of signed imm .SAT_ADD matching.
* tree-ssa-math-opts.cc (match_saturation_add): Add fold
convert for const_int to the type of operand 0.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index c10bf9a..0098824 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3277,6 +3277,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) @2) (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)))) +/* Signed saturation add, case 6 (one op is imm): + T sum = (T)((UT)X + (UT)IMM); + SAT_S_ADD = (X ^ IMM) < 0 ? sum : (X ^ sum) >= 0 ? sum : (x < 0) ? MIN : MAX; + The T and UT are type pair like T=int8_t, UT=uint8_t. */ + +(match (signed_integer_sat_add @0 @1) +(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) @2) +(if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type) + && wi::bit_and (wi::to_wide (@1), wi::to_wide (@3)) == 0))) + /* Unsigned saturation sub, case 1 (branch with gt): SAT_U_SUB = X > Y ? X - Y : 0 */ (match (unsigned_integer_sat_sub @0 @1) |