diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp --- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp +++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp @@ -354,9 +354,15 @@ } auto mapping = result.getInputMapping(i); assert(mapping && "unexpected deletion of function argument"); - for (size_t j = 0; j < mapping->size; ++j) + // Only attach the new argument attrs to the first type corresponding to + // it. Otherwise, attributes might be attached to types that they do not + // support. + newArgAttrs[mapping->inputNo] = + DictionaryAttr::get(rewriter.getContext(), convertedAttrs); + for (size_t j = 1; j < mapping->size; ++j) { newArgAttrs[mapping->inputNo + j] = - DictionaryAttr::get(rewriter.getContext(), convertedAttrs); + DictionaryAttr::get(rewriter.getContext(), {}); + } } attributes.push_back(rewriter.getNamedAttr( funcOp.getArgAttrsAttrName(), rewriter.getArrayAttr(newArgAttrs))); diff --git a/mlir/test/Conversion/FuncToLLVM/convert-argattrs.mlir b/mlir/test/Conversion/FuncToLLVM/convert-argattrs.mlir --- a/mlir/test/Conversion/FuncToLLVM/convert-argattrs.mlir +++ b/mlir/test/Conversion/FuncToLLVM/convert-argattrs.mlir @@ -1,8 +1,9 @@ // RUN: mlir-opt -convert-func-to-llvm %s | FileCheck %s // CHECK-LABEL: func @check_attributes -// When expanding the memref to multiple arguments, argument attributes are replicated. -// CHECK-COUNT-7: {dialect.a = true, dialect.b = 4 : i64} +// When expanding the memref to multiple arguments, argument attributes are only applied to the first pointer. +// CHECK-SAME: !llvm.ptr {dialect.a = true, dialect.b = 4 : i64} +// CHECK-NOT: {dialect.a = true, dialect.b = 4 : i64} func.func @check_attributes(%static: memref<10x20xf32> {dialect.a = true, dialect.b = 4 : i64 }) { return } @@ -10,8 +11,8 @@ // CHECK-LABEL: func @check_multiple // Make sure arguments attributes are attached to the right argument. We match // commas in the argument list for this purpose. -// CHECK: %{{.*}}: !llvm{{.*}} {first.arg = true}, %{{.*}}: !llvm{{.*}} {first.arg = true}, %{{.*}}: i{{.*}} {first.arg = true}, -// CHECK-SAME: %{{.*}}: !llvm{{.*}} {second.arg = 42 : i32}, %{{.*}}: !llvm{{.*}} {second.arg = 42 : i32}, %{{.*}}: i{{.*}} {second.arg = 42 : i32}) +// CHECK: %{{.*}}: !llvm.ptr {first.arg = true}, %{{[a-z0-9]*}}: !llvm.ptr, %{{[a-z0-9]*}}: i{{[0-9]*}}, +// CHECK-SAME: %{{.*}}: !llvm{{.*}} {second.arg = 42 : i32}, %{{.*}}: !llvm{{.*}}, %{{.*}}: i{{.*}}) func.func @check_multiple(%first: memref {first.arg = true}, %second: memref {second.arg = 42 : i32}) { return }