[Mlir-commits] [mlir] e41498d - [mlir][arith] Add initial files for (runtime) integration tests
Jakub Kuderski
llvmlistbot at llvm.org
Fri Sep 16 08:53:06 PDT 2022
Author: Jakub Kuderski
Date: 2022-09-16T11:52:48-04:00
New Revision: e41498dddb00e6a44f77315039ee288266bddf71
URL: https://github.com/llvm/llvm-project/commit/e41498dddb00e6a44f77315039ee288266bddf71
DIFF: https://github.com/llvm/llvm-project/commit/e41498dddb00e6a44f77315039ee288266bddf71.diff
LOG: [mlir][arith] Add initial files for (runtime) integration tests
The goal is to have a set of runtime tests for further extercise the
wide integer emulation pass and its conversion patterns. This was
suggested by @Mogball in D133629.
Add a minimal runtime test to demonstrate that printing and pass
pipeline works as expected.
Reviewed By: Mogball
Differential Revision: https://reviews.llvm.org/D134004
Added:
mlir/test/Integration/Dialect/Arithmetic/CPU/lit.local.cfg
mlir/test/Integration/Dialect/Arithmetic/CPU/test-wide-int-emulation-constants-i16.mlir
Modified:
mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp
index 7716f618d9e5e..1c4189c27c2df 100644
--- a/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp
+++ b/mlir/lib/Dialect/Arithmetic/Transforms/EmulateWideInt.cpp
@@ -358,6 +358,23 @@ struct ConvertTruncI final : OpConversionPattern<arith::TruncIOp> {
}
};
+//===----------------------------------------------------------------------===//
+// ConvertVectorPrint
+//===----------------------------------------------------------------------===//
+
+// This is primarily a convenience conversion pattern for integration tests
+// with `mlir-cpu-runner`.
+struct ConvertVectorPrint final : OpConversionPattern<vector::PrintOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::PrintOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ rewriter.replaceOpWithNewOp<vector::PrintOp>(op, adaptor.getSource());
+ return success();
+ }
+};
+
//===----------------------------------------------------------------------===//
// Pass Definition
//===----------------------------------------------------------------------===//
@@ -467,7 +484,7 @@ void arith::populateWideIntEmulationPatterns(
// 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
index 0000000000000..83247d7e37449
--- /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
index 0000000000000..8cc5ceba06522
--- /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
+}
More information about the Mlir-commits
mailing list