Bug 21474 – ICE with core.simd and -O (Illegal Instruction)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2020-12-12T01:39:26Z
Last change time
2020-12-21T11:07:50Z
Keywords
backend, pull
Assigned to
No Owner
Creator
ponce
Comments
Comment #0 by aliloko — 2020-12-12T01:39:26Z
-------- test3.d --------
import core.simd;
struct long1
{
long[1] arr;
}
int4 to_m128i(long1 a)
{
long2 r;
r[0] = a.arr[0];
return cast(int4)r;
}
--------------------------
Build with: dmd -O -m64 test3.d
DMD 2.094.2 returns -1073741795
DMD 2.088.0 has a bit more info and says: object.Error@(0): Illegal Instruction
The bug disappear with -O left out.
Comment #1 by aliloko — 2020-12-16T01:15:43Z
Found this bug another time in another incarnation.
Build with dmd -O for reproducing.
--------- test4.d -------------
import core.simd;
int4 cmpss_repro(float4 a)
{
int4 result;
result.ptr[0] = (1 > a.array[0]) ? -1 : 0;
return result;
}
-------------------------------
Comment #2 by aliloko — 2020-12-16T01:27:22Z
I wanted intel-intrinsics to support DMD better, including D_SIMD, but the first step of using core.simd when using DMD is not working.
The goal was being able to use DMD in debug (or release mode) with faster execution.
This is a blocker bug for intel-intrinsics.
Comment #3 by maxhaton — 2020-12-17T22:48:31Z
(In reply to ponce from comment #1)
> Found this bug another time in another incarnation.
>
> Build with dmd -O for reproducing.
>
>
> --------- test4.d -------------
>
> import core.simd;
>
> int4 cmpss_repro(float4 a)
> {
> int4 result;
> result.ptr[0] = (1 > a.array[0]) ? -1 : 0;
> return result;
> }
>
> -------------------------------
This particular example yields the output
---
findreg(0, line=751, file='src/dmd/backend/cod4.d', function = '_D5dtest11cmpss_reproFNhG4fZNhG4i')
dmd: src/dmd/backend/cgcod.d:1864: Assertion `0' failed.
---
The function in question:
-------------------
reg_t findreg(regm_t regm, int line, const(char)* file)
{
debug
regm_t regmsave = regm;
reg_t i = 0;
while (1)
{
if (!(regm & 0xF))
{
regm >>= 4;
i += 4;
if (!regm)
break;
}
if (regm & 1)
return i;
regm >>= 1;
i++;
}
debug
printf("findreg(%s, line=%d, file='%s', function = '%s')\n",regm_str(regmsave),line,file,funcsym_p.Sident.ptr);
fflush(stdout);
// *(char*)0=0;
assert(0);
}
-------------------
On the assumption that dmd builds are distributed after being compiled with ldc, ldc (possibly dmd as well) will optimise an assert(0) to a x86 ud2 instruction.
Comment #4 by maxhaton — 2020-12-17T22:49:58Z
Yields that output on a current (DMD64 D Compiler v2.094.2 - fresh git build) dmd built with debug symbols and versions turned on.
Comment #5 by dlang-bot — 2020-12-18T08:55:59Z
@WalterBright created dlang/dmd pull request #12032 "fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)" fixing this issue:
- fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)
https://github.com/dlang/dmd/pull/12032
Comment #6 by dlang-bot — 2020-12-19T10:11:08Z
@WalterBright created dlang/dmd pull request #12035 "fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)" fixing this issue:
- fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)
https://github.com/dlang/dmd/pull/12035
Comment #7 by dlang-bot — 2020-12-20T11:53:41Z
dlang/dmd pull request #12035 "Issue 21486 - assert fail cgcod.d:1864 with simd and -O" was merged into master:
- 1a869098fd7ad87fe989ae9ffb21272d09107205 by Walter Bright:
fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)
https://github.com/dlang/dmd/pull/12035
Comment #8 by dlang-bot — 2020-12-21T11:07:50Z
dlang/dmd pull request #12032 "fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)" was merged into master:
- bde681964420e72bb6fd77ebdf22b8c6a982b688 by Walter Bright:
fix Issue 21474 - ICE with core.simd and -O (Illegal Instruction)
https://github.com/dlang/dmd/pull/12032