On 1/2/25 1:34 AM, Li Xu wrote:
From: xuli <xu...@eswincomputing.com>

This patch would like to support .SAT_ADD when IMM=-1.

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, -1, INT8_MIN, INT8_MAX)

Before this patch:
__attribute__((noinline))
int8_t sat_s_add_imm_int8_t_fmt_1_0 (int8_t x)
{
   unsigned char x.0_1;
   unsigned char _2;
   unsigned char _3;
   int8_t iftmp.1_4;
   signed char _8;
   unsigned char _9;
   signed char _10;

   <bb 2> [local count: 1073741824]:
   x.0_1 = (unsigned char) x_5(D);
   _3 = -x.0_1;
   _10 = (signed char) _3;
   _8 = x_5(D) & _10;
   if (_8 < 0)
     goto <bb 4>; [1.40%]
   else
     goto <bb 3>; [98.60%]

   <bb 3> [local count: 434070867]:
   _2 = x.0_1 + 255;

   <bb 4> [local count: 1073741824]:
   # _9 = PHI <_2(3), 128(2)>
   iftmp.1_4 = (int8_t) _9;
   return iftmp.1_4;

}

After this patch:
__attribute__((noinline))
int8_t sat_s_add_imm_int8_t_fmt_1_0 (int8_t x)
{
   int8_t _4;

   <bb 2> [local count: 1073741824]:
   gimple_call <.SAT_ADD, _4, x_5(D), 255> [tail call]
   gimple_return <_4>

}

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 <xu...@eswincomputing.com>

gcc/ChangeLog:

        * match.pd: Add signed scalar SAT_ADD IMM form1 with IMM=-1 matching.
        * tree-ssa-math-opts.cc (match_unsigned_saturation_add): Adapt function 
name.
        (match_saturation_add_with_assign): Match signed and unsigned SAT_ADD 
with assign.
        (math_opts_dom_walker::after_dom_children): Match imm=-1 signed SAT_ADD 
with NOP_EXPR case.
So is there anything special about the constant -1 that allows this to simplify in ways that don't work for other constants? If yes, then what is it? If not, then why are we treating -1 specially?

jeff

Reply via email to