[Mlir-commits] [mlir] 4a38995 - [mlir][arith] Validate pass options in arith-int-narrowing
Jakub Kuderski
llvmlistbot at llvm.org
Mon Jul 31 08:32:28 PDT 2023
Author: Jakub Kuderski
Date: 2023-07-31T11:32:01-04:00
New Revision: 4a3899577ae038b8b640620eb38d02a34988c732
URL: https://github.com/llvm/llvm-project/commit/4a3899577ae038b8b640620eb38d02a34988c732
DIFF: https://github.com/llvm/llvm-project/commit/4a3899577ae038b8b640620eb38d02a34988c732.diff
LOG: [mlir][arith] Validate pass options in arith-int-narrowing
Exist gracefully instead of triggering an assertions.
Fixes: https://github.com/llvm/llvm-project/issues/64257
Reviewed By: springerm
Differential Revision: https://reviews.llvm.org/D156694
Added:
mlir/test/Dialect/Arith/int-narrowing-invalid-options.mlir
Modified:
mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp b/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp
index 4f294e6e4c91ee..f7303a479449b7 100644
--- a/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp
@@ -748,6 +748,12 @@ struct ArithIntNarrowingPass final
using ArithIntNarrowingBase::ArithIntNarrowingBase;
void runOnOperation() override {
+ if (bitwidthsSupported.empty() ||
+ llvm::is_contained(bitwidthsSupported, 0)) {
+ // Invalid pass options.
+ return signalPassFailure();
+ }
+
Operation *op = getOperation();
MLIRContext *ctx = op->getContext();
RewritePatternSet patterns(ctx);
diff --git a/mlir/test/Dialect/Arith/int-narrowing-invalid-options.mlir b/mlir/test/Dialect/Arith/int-narrowing-invalid-options.mlir
new file mode 100644
index 00000000000000..0e34108973b4c9
--- /dev/null
+++ b/mlir/test/Dialect/Arith/int-narrowing-invalid-options.mlir
@@ -0,0 +1,16 @@
+// RUN: not mlir-opt %s --arith-int-narrowing --mlir-print-ir-after-failure 2>&1 \
+// RUN: | FileCheck %s
+
+// RUN: not mlir-opt %s --arith-int-narrowing="int-bitwidths-supported=0" \
+// RUN: --mlir-print-ir-after-failure 2>&1 | FileCheck %s
+
+// Make sure we do not crash on invalid pass options.
+
+// CHECK: IR Dump After ArithIntNarrowing Failed (arith-int-narrowing)
+// CHECK-LABEL: func.func @addi_extsi_i8
+func.func @addi_extsi_i8(%lhs: i8, %rhs: i8) -> i32 {
+ %a = arith.extsi %lhs : i8 to i32
+ %b = arith.extsi %rhs : i8 to i32
+ %r = arith.addi %a, %b : i32
+ return %r : i32
+}
More information about the Mlir-commits
mailing list