Author: Florian Hahn Date: 2020-11-18T11:44:11Z New Revision: 680931af2757fb495c5727d335ffa580fb3dbe98
URL: https://github.com/llvm/llvm-project/commit/680931af2757fb495c5727d335ffa580fb3dbe98 DIFF: https://github.com/llvm/llvm-project/commit/680931af2757fb495c5727d335ffa580fb3dbe98.diff LOG: [Matrix] Adjust matrix pointer type for inline asm arguments. Matrix types in memory are represented as arrays, but accessed through vector pointers, with the alignment specified on the access operation. For inline assembly, update pointer arguments to use vector pointers. Otherwise there will be a mis-match if the matrix is also an input-argument which is represented as vector. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D91631 Added: Modified: clang/lib/CodeGen/CGStmt.cpp clang/test/CodeGen/matrix-type.c Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index d8be0ef4e525..d67e73a2ec3b 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2306,8 +2306,21 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { std::max((uint64_t)LargestVectorWidth, VT->getPrimitiveSizeInBits().getKnownMinSize()); } else { - ArgTypes.push_back(Dest.getAddress(*this).getType()); - Args.push_back(Dest.getPointer(*this)); + llvm::Type *DestAddrTy = Dest.getAddress(*this).getType(); + llvm::Value *DestPtr = Dest.getPointer(*this); + // Matrix types in memory are represented by arrays, but accessed through + // vector pointers, with the alignment specified on the access operation. + // For inline assembly, update pointer arguments to use vector pointers. + // Otherwise there will be a mis-match if the matrix is also an + // input-argument which is represented as vector. + if (isa<MatrixType>(OutExpr->getType().getCanonicalType())) { + DestAddrTy = llvm::PointerType::get( + ConvertType(OutExpr->getType()), + cast<llvm::PointerType>(DestAddrTy)->getAddressSpace()); + DestPtr = Builder.CreateBitCast(DestPtr, DestAddrTy); + } + ArgTypes.push_back(DestAddrTy); + Args.push_back(DestPtr); Constraints += "=*"; Constraints += OutputConstraint; ReadOnly = ReadNone = false; diff --git a/clang/test/CodeGen/matrix-type.c b/clang/test/CodeGen/matrix-type.c index 399984b50c69..ab239a247b1d 100644 --- a/clang/test/CodeGen/matrix-type.c +++ b/clang/test/CodeGen/matrix-type.c @@ -162,10 +162,10 @@ void matrix_inline_asm_memory_readwrite() { // CHECK-LABEL: define void @matrix_inline_asm_memory_readwrite() // CHECK-NEXT: entry: // CHECK-NEXT: [[ALLOCA:%.+]] = alloca [16 x double], align 8 - // CHECK-NEXT: [[PTR:%.+]] = bitcast [16 x double]* [[ALLOCA]] to <16 x double>* - // CHECK-NEXT: [[VAL:%.+]] = load <16 x double>, <16 x double>* [[PTR]], align 8 - // FIXME: Pointer element type does not match the vector type. - // CHECK-NEXT: call void asm sideeffect "", "=*r|m,0,~{memory},~{dirflag},~{fpsr},~{flags}"([16 x double]* [[ALLOCA]], <16 x double> [[VAL]]) + // CHECK-NEXT: [[PTR1:%.+]] = bitcast [16 x double]* [[ALLOCA]] to <16 x double>* + // CHECK-NEXT: [[PTR2:%.+]] = bitcast [16 x double]* [[ALLOCA]] to <16 x double>* + // CHECK-NEXT: [[VAL:%.+]] = load <16 x double>, <16 x double>* [[PTR2]], align 8 + // CHECK-NEXT: call void asm sideeffect "", "=*r|m,0,~{memory},~{dirflag},~{fpsr},~{flags}"(<16 x double>* [[PTR1]], <16 x double> [[VAL]]) // CHECK-NEXT: ret void dx4x4_t m; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits