Jump to page: 1 2
Thread overview
[Issue 22372] Loop index incorrectly optimised out for -release -O
Oct 09, 2021
Teodor Dutu
Oct 09, 2021
Iain Buclaw
Oct 09, 2021
Imperatorn
Oct 09, 2021
Teodor Dutu
Oct 09, 2021
Imperatorn
Oct 10, 2021
Basile-z
Oct 10, 2021
Basile-z
Oct 10, 2021
Basile-z
Oct 10, 2021
Ketmar Dark
Oct 11, 2021
Dlang Bot
Oct 11, 2021
Dlang Bot
Oct 12, 2021
Walter Bright
Oct 12, 2021
Dlang Bot
Oct 12, 2021
Dlang Bot
October 09, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

Teodor Dutu <teodor.dutu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |teodor.dutu@gmail.com
           Severity|regression                  |blocker

--- Comment #1 from Teodor Dutu <teodor.dutu@gmail.com> ---
Using run.dlang.io, I tried to find a regression, but all supported DMD versions (2.060 and newer) are printing the same incorrect output (Exception: i = 0; n = 1). My experiment can be found here: https://run.dlang.io/is/uYfTzl. This seems to be a backend issue, as both LDC and LDC-beta are working fine.

However, I came across this bug when working on this PR:
https://github.com/dlang/dmd/pull/13116. And when analysing the CI outputs, I
noticed that all 3 of DMD, LDC and GDC are failing the same test, which I've
also been able to reproduce myself:
- LDC: https://cirrus-ci.com/task/6291197929979904?logs=test_druntime#L1449
- DMD: https://cirrus-ci.com/task/5728247976558592?logs=test_druntime#L1390
- GDC: https://cirrus-ci.com/task/4883823046426624?logs=test_druntime#L1411

The failure of this test is caused by the issue I mentioned above and the code with which I reproduced the bug is based on it.

--
October 09, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org

--- Comment #2 from Iain Buclaw <ibuclaw@gdcproject.org> ---
(In reply to Teodor Dutu from comment #1)
> However, I came across this bug when working on this PR:
> https://github.com/dlang/dmd/pull/13116. And when analysing the CI outputs,
> I noticed that all 3 of DMD, LDC and GDC are failing the same test, which
> I've also been able to reproduce myself:
> - LDC: https://cirrus-ci.com/task/6291197929979904?logs=test_druntime#L1449
> - DMD: https://cirrus-ci.com/task/5728247976558592?logs=test_druntime#L1390
> - GDC: https://cirrus-ci.com/task/4883823046426624?logs=test_druntime#L1411
> 
> The failure of this test is caused by the issue I mentioned above and the code with which I reproduced the bug is based on it.
There is no bug in GDC or LDC.

$ gdc -O2 -frelease pr22372.d && ./a.out
Exception: i = 1; n = 1
$ ldc2 -O -release pr22372.d && ./pr22732
Exception: i = 1; n = 1
$ dmd -O -release pr22372.d && ./pr22732
Exception: i = 0; n = 1

--
October 09, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

Imperatorn <johan_forsberg_86@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johan_forsberg_86@hotmail.c
                   |                            |om

--- Comment #3 from Imperatorn <johan_forsberg_86@hotmail.com> ---
If you make size_t i static the behaviour is correct

--
October 09, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

--- Comment #4 from Teodor Dutu <teodor.dutu@gmail.com> ---
(In reply to Imperatorn from comment #3)
> If you make size_t i static the behaviour is correct

Yes, this would fix the issue, but it would be a hack rather than a solution. The bug would still persist in DMD's backend.

--
October 09, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

--- Comment #5 from Imperatorn <johan_forsberg_86@hotmail.com> ---
Lol, of course. It was just an observation.

Another observation:
If you change type from size_t to int or uint the behaviour is correct

--
October 10, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #6 from Basile-z <b2.temp@gmx.com> ---
Hello, I've worked on the bug a bit and found the problem location in the backend, in gloop, which performs loop optims:

`i` is optimized in the code that follows [1].

[1] https://github.com/dlang/dmd/blob/master/src/dmd/backend/gloop.d#L2966

--
October 10, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend

--
October 10, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

--- Comment #7 from Basile-z <b2.temp@gmx.com> ---
by digging further it looks like the problem resides in dmd.backend.gloop reference counting system. OPInd would be ignored, so when a loop body only contains an IndexExp and that the IndexExp subscript is the IV (increment value ?), DMD thinks that the IV is not used.

--
October 10, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--
October 11, 2021
https://issues.dlang.org/show_bug.cgi?id=22372

--- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> ---
@teodutu created dlang/druntime pull request #3585 "Use workaround until issue 22372 is fixed" mentioning this issue:

- Use workaround until issue 22372 is fixed

  Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>

https://github.com/dlang/druntime/pull/3585

--
« First   ‹ Prev
1 2