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

            Bug ID: 118468
           Summary: vectorizer: extra phi blocks vectorization of if
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andi-gcc at firstfloor dot org
  Target Milestone: ---

This is forked from PR116126 to handle another early exit problem

const unsigned char *search_line_fast2 (const unsigned char *s, const unsigned
char *end)
{
        while (s < end) {
                if (*s == '\n' || *s == '\r' 
#ifdef MORE
                                || *s == '\\' || *s == '?'
#endif
                                )
                        return s;
                s++;
        }
        return s;
}

When build

cc1 -O3 -mavx10.2 search-line-fast-short.c -quiet -fopt-info-all -o x.s
-fdump-tree-vect
it vectorizes but with -DMORE=1 it gives:
search-line-fast-short.c:3:18: missed: couldn't vectorize loop
search-line-fast-short.c:3:18: missed: not vectorized: unsupported control flow
in loop.

tree-vect-loop.c:
  /* Check if we have any control flow that doesn't leave the loop.  */
  basic_block *bbs = get_loop_body (loop);
  for (unsigned i = 0; i < loop->num_nodes; i++)
    if (EDGE_COUNT (bbs[i]->succs) != 1
        && (EDGE_COUNT (bbs[i]->succs) != 2
            || !loop_exits_from_bb_p (bbs[i]->loop_father, bbs[i])))
      {
        free (bbs);
        return opt_result::failure_at (vect_location,
                                       "not vectorized:"
                                       " unsupported control flow in loop.\n");



tree-if-conv converts the if, but then generates:


 _13 = _5 | prephitmp_26;
  if (_13 != 0)
    goto <bb 12>; [8.03%]
  else
    goto <bb 6>; [91.97%]

(still inside loop)
  <bb 12> [local count: 83800317]:
  # s_24 = PHI <s_15(5)>
  goto <bb 7>; [100.00%]  -> leaving loop


So the empty basic block with the extra PHI prevents vectorization.

The question is what to do about it. Either if-conv could avoid it, or the
vectorizer could handle this case.

Reply via email to