On 02/24/2013 01:07 PM, Kirk Liberty wrote:
On Sun, Feb 24, 2013 at 6:10 AM, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote:
On 24 February 2013 00:23, Kirk Liberty wrote:
Hi all,
I'm trying to use g++ to compile a function with optimization O2
except for one function I want at O3. I'm not having any luck with
__attribute__ or #pragma. I am using GCC version 4.7.2. With
__attribute__ I am getting a warning that the directive was ignored,
and with #pragma I am simply not seeing the speedup expected.
Maybe the optimizer simply doesn't make the code any faster.
When I globally use O3 I see about a 3 times speedup in that function.
Here's what I've tried.
bool* getStreamBool(uint64_t num) __attribute__ ((optimize("-O3"))) {...}
For me, this has worked but with earlier GCC version than 4.7.2:
__attribute__((optimize ("O3")))
bool* getStreamBool(uint64_t num) {...}
I.e., put the attribute before the function and leave off the dash on
-O3 and no space after __attribute__. Not sure if this really makes a
difference. You can look at the objdump of the program to see if it
actually changed your function's assembly code.
However, I was unable to get the "pragma GCC optimize 3" method to have
any effect at all!
Then again, some functions are not optimized any more at 3 as compared
to 2. (But I was going from 0 to 3 so there should be big difference.)
I think this should be "O3" or just "3", without the dash.
I have tried it without the dash, but not without the "O".
I seem to have broken my <cmath> and <random> files so I can't try it right now.
Kirk