Thread overview
[Issue 22163] wrong code with static float array and delegate accessing it
Aug 02, 2021
Dennis
Nov 02, 2021
Dlang Bot
Dec 13, 2021
Dennis
[Issue 22163] [REG 2.094.0] wrong code with static float array and delegate accessing it
Dec 13, 2021
Paul Backus
Jan 14, 2022
Dlang Bot
August 02, 2021
https://issues.dlang.org/show_bug.cgi?id=22163

--- Comment #1 from Dennis <dkorpel@live.nl> ---
So far I found out that the delegate makes the parameter volatile in dmd/tocsym.d:

```
if (vd.nestedrefs.dim)
{
    /* Symbol is accessed by a nested function. Make sure
     * it is not put in a register, and that the optimizer
     * assumes it is modified across function calls and pointer
     * dereferences.
     */
    //printf("\tnested ref, not register\n");
    type_setcv(&t, t.Tty | mTYvolatile);
}
```

Then in dmd/backend/cod1.d:FuncParamRegs_alloc the float[2] is combined into the xmm0 register:

```
if (tyaggregate(ty))
{
/* ... */
        else if (tybasic(t.Tty) == TYarray)
        {
            if (I64)
                argtypes(t, targ1, targ2);
        }
```

But in dmd/backend/cod3.d:prolog_loadparams this branch isn't taken:
```
// This logic is same as FuncParamRegs_alloc function at src/dmd/backend/cod1.d
//
// Find suitable SROA based on the element type
// (Don't put volatile parameters in registers)
if (tyb == TYarray && !(t.Tty & mTYvolatile))
{
    type *targ1;
    argtypes(t, targ1, t2);
    if (targ1)
        t = targ1;
}
```
Which makes it load a `double` from xmm0 instead of a `float`. The comment
"This logic is same as FuncParamRegs_alloc function" is no longer true, but I'm
not certain what the fix is. I doubt `volatile` should affect the abi, but
"Don't put volatile parameters in registers" was written for a reason so I
don't want to remove that without consideration.

--
November 02, 2021
https://issues.dlang.org/show_bug.cgi?id=22163

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #13256 "Fix issue 22163 - wrong code with static float array and delegate accessing it" fixing this issue:

- Fix issue 22163 - wrong code with static float array and delegate accessing it

https://github.com/dlang/dmd/pull/13256

--
December 13, 2021
https://issues.dlang.org/show_bug.cgi?id=22163

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |naydef@abv.bg

--- Comment #3 from Dennis <dkorpel@live.nl> ---
*** Issue 22588 has been marked as a duplicate of this issue. ***

--
December 13, 2021
https://issues.dlang.org/show_bug.cgi?id=22163

Paul Backus <snarwin+bugzilla@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla@gmail.com
            Summary|wrong code with static      |[REG 2.094.0] wrong code
                   |float array and delegate    |with static float array and
                   |accessing it                |delegate accessing it
           Severity|major                       |regression

--
January 14, 2022
https://issues.dlang.org/show_bug.cgi?id=22163

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #13256 "Fix issue 22163 - wrong code with static float array and delegate accessing it" was merged into stable:

- 78d2e0833d21680de1090ad3d3fd68dd3205739e by dkorpel:
  Fix issue 22163 - wrong code with static float array and delegate accessing
it

https://github.com/dlang/dmd/pull/13256

--