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,19 @@ } auto mapping = result.getInputMapping(i); assert(mapping && "unexpected deletion of function argument"); + // Only attach the new argument attributes if there is a one-to-one + // mapping from old to new types. Otherwise, attributes might be + // attached to types that they do not support. + if (mapping->size == 1) { + newArgAttrs[mapping->inputNo] = + DictionaryAttr::get(rewriter.getContext(), convertedAttrs); + continue; + } + // TODO: Implement custom handling for types that expand to multiple + // function arguments. for (size_t j = 0; 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,17 +1,20 @@ // 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} -func.func @check_attributes(%static: memref<10x20xf32> {dialect.a = true, dialect.b = 4 : i64 }) { +// CHECK-SAME: {dialect.a = true, dialect.b = 4 : i64} +func.func @check_attributes(%int: i64 {dialect.a = true, dialect.b = 4 : i64 }) { + return +} + +// CHECK-LABEL: func @check_memref +// When expanding the memref to multiple arguments, argument attributes should be dropped entirely. +// CHECK-NOT: {llvm.noalias} +func.func @check_memref(%static: memref<10x20xf32> {llvm.noalias}) { return } // 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}) -func.func @check_multiple(%first: memref {first.arg = true}, %second: memref {second.arg = 42 : i32}) { +// CHECK-SAME: %{{.*}}: f32 {first.arg = true}, %{{.*}}: i64 {second.arg = 42 : i32} +func.func @check_multiple(%first: f32 {first.arg = true}, %second: i64 {second.arg = 42 : i32}) { return }