Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Why is the Linux compilers are wrong?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
just a guest
n00b
n00b


Joined: 18 Jan 2011
Posts: 13
Location: Ставрополь

PostPosted: Tue Jan 18, 2011 9:34 am    Post subject: Why is the Linux compilers are wrong? Reply with quote

Why not recommend to make anything with a flag of a max performance? I just can't understand - how the compiler can compile a unworking program? After all, this is not the correct compiler, right? So he miscalculated somewhere, perhaps the address is not correctly written, it's for programs fatal.
Or here's another: I has fumbled in net about building a system with the ICC and found phrases like "kernel can not even try to make with it" and "It is going to compile archiver, and archiver even works, but when you try to open the archive says that he is corrupt. Although the archive is completely good ...". In my opinion in the source code is pretty clear describes - what, where and why. So how then possible to compile archiver, that it will not open archives?
Back to top
View user's profile Send private message
aCOSwt
Bodhisattva
Bodhisattva


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Tue Jan 18, 2011 10:29 am    Post subject: Reply with quote

Well, Pardon me but I had troubles understanding your post.
Do you mean that a compiler should refuse to build a program with features incompatible with the application run-time environment, with functions that might bug at run-time ? 8O
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2007

PostPosted: Tue Jan 18, 2011 11:20 am    Post subject: Re: Why is the Linux compilers are wrong? Reply with quote

just a guest wrote:
Why not recommend to make anything with a flag of a max performance? I just can't understand - how the compiler can compile a unworking program? After all, this is not the correct compiler, right? So he miscalculated somewhere, perhaps the address is not correctly written, it's for programs fatal.

If you are asking why the Gentoo compiler guide recommends not using -O3, I agree with you. If the compiler offers -O3, it ought to work, and improve performance. There may be occasions where it doesn't, such as machines with small memory where the memory use of in-lining routines may cause paging, but in general I think it's reasonable to expect -O3 code to be faster than O2.
My suspicion is that gcc -O3 was initially buggy, and got a bad reputation, and that's stuck even though much time has passed and many bugs been fixed.
FWIW, I've always specified -O3 on all my Gentoo systems, for over 5 years, and never had a stability problem resulting. I have no idea whether they're any faster than -O2. Gentoo overrides -O3 in make.conf for applications believed to encounter compiler bugs, but if you are desperate for -O3, you can usually override Gentoo's overrides.
just a guest wrote:
Or here's another: I has fumbled in net about building a system with the ICC and found phrases like "kernel can not even try to make with it" and "It is going to compile archiver, and archiver even works, but when you try to open the archive says that he is corrupt. Although the archive is completely good ...". In my opinion in the source code is pretty clear describes - what, where and why. So how then possible to compile archiver, that it will not open archives?
If you are asking why code that an archive program works when compiled by gcc but fails when compiled by ICC, that will be down to compiler bugs. Just like any program, compilers can have bugs. Developers will code around the bugs when they find them, but as ICC is much less commonly used in Linux systems, there will be much less incentive to code around its bugs than gcc's. If I understand correctly, ICC offers best performance for scientific applications, so perhaps its users rarely use it to compile archive programs!
_________________
Greybeard
Back to top
View user's profile Send private message
aCOSwt
Bodhisattva
Bodhisattva


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Tue Jan 18, 2011 12:47 pm    Post subject: Reply with quote

Thanks to Goverp's post, I understand better your post !

About the question why gentoo's guide does not recommend -O3, in addition with what Goverp rightly points out, one should mention that -O3 does not necessarily improve performances :

Quickly said, -O3 = -O2 + finline-functions + some others

1/ Many of the specific -O3 optimizations lead to ignoring developer's explicit will.

finline-functions for instance, tells the compiler to ignore specific declarations in the code and decide by itself if some function will or will not be inlined.
As it is impossible for the compiler to actually benchmark the result... :roll: the compiler makes its decision from some so-called heuristical analysis which... is not always right and might lead to unexpected results !
Activating such an optimization, you suppose that the compiler will be wiser than the dev ! 8O Honestly ! If it happens it is not, whose fault is it ?

Well, as a consequence of this, you can understand that dev's would refuse supporting builds ignoring what they specifically took time and care to code.

2/ Many of the specific -O3 optimizations lead to results highly depending on the arch, the amount of cache...
If you decide to duplicate the code of a loop (what -funswitch-loop actually does) you will necessarily need more cache and can understand that the result will depend on the speed of your memory transfers.
-O3 specific optimizations, contrarily to -O2, are actually trade-offs !

As a conclusion, I would understand that you put this on the compiler's fault but, the only bug imho is in its documentation :
man gcc wrote:
-O3 Optimize yet more

When one should more honestly write : -O3 Might optimize more, or less, depending on the source and the targeted arch.
Back to top
View user's profile Send private message
just a guest
n00b
n00b


Joined: 18 Jan 2011
Posts: 13
Location: Ставрополь

PostPosted: Tue Jan 18, 2011 2:16 pm    Post subject: Reply with quote

Yeah, thanks for understanding, seems me is only one, who thinking that I've no any syntax errors :) Sorry for bad English.
I'm grateful for all answers, and will be glad, if anyone decides to add one more about it. Thanks.
Back to top
View user's profile Send private message
just a guest
n00b
n00b


Joined: 18 Jan 2011
Posts: 13
Location: Ставрополь

PostPosted: Tue Jan 18, 2011 2:45 pm    Post subject: Reply with quote

Quote:
FWIW, I've always specified -O3 on all my Gentoo systems, for over 5 years, and never had a stability problem resulting.

Are you compile with -03 even kernel?
P.S.
I just want to install Gentoo, and think in particular: may be do -03...
Back to top
View user's profile Send private message
Yamakuzure
Advocate
Advocate


Joined: 21 Jun 2006
Posts: 2284
Location: Adendorf, Germany

PostPosted: Tue Jan 18, 2011 3:47 pm    Post subject: Reply with quote

It might be worth reading the documentation of something as aggressive as O3 before posting what is more imagination than fact. However, the compiler uses the "inline" keyword of the programmer, and then decides whether it is really inlined by complexity of the function. In short: You do not want overly complex functions to be inlined. But as a programmer you can force inlining with a special function attribute. Basically it is a bad idea, because the compiler actually is smarter than you. Or in other words: If you try to outsmart your compiler, it will get it's revenge very soon and very hard.

But here we go with the documentation:
gcc.gnu.org/onlinedocs wrote:
-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-vectorize and -fipa-cp-clone options.

-finline-functions (*)
Integrate all simple functions into their callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way.

If all calls to a given function are integrated, and the function is declared static, then the function is normally not output as assembler code in its own right.

-funswitch-loops
Move branches with loop invariant conditions out of the loop, with duplicates of the loop on both branches (modified according to result of the condition).

-fpredictive-commoning
Perform predictive commoning optimization, i.e., reusing computations (especially memory loads and stores) performed in previous iterations of loops.

-fgcse-after-reload
When -fgcse-after-reload is enabled, a redundant load elimination pass is performed after reload. The purpose of this pass is to cleanup redundant spilling.

-ftree-vectorize
Perform loop vectorization on trees.

-fipa-cp-clone
Perform function cloning to make interprocedural constant propagation stronger. When enabled, interprocedural constant propagation will perform function cloning when externally visible function can be called with constant arguments. Because this optimization can create multiple copies of functions, it may significantly increase code size (see --param ipcp-unit-growth=value).

(*) But you do not need -finline-functions:

-finline-small-functions
Integrate functions into their callers when their body is smaller than expected function call code (so overall size of program gets smaller). The compiler heuristically decides which functions are simple enough to be worth integrating in this way.

Enabled at level -O2.

-findirect-inlining
Inline also indirect calls that are discovered to be known at compile time thanks to previous inlining. This option has any effect only when inlining itself is turned on by the -finline-functions or -finline-small-functions options.

Enabled at level -O2.
Generally speaking, using -O3 will generate larger results than -O2 and will be generally slower. The only known exceptions, thus packages that really benefit from using -O3 are sqlite and python.
_________________
Important German:
  1. "Aha" - German reaction to pretend that you are really interested while giving no f*ck.
  2. "Tja" - German reaction to the apocalypse, nuclear war, an alien invasion or no bread in the house.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Tue Jan 18, 2011 4:02 pm    Post subject: Reply with quote

just a guest wrote:
Quote:
FWIW, I've always specified -O3 on all my Gentoo systems, for over 5 years, and never had a stability problem resulting.

Are you compile with -03 even kernel?
P.S.
I just want to install Gentoo, and think in particular: may be do -03...

Kernel compilation will not use your CFLAGS from make.conf. You can use -Os when you set optimize for size in kernel config, and that is not zero in -Ox, it is an O as in optimization.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
aCOSwt
Bodhisattva
Bodhisattva


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Tue Jan 18, 2011 4:44 pm    Post subject: Reply with quote

Yamakuzure wrote:
It might be worth reading the documentation of something as aggressive as O3 before posting what is more imagination than fact.

lol !
Well... if what I wrote (and experimented) is imagination then what is
Yamakuzure wrote:
because the compiler actually is smarter than you
8O
supposed to be as an argument ?
Some Bergson-unaware charming a-priori ?
(gcc mailing list unaware at least for sure !)

My point is simply that I need a compiler that does what I order period. The same if I decide a variable to be global or not !
I can of course be wrong when deciding to inline or not a function. But I have the means to check if my decision is correct or not. Many many many more accurate and deterministic means than any euristical algorithm of any kind. If I explicitely specify inlining then it has to be inlined, and if I do not specify the keyword then, it does not implicitely mean that I don't care, it does mean that I do not want the function inlined, period !

And I strongly support both the rights of the end user to compile -O3 and the rights of the devs to ignore bug reports in this context.
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2007

PostPosted: Wed Jan 19, 2011 1:28 pm    Post subject: You can't (easily) change kernel compile options Reply with quote

just a guest wrote:
Quote:
FWIW, I've always specified -O3 on all my Gentoo systems, for over 5 years, and never had a stability problem resulting.

Are you compile with -03 even kernel?
...

In make.conf only. In normal use, the kernel's Makefile uses options set in the "Processor type and features" configuration section to set gcc options, and ignores anything in make.conf. I'm sure this is because the kernel developers need to be particularly careful about compiler options to ensure stability. I think I read about someone changing the Makefiles to allow more specific optimization, but I've not tried it myself.

Assuming you build a kernel tailored to your hardware, my guess is you will already have achieved most of the potential performance benefit over a generic kernel.
_________________
Greybeard
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2007

PostPosted: Wed Jan 19, 2011 1:32 pm    Post subject: Reply with quote

aCOSwt wrote:

...
And I strongly support both the rights of the end user to compile -O3 and the rights of the devs to ignore bug reports in this context.

I hope that's the right of the application developers to ignore the bug reports - the compiler developers surely should consider bugs caused by -O3 as serious.
_________________
Greybeard
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum