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

            Bug ID: 114322
           Summary: [14 Regression] SCEV analysis failed for bases like
                    A[(i+x)*stride] since r14-9193-ga0b1798042d033
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hliu at amperecomputing dot com
  Target Milestone: ---

Compile the following case with: gcc simp.c -Ofast -mcpu=neoverse-n1 -S \
         -fdump-tree-ifcvt -fdump-tree-vect-details-scev

int
foo (short *A, int x, int stride)
{
  int sum = 0;

  if (stride > 1)
    {
      #pragma GCC unroll 1
      for (int i = 0; i < 1024; ++i)
        sum += A[(i + x) * stride];
    }

  return sum;
}

The gimple in the loop is:

  <bb 3>:
  # sum_19 = PHI <sum_15(6), 0(5)>
  # i_20 = PHI <i_16(6), 0(5)>
  # ivtmp_37 = PHI <ivtmp_36(6), 1024(5)>
  _1 = x_12(D) + i_20;
  _2 = _1 * stride_11(D);
  _3 = (long unsigned int) _2;
  _4 = _3 * 2;
  _5 = A_13(D) + _4;
  _6 = *_5;
  _7 = (int) _6;
  sum_15 = _7 + sum_19;


Before the commit (i.e., from pr114074 bug fix), it can be vectorized:

Creating dr for *_5
analyze_innermost: (analyze_scalar_evolution 
  (loop_nb = 1)
  (scalar = _5)
(get_scalar_evolution 
  (scalar = _5)
  (scalar_evolution = {A_13(D) + (long unsigned int) (stride_11(D) * x_12(D)) *
2, +, (long unsigned int) stride_11(D) * 2}_1))
)
success.
(analyze_scalar_evolution 
  (loop_nb = 1)
  (scalar = _5)
(get_scalar_evolution 
  (scalar = _5)
  (scalar_evolution = {A_13(D) + (long unsigned int) (stride_11(D) * x_12(D)) *
2, +, (long unsigned int) stride_11(D) * 2}_1))
)
(instantiate_scev 
  (instantiate_below = 5 -> 3)
  (evolution_loop = 1)
  (chrec = {A_13(D) + (long unsigned int) (stride_11(D) * x_12(D)) * 2, +,
(long unsigned int) stride_11(D) * 2}_1)
  (res = {A_13(D) + (long unsigned int) (stride_11(D) * x_12(D)) * 2, +, (long
unsigned int) stride_11(D) * 2}_1))
        base_address: A_13(D) + (sizetype) (stride_11(D) * x_12(D)) * 2
        offset from base address: 0
        constant offset from base address: 0
        step: (ssizetype) ((long unsigned int) stride_11(D) * 2)
        base alignment: 2
        base misalignment: 0
        offset alignment: 128
        step alignment: 2
        base_object: *A_13(D) + (sizetype) (stride_11(D) * x_12(D)) * 2
        Access function 0: {0B, +, (long unsigned int) stride_11(D) * 2}_1


After the commit, loop vectorized failed due to SCEV failure with *_5:

Creating dr for *_5
analyze_innermost: (analyze_scalar_evolution 
  (loop_nb = 1)
  (scalar = _5)
(get_scalar_evolution 
  (scalar = _5)
  (scalar_evolution = _5))
)
(analyze_scalar_evolution 
  (loop_nb = 1)
  (scalar = _5)
(get_scalar_evolution 
  (scalar = _5)
  (scalar_evolution = _5))
)
simp.c:11:10: missed:  failed: evolution of base is not affine.
..
  (res = scev_not_known))


To my understanding, '(i + x) * stride' is signed integer calculation, in which
overflow is undefined behavior and the case should be vectorized.

Reply via email to