This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]