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

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #9)
> A testcase would be the following - we don't perform loop-header copying
> for an isolated testcase, thus manually here.
> 
> void *
> foo (void **p, void **limit)
> {
>   if (++p < limit)
>     do
>       {
>         void *x = *p;
>         if (x != (void *)0 && x != (void *)1)
>           return x;
>       }
>     while (++p < limit);
>   return (void *)0;
> }
> 
> I can't spot what is wrong here with the vectorization off-head.

In fact the following doesn't spot any issue (it should exhaustively
test peeling & relative position of the to be found element).

void * __attribute__((noipa))
foo (void **p, void **limit)
{
  if (++p < limit)
    do
      {
        void *x = *p;
        if (x != (void *)0 && x != (void *)1)
          return x;
      }
    while (++p < limit);
  return (void *)0;
}

int main()
{
  void *x[4096];
  for (int j = 0; j < 4095; ++j)
    for (int k = j + 1; k < 4096; ++k)
      {
        for (int i = 0; i < 4096; ++i)
          x[i] = 0;
        x[k] = (void *)42;
        void *res = foo (&x[j], &x[4096]);
        if (res != (void *)42)
          __builtin_abort ();
      }
}

Reply via email to