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

Tamar Christina <tnfchris at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-12-25
           Keywords|                            |missed-optimization

--- Comment #1 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
Yeah, the patch wasn't intended to handle that case.

As the patch says it requires the sizes of the memories being accessed to be
constant. i.e. https://compiler-explorer.com/z/87d61h3x5 works and that already
works today.


my patch would allow this if we relax vect_analyze_early_break_dependences to
not worry about memory accesses if the condition itself does not access memory.

However I don't think this should get to my patch at all. this loop

void add(int N, int *__restrict a, int *__restrict b, int *__restrict c) {
  for (int i = 0; i < N; i++) {
    c[i] = a[i] + b[i];
    if (i > 1000) {
        break;
    }
  }
}

is essentially

void add2(int N, int *__restrict a, int *__restrict b, int *__restrict c) {
  for (int i = 0; i < 1001; i++) {
    c[i] = a[i] + b[i];
  }
}

and is what clang has rewritten it to.

GCC does the same in ivcanon but then doesn't realize the additional exit is
unreachable and should be removed.  So this case needs to be handled before it
reaches the vectorizer.

Reply via email to