Thread overview | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 24, 2013 [Issue 9387] New: Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9387 Summary: Compiler switch -O changes behavior of correct code Product: D Version: D2 Platform: x86_64 OS/Version: Mac OS X Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: stephan.schiffels@mac.com --- Comment #0 from Stephan <stephan.schiffels@mac.com> 2013-01-24 07:56:09 PST --- Created an attachment (id=1182) Source file with program that The attached program implements a part of Brent's minimization algorithm for one-dimensionsal functions. The code is from Numerical Recipes 3rd edition. I use dmd 2.061/ When I run the program with "rdmd brent_test.d" it runs fine and gives the correct result. When I run it with optimization, i.e. with "rdmd -O brent_test.d", it behaves differently. It enters some infinite loop and eventually throws the expected exception for too many iterations. You can see that I placed a writefln() into line 45, which outputs the value of variable a. When you move this writefln statement just one line below, i.e. below the if-statement, the code runs fine, even with optimization. I colleague of mine suggested that there might be a bug related to a large number of local variables. Maybe some limiting number of registers causes the machine to cache things into memory and pulling them back in a wrong way or something. Appreciate help! Stephan -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 24, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #1 from Stephan <stephan.schiffels@mac.com> 2013-01-24 08:06:00 PST --- During debugging, I actually looked at the value of every single local variable, and you can actually see how the value of some variables (for example "a") changes from one iteration to the next, without any assignment. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 24, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #2 from Stephan <stephan.schiffels@mac.com> 2013-01-24 10:00:41 PST --- I just checked: The bug definitely was introduced with version 2.061! With dmd version 2.060, everything works fine, with and without the "-O" switch. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 24, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@digitalmars.com Severity|major |regression -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 25, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2013-01-25 00:30:21 PST --- I can't reproduce this with the latest dmd. I'll upload a new beta tomorrow you can try. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 25, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #4 from Stephan <stephan.schiffels@mac.com> 2013-01-25 05:01:07 PST --- (In reply to comment #3) > I can't reproduce this with the latest dmd. I'll upload a new beta tomorrow you can try. What actually seems to be corrupted are the precompiled executables on the zip-file on the web. We checked this for the osx and the linux version. Both of these precompiled versions produce this bug. When we compile dmd from source, even for version 2.061 from the web, this bug does not occur. Stephan -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 25, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #5 from Stephan <stephan.schiffels@mac.com> 2013-01-25 06:53:50 PST --- (In reply to comment #3) > I can't reproduce this with the latest dmd. I'll upload a new beta tomorrow you can try. Sorry to jump back and forth here. I have to again correct my previous statement: With the latest version of dmd/druntime/phobos (2.062 from git), this bug does occur! But only when you compile and run separately. When you use dmd -run, both versions with and without -O work fine. This is quite weird. So: dmd -O brent_test.d ./brent_test should produce a different outcome than dmd brent_test.d ./brent_test I will try use bisect to find out when this bug was introduced. Stephan -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 25, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #6 from Walter Bright <bugzilla@digitalmars.com> 2013-01-25 10:37:02 PST --- When I compile and run separately, it works fine. You should also clarify whether you are using -m64 or not. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 25, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #7 from Stephan <stephan.schiffels@mac.com> 2013-01-25 10:43:26 PST --- Right, I use the 64bit model. And I tested this on OSX and on linux, with same outcomes on both platforms. It's frustating that you can't reproduce. Thanks for responding quickly on this anyway. I will see what I can find out with bisect. Stephan -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 28, 2013 [Issue 9387] Compiler switch -O changes behavior of correct code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan | http://d.puremagic.com/issues/show_bug.cgi?id=9387 --- Comment #8 from Don <clugdbug@yahoo.com.au> 2013-01-28 01:01:42 PST --- BTW you might be interested in std.numeric.findRoot, which is the root-finding-by-bracketing algorithm (in contrast to "Brent's algorithm" which is minima-finding-by-bracketing). In terms of number of calls, I believe it beats all published algorithms (in some cases, by an order of magnitude). I should really publish it. I did some work on the minima problem as well, and put it into Tango, but it isn't in Phobos. The code is very old now, dating from a time where there were many compiler limitations, and it could use a review. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation