Bug 23009 – [CODEGEN][SIMD] SIMD + optimizations + inlining + double

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2022-04-10T13:48:00Z
Last change time
2022-04-22T21:59:54Z
Keywords
backend, pull, SIMD, wrong-code
Assigned to
No Owner
Creator
ponce

Comments

Comment #0 by aliloko — 2022-04-10T13:48:00Z
Consider the following program: -------------------------------------- import core.simd; alias __m128d = double2; __m128d _mm_setr_pd (double e1, double e0) pure @trusted { double2 result; result[0] = e1; result[1] = e0; return result; } __m128d _mm_loadl_pd (__m128d a, const(double)* mem_addr) pure @trusted { a[0] = *mem_addr; return a; } void main(string[] args) { double A = 7.0; __m128d B = _mm_setr_pd(4.0, -5.0); __m128d R = _mm_loadl_pd(B, &A); double[2] correct = [ 7.0, -5.0 ]; assert(R.array == correct); } -------------------------------------- With DMD 2.099.1, build with: dmd -m64 -inline -O main.d It doesn't pass the assert. But it does pass if you omit -inline, or -O, or use another compiler.
Comment #1 by dkorpel — 2022-04-11T10:12:15Z
Reduced a bit more: ``` import core.simd; import core.stdc.stdio; double2 _mm_loadl_pd(double2 a, const(double)* mem_addr) { a[0] = *mem_addr; return a; } void main() { double A = 7.0; double2 B; B[0] = 4.0; B[1] = -5.0; double2 R = _mm_loadl_pd(B, &A); printf("%f %f\n", R[0], R[1]); double[2] correct = [ 7.0, -5.0 ]; assert(R.array == correct); } ``` Compile with -O, this one actually succeeds when _mm_loadl_pd gets inlined either with -inline or manually. Prints: 7.000000 0.000000 Instead of: 7.000000 -5.000000
Comment #2 by dlang-bot — 2022-04-12T13:01:26Z
@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 #3 by dlang-bot — 2022-04-12T23:59:57Z
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 #4 by dlang-bot — 2022-04-22T21:59:54Z
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