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

            Bug ID: 118727
           Summary: [15 Regression] gcc.dg/pr108692.c fails on LoongArch
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

FAIL: gcc.dg/pr108692.c execution test

To satisfy the general policy of the GCC BugZilla, the test case is pasted:

/* PR tree-optimization/108692 */
/* { dg-do run } */
/* { dg-options "-O2 -ftree-vectorize" } */

__attribute__((noipa)) int
foo (signed char *x, signed char *y, int n)
{
  int i, r = 0;
  signed char a, b;
  for (i = 0; i < n; i++)
    {
      a = x[i];
      b = y[i];
      int c = (unsigned char) a - (unsigned char) b;
      r = r + (c < 0 ? -c : c);
    }
  return r;
}

int
main ()
{
  signed char x[64] = {}, y[64] = {};
  if (__CHAR_BIT__ != 8 || __SIZEOF_INT__ != 4)
    return 0;
  x[32] = -128;
  y[32] = 1;
  if (foo (x, y, 64) != 127)
    __builtin_abort ();
  return 0;
}

Things start to go wrong at 182t.vect:

  vect_b_16.19_88 = MEM <vector(16) signed char> [(signed char
*)vectp_y.17_86];
  vectp_y.17_89 = vectp_y.17_86 + 16; 
  vect_b_16.20_90 = MEM <vector(16) signed char> [(signed char
*)vectp_y.17_89];
  vectp_y.17_91 = vectp_y.17_86 + 32; 
  vect_b_16.21_92 = MEM <vector(16) signed char> [(signed char
*)vectp_y.17_91];
  vectp_y.17_93 = vectp_y.17_86 + 48; 
  vect_b_16.22_94 = MEM <vector(16) signed char> [(signed char
*)vectp_y.17_93];
  vect_patt_41.24_111 = SAD_EXPR <vect_a_14.13_79, vect_b_16.19_88,
vect_r_23.23_95>;
  vect_patt_41.24_112 = SAD_EXPR <vect_a_14.14_81, vect_b_16.20_90,
vect_r_23.23_96>;
  vect_patt_41.24_113 = SAD_EXPR <vect_a_14.15_83, vect_b_16.21_92,
vect_r_23.23_97>;
  vect_patt_41.24_114 = SAD_EXPR <vect_a_14.16_85, vect_b_16.22_94,
vect_r_23.23_98>;

so it's doing signed SAD operation, as unsigned SAD operation should be done.

In GCC 14.2 the result is correct, and 179t.vect is correctly doing unsigned
SAD operation:

  vect_a.18_84 = VIEW_CONVERT_EXPR<vector(16) unsigned char>(vect_a_14.14_80);
  a.0_4 = (unsigned char) a_14;
  _5 = (int) a.0_4;
  vect_b.19_85 = VIEW_CONVERT_EXPR<vector(16) unsigned char>(vect_b_16.17_83);
  b.1_6 = (unsigned char) b_16;
  _7 = (int) b.1_6;
  c_17 = _5 - _7;
  _8 = ABS_EXPR <c_17>;
  vect_patt_29.20_86 = SAD_EXPR <vect_a.18_84, vect_b.19_85, vect_r_23.11_77>;

Reply via email to