================
@@ -180,6 +180,19 @@ llvm::Type *CodeGenTypes::convertTypeForLoadStore(QualType
T,
return llvm::IntegerType::get(getLLVMContext(),
(unsigned)Context.getTypeSize(T));
+ if (T->isConstantMatrixBoolType()) {
+ // Matrices are loaded and stored atomically as vectors. Therefore we
+ // construct a FixedVectorType here instead of returning
+ // ConvertTypeForMem(T) which would return an ArrayType instead.
+ const Type *Ty = Context.getCanonicalType(T).getTypePtr();
+ const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty);
+ llvm::Type *IRElemTy = ConvertType(MT->getElementType());
+ if (Context.getLangOpts().HLSL && T->isConstantMatrixBoolType())
+ IRElemTy = ConvertTypeForMem(Context.BoolTy);
+ return llvm::FixedVectorType::get(IRElemTy,
+ MT->getNumRows() * MT->getNumColumns());
----------------
Icohedron wrote:
> should this code go in ConvertTypeForMem instead?
ConvertTypeForMem has the same logic but returns an ArrayType instead of a
FixedVectorType, which does not work.
Matrices are allocated in memory as arrays, but loaded/stored as vectors.
I'm not sure why this is the case but it is how it is currently implemented.
For example in a C++ codegen test:
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCXX/matrix-type.cpp#L29-L31
```llvm
%a.addr = alloca [9 x float], align 4
store <9 x float> %a, ptr %a.addr, align 4
```
https://github.com/llvm/llvm-project/pull/175245
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits