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

            Bug ID: 98365
           Summary: Miss vectoization
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
                CC: hjl.tools at gmail dot com, wwwhhhyyy333 at gmail dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu

cat test.c

int foo (char a[64], char c[64])
{
  int i;
  char cnt=0;
  for (int i = 0;i != 64; i++)
    if (a[i] == c[i])
      cnt++;
  return cnt;
}

with -Ofast -mavx2 gcc failed to vectorize the loop due to 

dump of loop body:
-----------
  # cnt_21 = PHI <cnt_9(7), 0(15)>
  # i_22 = PHI <i_17(7), 0(15)>
  # ivtmp_19 = PHI <ivtmp_18(7), 64(15)>
  _1 = (sizetype) i_22;
  _2 = a_14(D) + _1;
  _3 = *_2;
  _5 = c_15(D) + _1;
  _6 = *_5;
  cnt.1_7 = (unsigned char) cnt_21;
  _8 = cnt.1_7 + 1;
  cnt_16 = (char) _8;
  cnt_9 = _3 == _6 ? cnt_16 : cnt_21;
  i_17 = i_22 + 1;
  ivtmp_18 = ivtmp_19 - 1;
----------

-fopt-info
---------
test.c:5:20: note:   vec_stmt_relevant_p: stmt live but not relevant.
test.c:5:20: note:   mark relevant 1, live 1: cnt_9 = _3 == _6 ? cnt_16 :
cnt_21;
test.c:5:20: note:   init: stmt relevant? i_17 = i_22 + 1;
test.c:5:20: note:   init: stmt relevant? ivtmp_18 = ivtmp_19 - 1;
test.c:5:20: note:   init: stmt relevant? if (ivtmp_18 != 0)
test.c:5:20: note:   worklist: examine stmt: cnt_9 = _3 == _6 ? cnt_16 :
cnt_21;
test.c:5:20: note:   vect_is_simple_use: operand *_2, type of def: internal
test.c:5:20: note:   mark relevant 1, live 0: _3 = *_2;
test.c:5:20: note:   vect_is_simple_use: operand *_5, type of def: internal
test.c:5:20: note:   mark relevant 1, live 0: _6 = *_5;
test.c:5:20: note:   vect_is_simple_use: operand (char) _8, type of def:
internal
test.c:5:20: note:   mark relevant 1, live 0: cnt_16 = (char) _8;
test.c:5:20: note:   vect_is_simple_use: operand cnt_21 = PHI <cnt_9(7),
0(15)>, type of def: unknown
test.c:5:20: missed:   Unsupported pattern.
----------------
Shouldn't cnt_21 = PHI <cnt_9(7), 0(15)>, stmt relevant?


BTW: with extra -fwrapv, gcc successfully vectorized the loop.

Reply via email to