GCC 4.2.4 optimization bug

Have a question about our Software Developer Kit? Ask them here.

GCC 4.2.4 optimization bug

Postby samo79 » Tue Jun 28, 2011 2:07 am

This bug was already reported (and included in a general post) on a topic in "General Developer support"

http://forum.hyperion-entertainment.biz/viewtopic.php?f=26&t=95&p=1498#p1498

But as it's a GCC issue i think it's better to report here as well

------------------------------------------------------------
GCC 4.2.4 Bugs
------------------------------------------------------------

The optimizer has bugs. Eg. when using -O1 or -O2 to compile Koules 1.16
for OS4, the resulting executable has a bug: namely, that the P key only
pauses while it is held down. Compiling with -O0 avoids this issue.


If you like to test it, just download Koules from OS4Depot and compile it with -O1 or -O2 with the usual make command, then start the game and press P for pause ;-)
User avatar
samo79
 
Posts: 524
Joined: Sat Jun 18, 2011 12:13 am
Location: Italy

Re: GCC 4.2.4 optimization bug

Postby kas1e » Tue Jun 28, 2011 10:32 am

@samo79

Just to add some stuff which can helps: No one will try to compile Koules and trying to understand what Kolues code do , to reproduce that error (its uninteresting and time consuming job). So, you (or that one who catch the bug) , should create small as possible example, with small as possible code, which will cleary show the difference and problems. And only after that if it will indeed bug, it will be fixed.

But from my expirience, i can tell you, that optimisation "bugs" in most cases are not bugs, but problems with code, and the way, how arguments passing to stack, how optimisator works with stack when you use O1/O2/O3 , and , while with O0 some "wrong" code can works, with O1 or O2 it will just works different. I have the same kind of problems with optimisation, when port some function over mui (DoSuperNew), which use hooks, tags and some stuff. And in end, someone on UtilityBase explain all the stuff (i.e. why compiler produce different code for different optimisation flags), and in end, its just forces to my bad code (which works with O1 and not works with O2).

Expectually when you have disabled optimisation at all in compare with any kind of enabled optimisation: its all will reacts different, if some nasty hacks/hooks/code are done in game itself. But to check all of this, need small example, with reducing all un-necessary for reproduce code.

So, if you and author of that programm still think that its reall bug in optimisation, need to create small as possible example, and then, if it indeed bug it will be fixed. But as it now like "some game have optimisation bug when you press P in game" give you no chance that it will be fixed.
kas1e
Beta Tester
Beta Tester
 
Posts: 469
Joined: Sat Jun 18, 2011 8:56 am

Re: GCC 4.2.4 optimization bug

Postby samo79 » Tue Jun 28, 2011 11:11 am

@Roman

Ok received, a small example should be pretty possible i think so at this point i will tell him to do so ;)

All what we know for now is that with -O1 or -O2 optimization Pause will not works correctly while with -O0 works, also would be interesting to know what happen using a more recent GCC, AFAIK latest version is now 4.5.3 altrough not released for the mass yet
User avatar
samo79
 
Posts: 524
Joined: Sat Jun 18, 2011 12:13 am
Location: Italy

Re: GCC 4.2.4 optimization bug

Postby kas1e » Tue Jun 28, 2011 11:51 am

@samo79
"Pause" its too "hi-level" in that case. All depends how code done which handle that "pause" code, and what code do before and after, and how it all handled and so on. Some small piece of only necessary code which cleary show the problem from low-level code-side will help for sure. The smaller example code which show the problem = the higher chances to detect the bug and fix it :)
kas1e
Beta Tester
Beta Tester
 
Posts: 469
Joined: Sat Jun 18, 2011 8:56 am

Re: GCC 4.2.4 optimization bug

Postby broadblues » Wed Jun 29, 2011 10:54 am

I agree with kas1e it's quite likely that optimisation is revealing a bug in your code.

Make sure you compile with -Wall and then fix all warnings. And fix them "properly" by that I mean think about them, and why they are happening, sometimes a simple cast is all that it required, other times you need to think much more carefully about what values are being assigned to which variables.

Be especially aware of any warnings related to unassigned variables, the values the variables take might vary with optimisation level.

Also if this code is targeted at more than one compiler, make sure there no assumptions about argument executation order etc in functions calls, this can vary from version to version, and maybe even with optimisation level.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 556
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: GCC 4.2.4 optimization bug

Postby Slayer » Wed Jun 29, 2011 10:58 am

Yes

I remember Gunther Nikl repeatedly saying the similair on the old gcc list, It's great to look forward to doing all this stuff myself...

Only at my extreme witts end would I admitt defeat and then have to contemplate the possibility I have indeed discovered a genuine gcc generated bug ;)

Of course when I do actually start coding (after I have the X1000) you are to conveniently forget I ever write such stuff as above :D
~Yes I am a Kiwi, No, I did not appear as an extra in 'Lord of the Rings'~
1x AmigaOne X5000 2.0GHz 2gM RadeonR9280X AOS4.x
3x AmigaOne X1000 1.8GHz 2gM RadeonHD7970 AOS4.x
User avatar
Slayer
Beta Tester
Beta Tester
 
Posts: 851
Joined: Tue Dec 21, 2010 5:19 am
Location: New Zealand

Re: GCC 4.2.4 optimization bug

Postby ssolie » Wed Jun 29, 2011 6:22 pm

samo79 wrote:But as it's a GCC issue i think it's better to report here as well

If you really believe this is a GCC optimizer bug then go to GCC bugs and read everything over.

The Amiga build of GCC does not modify anything in the optimizer so any bugs would need to be reported back to the GCC team anyway.

My bet is that the code is broken and has always been broken. More aggressive optimizers tend to expose such subtle bugs which more primitive compilers will gloss over.
AmigaOS Development Team Lead
Be authentic. Get AmigaOS.
User avatar
ssolie
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1010
Joined: Mon Dec 20, 2010 9:51 pm
Location: Canada


Return to SDK Support

Who is online

Users browsing this forum: No registered users and 4 guests

cron