diff --git a/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp --- a/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp +++ b/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp @@ -358,6 +358,23 @@ } }; +//===----------------------------------------------------------------------===// +// ConvertVectorPrint +//===----------------------------------------------------------------------===// + +// This is primarily a convenience conversion pattern for integration tests +// with `mlir-cpu-runner`. +struct ConvertVectorPrint final : OpConversionPattern { + using OpConversionPattern::OpConversionPattern; + + LogicalResult + matchAndRewrite(vector::PrintOp op, OpAdaptor adaptor, + ConversionPatternRewriter &rewriter) const override { + rewriter.replaceOpWithNewOp(op, adaptor.getSource()); + return success(); + } +}; + //===----------------------------------------------------------------------===// // Pass Definition //===----------------------------------------------------------------------===// @@ -467,7 +484,7 @@ // Populate `arith.*` conversion patterns. patterns.add< // Misc ops. - ConvertConstant, + ConvertConstant, ConvertVectorPrint, // Binary ops. ConvertAddI, // Extension and truncation ops. diff --git a/mlir/test/Integration/Dialect/Arithmetic/CPU/lit.local.cfg b/mlir/test/Integration/Dialect/Arithmetic/CPU/lit.local.cfg new file mode 100644 --- /dev/null +++ b/mlir/test/Integration/Dialect/Arithmetic/CPU/lit.local.cfg @@ -0,0 +1,5 @@ +import sys + +# No JIT on win32. +if sys.platform == 'win32': + config.unsupported = True diff --git a/mlir/test/Integration/Dialect/Arithmetic/CPU/test-wide-int-emulation-constants-i16.mlir b/mlir/test/Integration/Dialect/Arithmetic/CPU/test-wide-int-emulation-constants-i16.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Integration/Dialect/Arithmetic/CPU/test-wide-int-emulation-constants-i16.mlir @@ -0,0 +1,44 @@ +// Check that the wide integer constant emulation produces the same result as wide +// constants and that printing works. Emulate i16 ops with i8 ops. + +// RUN: mlir-opt %s --arith-emulate-wide-int="widest-int-supported=8" \ +// RUN: --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \ +// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \ +// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ +// RUN: --shared-libs=%mlir_lib_dir/libmlir_c_runner_utils%shlibext | \ +// RUN: FileCheck %s --match-full-lines --check-prefix=EMULATED + +func.func @entry() { + %cst0 = arith.constant 0 : i16 + %cst1 = arith.constant 1 : i16 + %cst_1 = arith.constant -1 : i16 + %cst_3 = arith.constant -3 : i16 + + %cst13 = arith.constant 13 : i16 + %cst256 = arith.constant 256 : i16 + + %cst_i16_max = arith.constant 32767 : i16 + %cst_i16_min = arith.constant -32768 : i16 + + // EMULATED: ( 0, 0 ) + vector.print %cst0 : i16 + // EMULATED-NEXT: ( 1, 0 ) + vector.print %cst1 : i16 + + // EMULATED-NEXT: ( -1, -1 ) + vector.print %cst_1 : i16 + // EMULATED-NEXT: ( -3, -1 ) + vector.print %cst_3 : i16 + + // EMULATED-NEXT: ( 13, 0 ) + vector.print %cst13 : i16 + // EMULATED-NEXT: ( 0, 1 ) + vector.print %cst256 : i16 + + // EMULATED-NEXT: ( -1, 127 ) + vector.print %cst_i16_max : i16 + // EMULATED-NEXT: ( 0, -128 ) + vector.print %cst_i16_min : i16 + + return +}