[Issue 23048] New: [SIMD][CODEGEN] Inline XMM.LODUPD leads to wrong SIMD content

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 23 14:07:59 UTC 2022


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

          Issue ID: 23048
           Summary: [SIMD][CODEGEN] Inline XMM.LODUPD leads to wrong SIMD
                    content
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: aliloko at gmail.com

Created attachment 1848
  --> https://issues.dlang.org/attachment.cgi?id=1848&action=edit
main source

Using DMD v2.100.0-beta.1-dirty,
consider the following program:


----------- main.d -------------

import core.stdc.stdio;
import core.simd;

double2 _mm_loadr_pd (const(double)* mem_addr)
{
    double2 a = *cast(double2*)(mem_addr);
    double2 r;
    r.ptr[0] = a.array[1];
    r.ptr[1] = a.array[0];
    return r;
}
unittest
{
    align(16) double[2] A = [56.0, -74.0];
    double2 R = _mm_loadr_pd(A.ptr);
}

double2 _mm_loadu_pd (const(double)* mem_addr)
{
    return cast(double2) __simd(XMM.LODUPD, *mem_addr);    
}

unittest
{
    double[2] A = [56.0, -75.0];
    double2 R = _mm_loadu_pd(A.ptr);
    printf("%f %f\n", R[0], R[1]);
    double[2] correct = [56.0, -75.0];
    assert(R.array == correct);    
}

void main()
{
}

--------------------------------

To reproduce:
   $ dmd -m64 -inline -O main.d -unittest
   $ main.exe


This outputs:
   56.000000 -74.000000
   main.d(29): [unittest] unittest failure
   1/1 modules FAILED unittests

instead of the normal:
   56.000000 -75.000000
   1 modules passed unittests


Notes:
   - -O, -inline, and -unittest are necessary.
   - _mm_loadu_pd  is inline into the unittest
   - the 1st unittest is necessary, what happens seems to be that a former
variable or register is reused

--


More information about the Digitalmars-d-bugs mailing list