Bug 24283 – [SIMD][CODEGEN] Bad codegen with and not + AVX2 registers

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2023-12-17T14:29:47Z
Last change time
2023-12-19T22:06:37Z
Keywords
backend, pull, SIMD, wrong-code
Assigned to
No Owner
Creator
ponce
See also
https://issues.dlang.org/show_bug.cgi?id=24284

Comments

Comment #0 by aliloko — 2023-12-17T14:29:47Z
With DMD64 D Compiler v2.106.0-dirty On machine with AVX2 instructions. Consider the following program: --------------- repro.d --------------- import core.simd; import core.stdc.stdio; void main() { int8 A = [7, -2, 9, 54654, 7, -2, 9, 54654]; int8 B = [14, 78, 111, -256, 14, 78, 111, -256]; int8 R = (~A) & B; int[8] correct = [8, 0, 102, -54784, 8, 0, 102, -54784]; // Should be [8, 0, 102, -54784, 8, 0, 102, -54784] // but return: [8, 0, 102, -54784, 6, 78, 9, 54528 instead when the issue is here. printf("%d %d %d %d %d %d %d %d\n", R[0], R[1], R[2], R[3], R[4], R[5], R[6], R[7]); assert(R.array == correct); } ----------------------------------------- Build it with: dmd -m64 -mcpu=native repro.d Codegen is wrong.
Comment #1 by aliloko — 2023-12-17T14:51:46Z
Similar problem with comparison operators, see Issue 24284
Comment #2 by bugzilla — 2023-12-18T06:12:38Z
The instructions it generates are: C5 FE 6F 05 00 00 00 00 vmovdqu YMM0,FLAT:.rodata[00h][RIP] C5 FE 6F 0D 00 00 00 00 vmovdqu YMM1,FLAT:.rodata[00h][RIP] C5 FE 6F 15 00 00 00 00 vmovdqu YMM2,FLAT:.rodata[00h][RIP] C5 FD EF C2 vpxor YMM0,YMM0,YMM2 C5 FD DB C1 vpand YMM0,YMM0,YMM1 C5 FE 7F 44 24 20 vmovdqu 020h[RSP],YMM0
Comment #3 by dlang-bot — 2023-12-18T07:12:29Z
@WalterBright created dlang/dmd pull request #15921 "fix Issue 24283 - [SIMD][CODEGEN] Bad codegen with and not + AVX2 reg…" fixing this issue: - fix Issue 24283 - [SIMD][CODEGEN] Bad codegen with and not + AVX2 registers https://github.com/dlang/dmd/pull/15921
Comment #4 by bugzilla — 2023-12-18T07:15:02Z
*** Issue 24284 has been marked as a duplicate of this issue. ***
Comment #5 by dlang-bot — 2023-12-19T20:14:01Z
dlang/dmd pull request #15921 "fix Issue 24283 - [SIMD][CODEGEN] Bad codegen with and not + AVX2 reg…" was merged into stable: - d400cde140883378c78e286ca85aedc20457be20 by Walter Bright: fix Issue 24283 - [SIMD][CODEGEN] Bad codegen with and not + AVX2 registers https://github.com/dlang/dmd/pull/15921
Comment #6 by dlang-bot — 2023-12-19T22:06:37Z
dlang/dmd pull request #15925 "Merge stable into master" was merged into master: - bfd09cddac6ebd69c63ddcf17bc90527084b718b by Walter Bright: fix Issue 24283 - [SIMD][CODEGEN] Bad codegen with and not + AVX2 registers (#15921) https://github.com/dlang/dmd/pull/15925