The gcc optimizer is retarded

So it is usually the case that I compile my code with -Os, this results in nice and compact code, however gcc tries too hard to make the code as small as possible sometimes making it very slow. I was forced to switch to -O2 because of this. However I really do not like how -O2 behaves in regards to inlining. It inlines really quite large functions, now I was mostly putting up with this but then it came to virtual functions and I was triggered.

Virtual functions and inlining:
You know what insane thing gcc did?
It first compared the value in the vtable and then if it matched the class’s own implementation it branched to the inline code, else it calls the vtable function.
Seriously WTF, inlining is meant to speed things up but now you have introduced a conditional branch and all that extra code bloat. Function calls are not that expensive, especially if you are going to try all this bullshit to avoid them. Just call the damn virtual function and stop doing retarded things.

I am really starting to get sick of writing code for gcc, its a really shit compiler that produces very ugly assembly. Luckily I maintain my own fork of gcc so this is another thing I will look into fixing. I shall create a new optimization level which is partway between -Os and -O2. This new optimization level will be such that it will avoid code which increases size but will not try to reduce code size either.

Addendum: -fno-devirtualize-speculatively option can disable this particular piece of bullshit. At least that’s one less hack I need to make to the compiler.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s