D: Correct vector compares for targets with mask types different from data size.
Fixes D language vector comparisons on targets with narrow mask registers, like AVX512.
This commit corrects how vector comparison expressions are handled in the D language frontend when the target architecture uses mask registers that are narrower than the vector data size. Specifically, on targets with AVX512 masks (which are 32x narrower than operands), the D frontend’s rule of using a same-size integral vector for the result caused type reinterpretation rejections. The solution mirrors the C/C++ frontends by computing a separate, appropriate return type for vector boolean operations.
In Details
In d-codegen.cc, the build_boolop function in GCC's D frontend previously used the comparison's mask type as the result type for VEC_COND_EXPR. This works fine when the mask type has the same width as the vector data type. However, with AVX512VL, mask registers (e.g., k0-k7) are significantly narrower (e.g., 8-bit for __m256 or 16-bit for __m512 when the data is 32-bit or 64-bit per element). For these targets, D's language rule requiring a same-width integral vector for the result led to type mismatches. This patch introduces build_vec_cmp and modifies build_boolop to compu…
- D language
- A systems programming language with C-like syntax and a large set of features including garbage collection, C compatibility, and powerful metaprogramming capabilities. It is supported by the GCC compiler.
- Vector compare
- A comparison operation performed on multiple data elements simultaneously using vector (SIMD) instructions. The result is typically a mask indicating which elements satisfied the comparison.
- Mask type
- In SIMD programming, a data type used to control which elements of a vector operation are active or affected. For example, AVX512 uses dedicated mask registers.
- AVX512
- An extension to the x86 instruction set architecture that supports single instruction, multiple data (SIMD) operations on 512-bit vectors. It includes advanced features like mask registers.
- VEC_COND_EXPR
- An internal GCC representation for a conditional vector expression, often generated from comparisons that produce a vector mask.