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

            Bug ID: 57642
           Summary: vectorizer not working with function templates
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yzhang1985 at gmail dot com

Hi, the following simple loop doesn't vectorize in GCC 4.8.1, but does with
4.3.2. It does vectorize if I make DoIt a regular function instead of a
templated function.


#include <iostream>
#include <math.h>
#include <emmintrin.h>
#include <stdint.h>
#include <nmmintrin.h>
#include <stdlib.h>


class SqrtFunc
{
public:
  float operator()(float x)
  {
    return (((3.02f * x) + 1.5f) * x - 2.1f) * x + 1.5f;
  }
};

template <typename Functor>
void DoIt(float *data, int size, Functor functor)
{
  for (int i = 0; i < size; ++i)
  {
    data[i] = functor(data[i]);
  }
}


int main()
{
  float data[2048];
  SqrtFunc functor;
  DoIt(data, sizeof(data), functor);
  return 0;
}

Reply via email to