Re: Xcode 5.1 compiler option -Ofast
Re: Xcode 5.1 compiler option -Ofast
- Subject: Re: Xcode 5.1 compiler option -Ofast
- From: Chris Lattner <email@hidden>
- Date: Tue, 18 Mar 2014 09:21:20 -0700
On Mar 18, 2014, at 6:05 AM, Doug Hill <email@hidden> wrote:
>> This option was new in Xcode 5, it isn't new in 5.1. -Ofast is equivalent
>> to turning on -ffast-math (which favors performance over strict IEEE
>> numerics) and -fstrict-aliasing as well as increasing code size. One of
>> the advanced LLVM talks at WWDC 2013 should have discussed it.
>>
>> -Chris
>
> According to documentation I could find -Ofast enables the following:
>
> 1. All -O3 optimizations
> 2. -ffast-math
> 3. The vectorizer (e.g. vectorize loops)
>
> It also looks like strict aliasing has been turned on by default in a
> seperate switch since Xcode 4.6. I don't see anything that says -Ofast
> affects this option, unless it's somehow bound up in -O3. I would be
> interested in finding out more info about this if someone has it.
Yep, this sounds right. -fstrict-aliasing is on by default since it is part of the C standard, the vectorizer is now on by default as well (though it is much more aggressive at -O3 than at -Os).
> Of course there are some caveats for using -Ofast:
>
> Do not use if your application has high floating point precision
> requirements.
>
> -ffast-math breaks IEEE 754 conformance. If you dont know why you need
> +/-INF or +/-0 you should be wary. Definitely not appropriate for
> scientific/financial calculations that need precision.
>
> Test carefully
>
> A requirement whenever you make changes that involve code-gen.
> In addition to unit tests, you should also test with Instruments to make
> sure performance actually improves. (see previous comments about cache
> misses)
>
> In general, Im wary of turning on optimizations just because its easy to
> set a switch. You have a greater chance of exposing bugs in your code and
> the toolchain, and those bugs are often very hard to track down. But Apple
> has been recommending -Ofast a lot so this looks like a good switch to
> explore.
The way I would put it is that you should prefer -Os, *unless* performance is critically important for some part of your app. This is the sort of flag you should opt into when you need the performance, not something you should default to using everywhere.
Thanks for the great summary Doug,
-Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden