LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   -O5? Is it safe? Does it exist? (http://www.linuxquestions.org/questions/programming-9/o5-is-it-safe-does-it-exist-932435/)

Zssfssz 03-02-2012 11:31 PM

-O5? Is it safe? Does it exist?
 
In several instances I have seen a person mention -O5 optomaztions. One said that the vareable i (it was the only vareable in the example... and C++) would't even be loded into memory but acctualy put in register eax;this makes it sound unsafe... Does GCC have it? Is it safe? Google doesn't bring up anything and the gcc docs are umm... large.

gnashley 03-03-2012 02:58 AM

-O3 is the highest one that exists.

H_TeXMeX_H 03-03-2012 04:15 AM

I've seen mplayer use '-O4'. However, the only one that is safe is '-O2'.

Zssfssz 03-03-2012 11:01 PM

Just tried it with gfortran (I normally test things with c first), it worked. Also tried -O25 and it worked! It there a process to this?

graemef 03-05-2012 05:59 AM

define "it worked" ;)

The compiler may have just ignored the switch or it may have substituted it for a number that is supported. Basically the various -Ox stitches are responsible for setting up certain optimisation flags, and beyond that don't do anything on their own.

colucix 03-05-2012 06:17 AM

Some compilers actually have -O4 and -O5 optimization levels (e.g XL Fortran for Multicore Acceleration by IBM), but this is very compiler-specific and I think you can live with -O3 at most. I agree with "The compiler ... may have substituted it for a number that is supported" as mentioned by graemef. Indeed, it uses the maximum available level of optimization. I cannot find a reference about this behaviour anyway.

gnashley 03-05-2012 06:52 AM

As I said, for gcc '-O3' is the highest one available. If you give values above 3 it simply ignores them and uses -O3. I'm not sure that -O2 is safer then -O2 -depends on what you mean by 'safe'. -O2 is certainly the most reliable. Using -O3 won't work for all sources and/or arches.

orgcandman 03-05-2012 02:59 PM

Quote:

Originally Posted by gnashley (Post 4618817)
As I said, for gcc '-O3' is the highest one available. If you give values above 3 it simply ignores them and uses -O3. I'm not sure that -O2 is safer then -O2 -depends on what you mean by 'safe'. -O2 is certainly the most reliable. Using -O3 won't work for all sources and/or arches.

NOTE: severely opinionated junk follows.

In general, if you've properly coded to the C/C++ virtual machine, -O3 is 'reliable'. However, if you've taken any shortcuts, then you'll likely have lots of "strange" behavior.

Additionally, -O3 may expose you to more compiler bugs (contrary to popular belief, compiler bugs are not fictitious).

The only way to know if a particular level is "safe" for you is to have very robust and aggressive unit tests which execute and use code coverage tools in conjunction to validate that you have actually hit all the lines of code from numerous permutations.

H_TeXMeX_H 03-06-2012 07:29 AM

Quote:

Originally Posted by orgcandman (Post 4619151)
In general, if you've properly coded to the C/C++ virtual machine, -O3 is 'reliable'.

Like that ever happens...

Reuti 03-07-2012 11:23 AM

Quote:

Originally Posted by orgcandman (Post 4619151)
In general, if you've properly coded to the C/C++ virtual machine, -O3 is 'reliable'. However, if you've taken any shortcuts, then you'll likely have lots of "strange" behavior.

What do you refer to with “properly coded” and “shortcuts”? The program might be properly coded, but as -O3 can reorder the computations one can face some overflow/underflow conditions with varying outcome. Although the program is still compiled in a mathematical correct way, the used algorithms can fail due to the reordering of operations.

orgcandman 03-07-2012 01:22 PM

Quote:

Originally Posted by Reuti (Post 4620949)
What do you refer to with “properly coded” and “shortcuts”? The program might be properly coded, but as -O3 can reorder the computations one can face some overflow/underflow conditions with varying outcome. Although the program is still compiled in a mathematical correct way, the used algorithms can fail due to the reordering of operations.

-O3 (and any level, really) can only reorder between synchronization points. By properly coded, I mean one codes to the standard in a completely unambiguous manner. Merely 'compliant' is not good enough (example is testing for overflow, which is "compliant" in that the standard allows it, but the results are not guaranteed).

Funny you bring up mathematical models. My current job is writing OTA channel emulation software (emulating Jakes' or Dent's versions of Rayleigh fading, for example). We use -O3. Our algorithms verify correct, statistically. I've used -O3 to compile lots of different software projects. It usually behaves.

As has been noted though, -OXXXX is completely compiler dependent and isn't so much a standard as a request to the compiler to try and do certain actions (omit frame pointers, reorder mathematical expressions, pass values using esoteric registers, etc). There was a time for the gnu compiler when O2 was considered dangerous, and O3 was downright insane. I think as the compilers have gotten better, the amazingly spectacular breakages have been eliminated and the code is usually correct.

Again, just my $.02


All times are GMT -5. The time now is 07:33 AM.