Sunday, January 9, 2022

[SOLVED] gcc vectorization messages

Issue

I read (http://software.intel.com/en-us/articles/vectorization-writing-cc-code-in-vector-format/) that the Intel compiler has a flag to output information about vectorization - things like "BLOCK WAS VECTORIZED.", etc. Does gcc have anything similar? I am just trying see if I can get an idea of what is getting vectorized and what is not. For example, I'd like to make a demo like this:

#include <vector>

class Point3
{
public:
  Point3() : Components(3)
  {
    data[0] = 0;
    data[1] = 0;
    data[2] = 0;
  }

  const unsigned int Components;
  float data[3];

private:


};

class Point4
{
public:
  Point4() : Components(4)
  {
    data[0] = 0;
    data[1] = 0;
    data[2] = 0;
    data[3] = 0;
  }

  const unsigned int Components;

  float data[4];
private:


};

template <typename T>
static float Add(const T& a, const T& b)
{
  float sumValues = 0.0f;
  for(unsigned int i = 0; i < a.Components; ++i)
  {
    sumValues += a.data[i] + b.data[i];
  }
  return sumValues;
}

int main()
{
  std::vector<Point3> point3vec(1000);
  for(std::size_t i = 0; i < point3vec.size() - 1; ++i)
  {
    Add(point3vec[i], point3vec[i+1]);
  }

  std::vector<Point4> point4vec(1000);
  for(std::size_t i = 0; i < point4vec.size(); ++i)
  {
    Add(point4vec[i], point4vec[i+1]);
  }

}

and see if one of the loops gets vectorized while the other doesn't.


Solution

See -ftree-vectorizer-verbose=n at http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-ftree_002dvectorizer_002dverbose-690

In newer versions of GCC use -fopt-info-vec -fopt-info-vec-missed.



Answered By - Jonathan Wakely