www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16497] New: suboptimal moves between SSE registers

https://issues.dlang.org/show_bug.cgi?id=16497

          Issue ID: 16497
           Summary: suboptimal moves between SSE registers
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: b2.temp gmx.com

I was not sure if this is an issue or not since DMD is not designed to generate
the best byte code but this is a case where something really odd is generated.

Take the function


T fun(double x, double c)
{
    return x*x*x - x*x*c + x*c;
}

compile with -O -release -c, disassemble and look at the code gen for fun:

00000000004A9E60h  sub rsp, 18h
00000000004A9E64h  movsd xmm5, xmm0
00000000004A9E68h  movsd xmm4, xmm1
00000000004A9E6Ch  movsd qword ptr [rsp], xmm1
00000000004A9E71h  movsd xmm0, qword ptr [rsp]
00000000004A9E76h  mulsd xmm0, xmm5
00000000004A9E7Ah  mulsd xmm1, xmm4
00000000004A9E7Eh  mulsd xmm1, xmm4
00000000004A9E82h  movsd xmm2, xmm4
00000000004A9E87h  mulsd xmm2, xmm4
00000000004A9E8Bh  mulsd xmm2, xmm5
00000000004A9E8Fh  subsd xmm1, xmm2
00000000004A9E93h  addsd xmm0, xmm1
00000000004A9E97h  add rsp, 18h
00000000004A9E9Bh  ret

we see that the stack pointer is increased by 24 bytes (16 would be enough BTW)
just to serve as space to move xmm1 in xmm0 while just "movsd xmm0, xmm1" is
necessary.

--
Sep 15 2016