Index: mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td =================================================================== --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -138,6 +138,7 @@ def LLVM_ShlOp : LLVM_ArithmeticOp<"shl", "CreateShl">; def LLVM_LShrOp : LLVM_ArithmeticOp<"lshr", "CreateLShr">; def LLVM_AShrOp : LLVM_ArithmeticOp<"ashr", "CreateAShr">; +def LLVM_NegOp : LLVM_UnaryArithmeticOp<"neg", "CreateNeg">; // Predicate for integer comparisons. def ICmpPredicateEQ : I64EnumAttrCase<"eq", 0>; Index: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td =================================================================== --- mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -76,6 +76,10 @@ }]; } +class IntegerUnaryOp traits = []> : + UnaryOpSameOperandAndResultType, + Arguments<(ins SignlessIntegerLike:$operand)>; + class FloatUnaryOp traits = []> : UnaryOpSameOperandAndResultType, Arguments<(ins FloatLike:$operand)>; @@ -1042,6 +1046,16 @@ }]; } +def NegIOp : IntegerUnaryOp<"negi"> { + let summary = "integer negation"; + let description = [{ + The `negi` operation computes the negation of a given value. It takes one + operand and returns one result of the same type. This type may be a integer + scalar type, a vector whose element type is integer, or a tensor of integers. + It has no standard attributes. + }]; +} + def OrOp : IntArithmeticOp<"or", [Commutative]> { let summary = "integer binary or"; let hasFolder = 1; Index: mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp =================================================================== --- mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp +++ mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp @@ -1259,6 +1259,9 @@ struct NegFOpLowering : public UnaryOpLLVMOpLowering { using Super::Super; }; +struct NegIOpLowering : public UnaryOpLLVMOpLowering { + using Super::Super; +}; struct AddIOpLowering : public BinaryOpLLVMOpLowering { using Super::Super; }; @@ -2802,6 +2805,7 @@ MulFOpLowering, MulIOpLowering, NegFOpLowering, + NegIOpLowering, OrOpLowering, PrefetchOpLowering, RemFOpLowering,