www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21676] New: [ICE][SIMD] DMD crashing with SIMD +

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

          Issue ID: 21676
           Summary: [ICE][SIMD] DMD crashing with SIMD + optimizations +
                    inlining
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: aliloko gmail.com

DMD 2.096-b1 either crash (or loops a long time) with the following code:


-------------- repro.d -------------


import core.simd;

double2 loadUnaligned(const(double)* pvec)
{
    double2 result;
    foreach(i; 0..2)
    {
        result[i] = pvec[i];
    }
    return result;
}

double2 _mm_setr_pd (double e1, double e0)
{
    double[2] result = [e1, e0];
    return loadUnaligned(result.ptr);
}

double2 fun (double2 a, double2 b)
{
    a[0] = (a[0] < b[0]) ? a[0] : b[0];
    return a;
}

void main(string[] args)
{
    double2 A = _mm_setr_pd(1.0, 2.0);
    double2 B = _mm_setr_pd(4.0, 1.0);
    double2 C = fun(A, B);
    assert(C.array[0] == 1.0);
    assert(C.array[1] == 1.0);
}

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


Run it with: 
   dmd -m64 -O -inline repro.d
   echo %errorlevel%


Notes:
  - static foreach avoids the issue
  - both -O and -inline needed
  - works OK and assert pass with LDC


  - DMD 2.088 gives more details:

-----------
ERROR: This is a compiler bug.
Please report it via https://issues.dlang.org/enter_bug.cgi
with, preferably, a reduced, reproducible example and the information below.
DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the
reduction.
---
DMD v2.088.1-dirty
predefs   DigitalMars Windows CRuntime_Microsoft CppRuntime_Microsoft
LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 Win64 D_LP64
assert D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat
binary    c:\d\dmd_2.088.1\windows\bin\dmd.exe
version   v2.088.1-dirty
config    c:\d\dmd_2.088.1\windows\bin\sc.ini
DFLAGS    -Ic:\d\dmd_2.088.1\windows\bin\..\..\src\phobos
-Ic:\d\dmd_2.088.1\windows\bin\..\..\src\druntime\import -L/OPT:NOICF
---

object.Error (0): Illegal Instruction
----------------
0x00631AD4

--
Mar 02