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

            Bug ID: 118211
           Summary: tree-vectorize: vectorize input.cc, find_end_of_line
           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 the hot loop of the line searching function in gcc input.cc.
It currently fails to vectorize on AVX512F. Would be nice if it could.

% gcc -O3 -mavx512f -fopt-info -fopt-info-all  eol.cc -S
Unit growth for small function inlining: 18->18 (0%)

Inlined 0 calls, eliminated 0 functions

BB 3 is always executed in loop 1
loop 1's coldest_outermost_loop is 1, hotter_than_inner_loop is NULL
eol.cc:6:36: missed: couldn't vectorize loop
eol.cc:8:11: missed: can't safely apply code motion to dependencies of _1 =
*s_12;
 to vectorize the early exit.
eol.cc:4:1: note: vectorized 0 loops in function.
eol.cc:23:36: note: ***** Analysis failed with vector mode V32QI
BB 3 is always executed in loop 1
loop 1's coldest_outermost_loop is 1, hotter_than_inner_loop is NULL
eol.cc:6:36: note: considering unrolling loop 1 at BB 5
considering unrolling loop with constant number of iterations
considering unrolling loop with runtime-computable number of iterations

#include <stddef.h>

const char *
find_end_of_line (const char *s, size_t len)
{
  for (const auto end = s + len; s != end; ++s)
    {
      if (*s == '\n')
        return s;
      if (*s == '\r')
        {
          const auto next = s + 1;
          if (next == end)
            {
              break;
            }
          return (*next == '\n' ? next : s);
        }
    }
  return nullptr;
}

Reply via email to