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

            Bug ID: 125260
           Summary: New signed overflow introduced by vectorization
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
            Blocks: 118443
  Target Milestone: ---

The vectorizer introduces new signed overflows when the function below (taken
from testsuite/gcc.dg/vect/vect-uncounted-run_2.c) is compiled for x86_64 with
-O2 -march=x86-64-v3

#include <assert.h>
#define N 9

__attribute__((noipa, noinline))
void
test01 ()
{
    {
      int x[N] = {2, 4, 6, 8, 10, 12, 14, 16, 18};
      const int y[N] = {3, 5, 7, 9, 11, 13, 15, 17, 19};
      int z[N] = {5, 9, 13, 17, 21, 25, 29, 33, 37};

      int *x0 = x;
      int *xN = x+N;
      const int *y0 = y;
      const int *yN = y+N;

      int *res = x;

      for (; x0 != xN && y0 != yN; ++x0, (void)++y0, ++res)
        *res = *x0 + *y0;
      assert (x0 == x+N && y0 == y+N && res == x+N);
      assert (x[0] == z[0] && x[1] == z[1]);
    }
}


The vectorized loop performs the addition as

  vect__1.10_76 = MEM <vector(8) int> [(int *)vectp_x.8_74];
  vect__2.13_79 = MEM <const vector(8) int> [(const int *)vectp_y.11_77];
  vect__3.14_80 = vect__1.10_76 + vect__2.13_79;

The loads reads out of bounds in the second iteration, which is OK because of
the alignment, and later comparisons ensure the extra elements are not stored.
But adding the out of bounds elements may overflow.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing

Reply via email to