Skip to content

Commit 4a38995

Browse files
committed
[mlir][arith] Validate pass options in arith-int-narrowing
Exist gracefully instead of triggering an assertions. Fixes: #64257 Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D156694
1 parent 955fc63 commit 4a38995

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ struct ArithIntNarrowingPass final
748748
using ArithIntNarrowingBase::ArithIntNarrowingBase;
749749

750750
void runOnOperation() override {
751+
if (bitwidthsSupported.empty() ||
752+
llvm::is_contained(bitwidthsSupported, 0)) {
753+
// Invalid pass options.
754+
return signalPassFailure();
755+
}
756+
751757
Operation *op = getOperation();
752758
MLIRContext *ctx = op->getContext();
753759
RewritePatternSet patterns(ctx);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: not mlir-opt %s --arith-int-narrowing --mlir-print-ir-after-failure 2>&1 \
2+
// RUN: | FileCheck %s
3+
4+
// RUN: not mlir-opt %s --arith-int-narrowing="int-bitwidths-supported=0" \
5+
// RUN: --mlir-print-ir-after-failure 2>&1 | FileCheck %s
6+
7+
// Make sure we do not crash on invalid pass options.
8+
9+
// CHECK: IR Dump After ArithIntNarrowing Failed (arith-int-narrowing)
10+
// CHECK-LABEL: func.func @addi_extsi_i8
11+
func.func @addi_extsi_i8(%lhs: i8, %rhs: i8) -> i32 {
12+
%a = arith.extsi %lhs : i8 to i32
13+
%b = arith.extsi %rhs : i8 to i32
14+
%r = arith.addi %a, %b : i32
15+
return %r : i32
16+
}

0 commit comments

Comments
 (0)