Thread overview
[Issue 10226] core.simd inefficient codegen
[Issue 10226] core.simd bad codegen
Apr 15, 2016
Benjamin Thaut
Apr 25, 2016
Walter Bright
Apr 25, 2016
Walter Bright
Apr 25, 2016
Walter Bright
Mar 13, 2017
Martin Nowak
Mar 14, 2017
Martin Nowak
Dec 17, 2022
Iain Buclaw
April 15, 2016
https://issues.dlang.org/show_bug.cgi?id=10226

Benjamin Thaut <code@benjamin-thaut.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |SIMD

--
April 25, 2016
https://issues.dlang.org/show_bug.cgi?id=10226

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to Benjamin Thaut from comment #8)
> Building with debug symbols gives a ICE ;-)

It works when I compile with -g.

--
April 25, 2016
https://issues.dlang.org/show_bug.cgi?id=10226

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #10 from Walter Bright <bugzilla@digitalmars.com> ---
It isn't 'bad' codegen, it's just inefficient codegen. I reclassified this as an enhancement request.

--
April 25, 2016
https://issues.dlang.org/show_bug.cgi?id=10226

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|core.simd bad codegen       |core.simd inefficient
                   |                            |codegen

--
March 13, 2017
https://issues.dlang.org/show_bug.cgi?id=10226

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu

--- Comment #11 from Martin Nowak <code@dawg.eu> ---
cat > bug.d << CODE
import core.simd;

alias vec = __vector(double[2]);

void storeUnaligned(ref vec a, in ref vec val)
{
    __simd_sto(XMM.STOUPD, a, val);
}

void test(ref vec a, in vec b)
{
    __simd_sto(XMM.STOUPD, a, b * b); // works
    immutable tmp = b * b;
    __simd_sto(XMM.STOUPD, a, tmp); // dips stack
    storeUnaligned(a, tmp); // dips stack
}
CODE
dmd -c -O -release -inline bug
----
        mulpd   xmm1, xmm3                              ; 000C _ 66: 0F 59. CB
        movapd  xmmword ptr [rsp], xmm1                 ; 0010 _ 66: 0F 29. 0C
24
        movdqa  xmm2, xmmword ptr [rsp]                 ; 0015 _ 66: 0F 6F. 14
24
        movupd  xmmword ptr [rdi], xmm2                 ; 001A _ 66: 0F 11. 17
----
Turns out that dmd's codegen is almost prohibitively inefficient, the intermediate value unnecessarily get pushed to the stack.

--
March 14, 2017
https://issues.dlang.org/show_bug.cgi?id=10226

--- Comment #12 from Martin Nowak <code@dawg.eu> ---
The cause for the example in comment 11 seems to be the void16 parameters of __simd_sto which breaks the

  (tyfloating(em->Ety) != 0) == (tyfloating(e->Ety) != 0)

condition in localizer.

https://github.com/dlang/dmd/blob/0089ae06db7c7b4bebe4d11bfcf02eab69936d81/src/ddmd/backend/glocal.c#L344


The assignment of value

{
(__vector(float[4])* p = &a[0];) , ((__vector(float[4]) value = b - c;));
__simd_sto(cast(XMM)3857, cast(__vector(void[16]))*p,
cast(__vector(void[16]))value);
}

is optimized to this el

el:0x9003b0 cnt=0 cs=0 *  TYsigned char[16] 0x900350
 el:0x900350 cnt=0 cs=0 var  TY*  __a_8
el:0x8ffc94 cnt=0 cs=0 -  TYsigned char[16] 0x8ffbd4 0x8ffc34
 el:0x8ffbd4 cnt=0 cs=0 var  TYfloat[4]  b
 el:0x8ffc34 cnt=0 cs=0 var  TYfloat[4]  c

which assigns a float[4] vector to a byte[16] vector.

--
March 15, 2017
https://issues.dlang.org/show_bug.cgi?id=10226

--- Comment #13 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/194fa0a92aec4a2b4fa5a6e28feeedca6daceb76 partly resolve Issue 10226 - inefficient core.simd codegen

- fix localization of float vector expressions passed to
  void16 parameters of simd intrinsics

https://github.com/dlang/dmd/commit/0d4eb1f06b938599293249eaecc2130fa6c89c81 Merge pull request #6626 from MartinNowak/issue10226

partly resolve Issue 10226 - inefficient core.simd codegen

--
August 07, 2017
https://issues.dlang.org/show_bug.cgi?id=10226

--- Comment #14 from github-bugzilla@puremagic.com ---
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/194fa0a92aec4a2b4fa5a6e28feeedca6daceb76 partly resolve Issue 10226 - inefficient core.simd codegen

https://github.com/dlang/dmd/commit/0d4eb1f06b938599293249eaecc2130fa6c89c81 Merge pull request #6626 from MartinNowak/issue10226

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=10226

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4

--