https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123916

            Bug ID: 123916
           Summary: [RISC-V] Failed to vectorize due to forget to pick
                    value from --param=gpr2vr-cost
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pan2.li at intel dot com
  Target Milestone: ---

Assume we have sample code as below, it fails to vectorize when gpr2vr-cost=0
after the middle-end introduced the slp_node and vectype in
record_stmt_cost(which is dropped in previous). The root cause is that the
value of gpr2vr-cost is not well picked up in some places, and finally result
in the cost of vectorize is bigger than scalar.

I am preparing a fix, and will send it out if no surprise from test.

-------- sample code ----------

#include <stdint.h>

#define T int32_t
#define UT uint32_t

T
test_sat_add (T x, T y)
{
  T sum = (UT)x + (UT)y;
  return (x ^ y) < 0
    ? sum
    : (sum ^ x) >= 0
      ? sum
      : x < 0 ? INT32_MIN : INT32_MAX;
}

void
test_vx_binary_sat_add (T * restrict out, T * restrict in, T x, unsigned n)
{
  unsigned k = 0;
  T tmp = x + 3;

  while (k < n)
    {
      tmp = tmp ^ 0x82;
      out[k + 0] = test_sat_add (in[k + 0], tmp);
      out[k + 1] = test_sat_add (in[k + 1], tmp);
      k += 2;

      out[k + 0] = test_sat_add (in[k + 0], tmp);
      out[k + 1] = test_sat_add (in[k + 1], tmp);
      k += 2;

      out[k + 0] = test_sat_add (in[k + 0], tmp);
      out[k + 1] = test_sat_add (in[k + 1], tmp);
      k += 2;

      out[k + 0] = test_sat_add (in[k + 0], tmp);
      out[k + 1] = test_sat_add (in[k + 1], tmp);
      k += 2;
    }
}

Reply via email to