http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58821

            Bug ID: 58821
           Summary: conditional reduction does not vectorize
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincenzo.innocente at cern dot ch

in the following foo vectorize bar does not
(bar does not vectorize even for 
 if (x[i]>0) s+=x[i];
)
compiled as 
c++ -Ofast -fopt-info-loop -S condRed.cc -fopenmp -ftree-loop-if-convert-stores
-march=core-avx2

gcc version 4.9.0 20131011 (experimental) [trunk revision 203426] (GCC) 

neither
#pragma omp simd reduction(+:s)
nor
#pragma ivdep
helps


const int N=1024;
float x[N], y[N];

float bar() {
  float s=0;
  for (int i=0; i<N; ++i)
   if (x[i]>0) s+=y[i];
  return s;
}


float foo() {
  float s=0;
  for (int i=0; i<N; ++i)
   s+= (x[i]>0) ?y[i] : 0;
  return s;
}



float barOMP() {
  float s=0;
#pragma omp simd reduction(+:s)
  for (int i=0; i<N; ++i)
   if (x[i]>0) s+=y[i];
  return s;
}


float fooOMP() {
  float s=0;
#pragma omp simd reduction(+:s)
  for (int i=0; i<N; ++i)
   s+= (x[i]>0) ?y[i] : 0;
  return s;
}


float barIVDEP() {
  float s=0;
#pragma ivdep
  for (int i=0; i<N; ++i)
   if (x[i]>0) s+=y[i];
  return s;
}

Reply via email to