Index: mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td =================================================================== --- mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -49,6 +49,8 @@ static StringRef getStructRetAttrName() { return "llvm.sret"; } static StringRef getInAllocaAttrName() { return "llvm.inalloca"; } static StringRef getNoUndefAttrName() { return "llvm.noundef"; } + static StringRef getSExtAttrName() { return "llvm.signext"; } + static StringRef getZExtAttrName() { return "llvm.zeroext"; } /// Verifies if the attribute is a well-formed value for "llvm.struct_attrs" static LogicalResult verifyStructAttr( Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -989,6 +989,25 @@ llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()) .addAttribute(llvm::Attribute::NoUndef)); } + if (auto attr = function.getArgAttrOfType( + argIdx, LLVMDialect::getSExtAttrName())) { + // llvm.signext can be added to any integer argument type. + if (!mlirArgTy.isa()) + return function.emitError( + "llvm.signext attribute attached to LLVM non-integer argument"); + llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()) + .addAttribute(llvm::Attribute::SExt)); + } + if (auto attr = function.getArgAttrOfType( + argIdx, LLVMDialect::getZExtAttrName())) { + // llvm.zeroext can be added to any integer argument type. + if (!mlirArgTy.isa()) + return function.emitError( + "llvm.zeroext attribute attached to LLVM non-integer argument"); + llvmArg.addAttrs(llvm::AttrBuilder(llvmArg.getContext()) + .addAttribute(llvm::Attribute::ZExt)); + } + ++argIdx; } Index: mlir/test/Target/LLVMIR/llvmir-invalid.mlir =================================================================== --- mlir/test/Target/LLVMIR/llvmir-invalid.mlir +++ mlir/test/Target/LLVMIR/llvmir-invalid.mlir @@ -83,6 +83,20 @@ // ----- +// expected-error@+1{{llvm.signext attribute attached to LLVM non-integer argument}} +llvm.func @invalid_signext(%arg0: f32 {llvm.signext}) { + "llvm.return"() : () -> () +} + +// ----- + +// expected-error@+1{{llvm.zeroext attribute attached to LLVM non-integer argument}} +llvm.func @invalid_zeroext(%arg0: f32 {llvm.zeroext}) { + "llvm.return"() : () -> () +} + +// ----- + llvm.func @no_non_complex_struct() -> !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> { // expected-error @below{{expected struct type to be a complex number}} %0 = llvm.mlir.constant(dense<[[[1, 2], [3, 4]], [[42, 43], [44, 45]]]> : tensor<2x2x2xi32>) : !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> Index: mlir/test/Target/LLVMIR/llvmir.mlir =================================================================== --- mlir/test/Target/LLVMIR/llvmir.mlir +++ mlir/test/Target/LLVMIR/llvmir.mlir @@ -1108,6 +1108,22 @@ // CHECK-LABEL: declare void @inallocaattr_decl(ptr inalloca(i32)) llvm.func @inallocaattr_decl(!llvm.ptr {llvm.inalloca = i32}) +// CHECK-LABEL: define void @signextattr(i1 signext % +llvm.func @signextattr(%arg0: i1 {llvm.signext}) { + llvm.return +} + +// CHECK-LABEL: declare void @signextattr_decl(i1 signext) +llvm.func @signextattr_decl(i1 {llvm.signext}) + +// CHECK-LABEL: define void @zeroextattr(i1 zeroext % +llvm.func @zeroextattr(%arg0: i1 {llvm.zeroext}) { + llvm.return +} + +// CHECK-LABEL: declare void @zeroextattr_decl(i1 zeroext) +llvm.func @zeroextattr_decl(i1 {llvm.zeroext}) + // CHECK-LABEL: @llvm_varargs(...) llvm.func @llvm_varargs(...)