how to keep command line options but add more optimization flag to certain function

Guo, Gcwenken gcwenken.guo@ttu.edu
Wed Aug 19 22:14:00 GMT 2015


Hi:
An easy example:
auto f(double*a,unsigned long const N)
{
  for(auto i(0);i!=N;++i) a[i]+=2*i;
}
and then I use g++ -std=c++1z -O2 -march=native -ftree-vectorize -fopt-info -S to compile the source code. The output show: note loop vectorized. That is good.

After that I want to add more aggressive optimization to such function. So I write:
__attribute__((optimize("unroll-loops"))) auto f(double*a,unsigned long const N)
{
  for(auto i(0);i!=N;++i) a[i]+=2*i;
}

and then I use g++ -std=c++1z -O2 -march=native -ftree-vectorize -fopt-info -S to compile the source code. The output just show: note loop unroll 7 times. And then I check the asm file and find out that gcc just does unroll-loops optimization but ignores tree-vectorize
 in the command line.

I also try to use:
#pragma GCC optimize("unroll-loops")auto f(double*a,unsigned long const N){  for(auto i(0);i!=N;++i) a[i]+=2*i;}
still not working. So I want to ask how to keep command line options but add more optimization flag to certain function.

I use g++-5.2, x86-64 linux and cpu support avx2.





More information about the Gcc-help mailing list