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

            Bug ID: 81196
           Summary: Number of iterations found for p!=q but not for p<q
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

void f(short*p){
  p=(short*)__builtin_assume_aligned(p,64);
  short*q=p+256;
  for(;p!=q;++p,--q){
    short t=*p;*p=*q;*q=t;
  }
}

compiled with -O3 -march=skylake, this gets vectorized. However, if I replace
p!=q with p<q (much safer in case 256 was actually 255), it isn't vectorized
anymore, apparently because the number of iterations cannot be determined.
Replacing p!=q with p!=q&&(p+1)!=q (or using std::reverse) also breaks
vectorization, but that's less surprising.

Reply via email to