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

           Summary: Does not vectorize loops involving casts from floating
                    point to integer types
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: jeremysal...@gmail.com


The following code vectorizes with the command line options:

-march=native -mtune=native -ftree-vectorizer-verbose=12 -O3 -std=c99
-ffast-math -funsafe-math-optimizations -lm  main.c

#include <stdio.h>
#include <math.h>
int main() {
  double g[1000];
  for(int i=0; i<1000; i++) {
    g[i]=2*(g[i]);
  }
  for(int i=0; i<1000; i++) {
   printf("%f\n",g[i]);
  }
}

but the following code does not with the same options:


#include <stdio.h>
#include <math.h>
int main() {
  double g[1000];
  for(int i=0; i<1000; i++) {
    g[i]=2*((unsigned long)g[i]);
  }
  for(int i=0; i<1000; i++) {
   printf("%f\n",g[i]);
  }
}

If I understand correctly, there are SSE instructions for casting doubles to
long integers on the platform I'm on (Intel Atom) which GCC could use.  (or
perhaps there could be a benefit to vectorizing other parts of the loop, even
if the cast does not utilize SIMD instructions.)

Reply via email to