digitalmars.D.learn - Using -O with DMD seems to produce non-random values.
- Michael (31/35) May 19 2016 I'm not entirely sure what optimisations are made when supplying
I'm not entirely sure what optimisations are made when supplying the -O flag to rdmd, but this may be related to an earlier issue I found for similar code here: https://issues.dlang.org/show_bug.cgi?id=16027 The code is: void main() { auto seed = 128; auto rand = Random(seed); double[] values; values = generateValues(rand, 10); writeln(values); } double[] generateValues(ref Random rand, int l) { auto values = new double[](l); foreach (ref val; values) { auto value = 1.0; if (uniform(0, 2, rand)) { value = value * -1; } val = value; } return values; } Which returns different values depending on whether -O is passed:$rdmd testing_optimiser.d [1, -1, -1, 1, -1, 1, 1, 1, -1, -1] $rdmd -O testing_optimiser.d [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]Any idea what causes this to occur when optimising? I wanted to try and speed up a simulation I'm running but it just produces too many unexpected consequences.
May 19 2016
Could it be that the code is optimised to the same as that in the original issue and so the current compiler still produces the incorrect result? Obviously the original issue has since been fixed but I won't be able to test this until the next version of DMD is released.
May 19 2016
how this works? double[] generateValues(ref Random rand, int l) { auto values = new double[](l); foreach (ref val; values) { auto value = 1; if (uniform(0, 2, rand)) { value = value * -1; } val = value; } return values; }
May 19 2016
On 05/19/2016 05:09 PM, Michael wrote:Any idea what causes this to occur when optimising? I wanted to try and speed up a simulation I'm running but it just produces too many unexpected consequences.I suspect that you're seeing issue 16027 [1], a bad bug in 2.071.0. The upcoming 2.071.1 point release should have it fixed. [1] https://issues.dlang.org/show_bug.cgi?id=16027
May 19 2016
On Thursday, 19 May 2016 at 15:49:17 UTC, ag0aep6g wrote:On 05/19/2016 05:09 PM, Michael wrote:Yeah that's what I was thinking but I don't know much about the optimisation process so I wanted to mention it anyway.Any idea what causes this to occur when optimising? I wanted to try and speed up a simulation I'm running but it just produces too many unexpected consequences.I suspect that you're seeing issue 16027 [1], a bad bug in 2.071.0. The upcoming 2.071.1 point release should have it fixed. [1] https://issues.dlang.org/show_bug.cgi?id=16027
May 19 2016
On Thursday, 19 May 2016 at 17:07:27 UTC, Michael wrote:On Thursday, 19 May 2016 at 15:49:17 UTC, ag0aep6g wrote:[...]And now I see that you linked there yourself in the OP. No idea how I missed that.[1] https://issues.dlang.org/show_bug.cgi?id=16027Yeah that's what I was thinking but I don't know much about the optimisation process so I wanted to mention it anyway.
May 19 2016