]> git.ipfire.org Git - thirdparty/gcc.git/commit
Match: Support for signed scalar SAT_ADD IMM form 2
authorpanciyan <panciyan@eswincomputing.com>
Tue, 24 Jun 2025 01:28:49 +0000 (09:28 +0800)
committerxuli <xuli1@eswincomputing.com>
Fri, 4 Jul 2025 01:12:43 +0000 (01:12 +0000)
commit0662d721cfbe162a06645d94640a146d3912f554
treeafb904f7d4eb85336e9adc691c0eadb80e96ee47
parent1b403ba38b601d0bcb0ad5c38770da1941ac626e
Match: Support for signed scalar SAT_ADD IMM form 2

This patch would like to support signed scalar SAT_ADD IMM form 2

Form2:
T __attribute__((noinline))                                  \
sat_s_add_imm_##T##_fmt_2##_##INDEX (T x)                    \
{                                                            \
  T sum = (T)((UT)x + (UT)IMM);                                   \
  return ((x ^ sum) < 0 && (x ^ IMM) >= 0) ?                 \
    (-(T)(x < 0) ^ MAX) : sum;                         \
}

Take below form1 as example:
DEF_SAT_S_ADD_IMM_FMT_2(0, int8_t, uint8_t, 9, INT8_MIN, INT8_MAX)

Before this patch:
__attribute__((noinline))
int8_t sat_s_add_imm_int8_t_fmt_2_0 (int8_t x)
{
  int8_t sum;
  unsigned char x.0_1;
  unsigned char _2;
  signed char _3;
  signed char _4;
  _Bool _5;
  signed char _6;
  int8_t _7;
  int8_t _10;
  signed char _11;
  signed char _13;
  signed char _14;

  <bb 2> [local count: 1073741822]:
  x.0_1 = (unsigned char) x_8(D);
  _2 = x.0_1 + 9;
  sum_9 = (int8_t) _2;
  _3 = x_8(D) ^ sum_9;
  _4 = x_8(D) ^ 9;
  _13 = ~_3;
  _14 = _4 | _13;
  if (_14 >= 0)
    goto <bb 3>; [59.00%]
  else
    goto <bb 4>; [41.00%]

  <bb 3> [local count: 259738146]:
  _5 = x_8(D) < 0;
  _11 = (signed char) _5;
  _6 = -_11;
  _10 = _6 ^ 127;

  <bb 4> [local count: 1073741824]:
  # _7 = PHI <sum_9(2), _10(3)>
  return _7;

}

After this patch:
__attribute__((noinline))
int8_t sat_s_add_imm_int8_t_fmt_2_0 (int8_t x)
{
  int8_t _7;

  <bb 2> [local count: 1073741824]:
  _7 = .SAT_ADD (x_8(D), 9); [tail call]
  return _7;

}

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: Ciyan Pan <panciyan@eswincomputing.com>
gcc/ChangeLog:

* match.pd: Add signed scalar SAT_ADD IMM form2 matching.
gcc/match.pd