Skip to content

Commit 9d441f7

Browse files
kuharDanielCChen
authored andcommitted
[mlir][arith] Fix type conversion in emulate-wide-int (llvm#112104)
Use `nullptr` to indicate that type conversion failed and no fallback conversion should be attempted. Fixes: llvm#108163
1 parent 0f6ea9f commit 9d441f7

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ arith::WideIntEmulationConverter::WideIntEmulationConverter(
10811081
if (width == 2 * maxIntWidth)
10821082
return VectorType::get(2, IntegerType::get(ty.getContext(), maxIntWidth));
10831083

1084-
return std::nullopt;
1084+
return nullptr;
10851085
});
10861086

10871087
// Vector case.
@@ -1102,7 +1102,7 @@ arith::WideIntEmulationConverter::WideIntEmulationConverter(
11021102
IntegerType::get(ty.getContext(), maxIntWidth));
11031103
}
11041104

1105-
return std::nullopt;
1105+
return nullptr;
11061106
});
11071107

11081108
// Function case.
@@ -1111,11 +1111,11 @@ arith::WideIntEmulationConverter::WideIntEmulationConverter(
11111111
// (i2N, i2N) -> i2N --> (vector<2xiN>, vector<2xiN>) -> vector<2xiN>
11121112
SmallVector<Type> inputs;
11131113
if (failed(convertTypes(ty.getInputs(), inputs)))
1114-
return std::nullopt;
1114+
return nullptr;
11151115

11161116
SmallVector<Type> results;
11171117
if (failed(convertTypes(ty.getResults(), results)))
1118-
return std::nullopt;
1118+
return nullptr;
11191119

11201120
return FunctionType::get(ty.getContext(), inputs, results);
11211121
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: mlir-opt --arith-emulate-wide-int="widest-int-supported=32" \
2+
// RUN: --split-input-file --verify-diagnostics %s
3+
4+
// Make sure we do not crash on unsupported types.
5+
6+
// Unsupported result type in `arith.extsi`.
7+
func.func @unsupported_result_integer(%arg0: i64) -> i64 {
8+
// expected-error@+1 {{failed to legalize operation 'arith.extsi' that was explicitly marked illegal}}
9+
%0 = arith.extsi %arg0: i64 to i128
10+
%2 = arith.muli %0, %0 : i128
11+
%3 = arith.trunci %2 : i128 to i64
12+
return %3 : i64
13+
}
14+
15+
// -----
16+
17+
// Unsupported result type in `arith.extsi`.
18+
func.func @unsupported_result_vector(%arg0: vector<4xi64>) -> vector<4xi64> {
19+
// expected-error@+1 {{failed to legalize operation 'arith.extsi' that was explicitly marked illegal}}
20+
%0 = arith.extsi %arg0: vector<4xi64> to vector<4xi128>
21+
%2 = arith.muli %0, %0 : vector<4xi128>
22+
%3 = arith.trunci %2 : vector<4xi128> to vector<4xi64>
23+
return %3 : vector<4xi64>
24+
}
25+
26+
// -----
27+
28+
// Unsupported function return type.
29+
// expected-error@+1 {{failed to legalize operation 'func.func' that was explicitly marked illegal}}
30+
func.func @unsupported_return_type(%arg0: vector<4xi64>) -> vector<4xi128> {
31+
%0 = arith.extsi %arg0: vector<4xi64> to vector<4xi128>
32+
return %0 : vector<4xi128>
33+
}
34+
35+
// -----
36+
37+
// Unsupported function argument type.
38+
// expected-error@+1 {{failed to legalize operation 'func.func' that was explicitly marked illegal}}
39+
func.func @unsupported_argument_type(%arg0: vector<4xi128>) -> vector<4xi64> {
40+
%0 = arith.trunci %arg0: vector<4xi128> to vector<4xi64>
41+
return %0 : vector<4xi64>
42+
}
43+

0 commit comments

Comments
 (0)