Bug 21673 – [SIMD][Win64] Wrong codegen for _mm_move_ss

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2021-03-02T00:19:50Z
Last change time
2022-04-22T21:59:52Z
Keywords
backend, pull, SIMD, wrong-code
Assigned to
No Owner
Creator
ponce

Comments

Comment #0 by aliloko — 2021-03-02T00:19:50Z
Consider the following program: --------------- repro.d ------------------ import core.simd; import core.stdc.stdio; float4 _mm_move_ss (float4 a, float4 b) { a.ptr[0] = b.array[0]; return a; } void main() { float4 A = [1.0f, 2.0f, 3.0f, 4.0f]; float4 B = [5.0f, 6.0f, 7.0f, 8.0f]; float4 R = _mm_move_ss(A, B); _mm_print_ps(A); _mm_print_ps(B); _mm_print_ps(R); float[4] correct = [5.0f, 2.0f, 3.0f, 4.0f]; assert(R.array == correct); } void _mm_print_ps(float4 v) { float[4] C = (cast(float4)v).array; printf("%f %f %f %f\n", C[0], C[1], C[2], C[3]); } ------------------------------------------ # With LDC, it prints: ---- 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 5.000000 0.000000 0.000000 0.000000 ---- and the assertion pass. # With DMD 2.096-b1 With the following flags: dmd -m64 -O -inline repro.d the program displays: ---- 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 5.000000 0.000000 0.000000 0.000000 [email protected](20): Assertion failure ---------------- 0x00007FF6D6F612D2 0x00007FF6D6F611D2 0x00007FF6D6F62E43 0x00007FF6D6F62CBF 0x00007FF6D6F62DAB 0x00007FF6D6F62CBF 0x00007FF6D6F62BE6 0x00007FF6D6F61503 0x00007FF6D6F61202 0x00007FF6D6F8F438 0x00007FFDD8B07C24 in BaseThreadInitThunk 0x00007FFDDAA0D721 in RtlUserThreadStart ---- Also buggy back in dmd_2.088.1
Comment #1 by aliloko — 2021-03-06T15:50:33Z
Erratum: In LDC it prints: ---- 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 5.000000 2.000000 3.000000 4.000000 ----
Comment #2 by dkorpel — 2022-04-11T09:14:02Z
The bug is in -O, not in -inline, because it persists when you manually inline: ``` void main() { float4 A = [1.0f, 2.0f, 3.0f, 4.0f]; float4 B = [5.0f, 6.0f, 7.0f, 8.0f]; float4 a = A; float4 b = B; a.ptr[0] = b.array[0]; float4 R = a; _mm_print_ps(A); _mm_print_ps(B); _mm_print_ps(R); float[4] correct = [5.0f, 2.0f, 3.0f, 4.0f]; assert(R.array == correct); } ``` Reduced a bit more: ``` import core.simd; import core.stdc.stdio; void main() { float4 A = [1.0f, 2.0f, 3.0f, 4.0f]; float4 B = [5.0f, 6.0f, 7.0f, 8.0f]; A.ptr[0] = B.array[0]; float4 R = A; _mm_print_ps(A); float[4] correct = [5.0f, 2.0f, 3.0f, 4.0f]; assert(R.array == correct); } void _mm_print_ps(float4 v) { float[4] C = (cast(float4)v).array; printf("%f %f %f %f\n", C[0], C[1], C[2], C[3]); } ``` Prints 5.000000 0.000000 0.000000 0.000000 Instead of 5.000000 2.000000 3.000000 4.000000 I tested this on Linux, so it's not Windows specific.
Comment #3 by dlang-bot — 2022-04-12T13:01:25Z
@dkorpel created dlang/dmd pull request #13977 "Fix issue 21673, 23009 - don't put SIMD variables in registers" fixing this issue: - Fix issue 21673, 23009 - don't put SIMD variables in registers https://github.com/dlang/dmd/pull/13977
Comment #4 by dlang-bot — 2022-04-12T23:59:55Z
dlang/dmd pull request #13977 "Fix issue 21673, 21676, 23009 - don't put SIMD variables in registers" was merged into stable: - 3423d410d9415a0120d7b21ec76fe2ace1c7d863 by Dennis Korpel: Fix issue 21673, 21676, 23009 - don't put SIMD variables in registers https://github.com/dlang/dmd/pull/13977
Comment #5 by dlang-bot — 2022-04-22T21:59:52Z
dlang/dmd pull request #14020 "merge stable" was merged into master: - c19baac0b667f36d4fd623e06a7728468acb3f56 by Dennis Korpel: Fix issue 21673, 21676, 23009 - don't put SIMD variables in registers https://github.com/dlang/dmd/pull/14020