<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117486>117486</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] [CG] Inconsistent lowering of matrix types to LLVM IR vector/array types
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:codegen,
extension:clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Sirraide
</td>
</tr>
</table>
<pre>
Currently, in `ConvertTypeForMem()`, we convert matrix types to LLVM IR array types, but in `ConvertType()`, we convert them to LLVM IR vector types. This doesn’t seem particularly sound to me since vector and array types afaik are generally not guaranteed to behave the same wrt padding etc. (and it is *definitely* not well-formed for e.g. `_BitInt(12)`, but I think we should disallow that in any case; see #117487).
For example, consider (https://godbolt.org/z/EqjEq18Kz):
```c++
using mat3 = float [[clang::matrix_type(3, 3)]];
void f(mat3 x, mat3 y) { x * y; }
```
For `f()`, we emit:
```llvm
define dso_local void @_Z1fu11matrix_typeILm3ELm3EfES_(<9 x float> noundef %x, <9 x float> noundef %y) #1 {
entry:
%x.addr = alloca [9 x float], align 4
%y.addr = alloca [9 x float], align 4
store <9 x float> %x, ptr %x.addr, align 4
store <9 x float> %y, ptr %y.addr, align 4
%col.load = load <3 x float>, ptr %x.addr, align 4
%vec.gep = getelementptr float, ptr %x.addr, i64 3
; ...
```
We should probably use vector types consistently considering that that’s what LLVM’s matrix intrinsics expect. We don’t support e.g. binding references to matrix subscript expressions, so it’s not like we really need them to be array types from what I can tell.
CC @efriedma-quic, @rjmccall, @fhahn
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVcFu2zgQ_Rr6MohgUZZlH3yI7XgRbHvZFltgLwFFjmS2FKmSlG316xdDuYmTbovdBRiFpjiPb55mHkUIurWIG1ZuWbmfiSEend980N4LrXBWOzVudoP3aKMZGd-BtsCW852zJ_Tx49jjwfn32DG-YnzNlnPac0aQ0wboRP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