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

            Bug ID: 114193
           Summary: missed early break vectorization of reduction
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

For the following loop:

int a[1024];
int f(int *x, int n)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 42)
            break;
        sum += a[i];
    }
    return sum;
}

at -O3 on aarch64 we miss vectorizing it.  It works if I move the early exit
down below the update of sum.  It looks like vect_analyze_scalar_cycles fails
to detect this as a reduction:

/app/example.c:5:23: note:   Analyze phi: sum_10 = PHI <sum_6(7), 0(6)>
/app/example.c:5:23: missed:   intermediate value used outside loop.
/app/example.c:5:23: missed:   Unknown def-use cycle pattern.

Reply via email to