This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
how to keep command line options but add more optimization flag to certain function
- From: "Guo, Gcwenken" <gcwenken dot guo at ttu dot edu>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 19 Aug 2015 22:14:34 +0000
- Subject: how to keep command line options but add more optimization flag to certain function
- Authentication-results: sourceware.org; auth=none
- References: <1520D03BE10FC848B7E7E7C90D3D18BD42C275E4 at centaur07 dot ttu dot edu>
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.