[mlir][Vector] Add check of supported reduction kind for ScanOp.

This patch adds check of supported reduction kind for ScanOp to avoid using and/or/xor for floating point type.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123977
This commit is contained in:
jacquesguan 2022-04-19 03:40:39 +00:00
parent 752c9122a6
commit 61baf2ffa7
2 changed files with 16 additions and 0 deletions

View File

@ -4588,6 +4588,13 @@ LogicalResult ScanOp::verify() {
return emitOpError("incompatible input/initial value shapes");
}
// Verify supported reduction kind.
Type eltType = getDestType().getElementType();
if (!isSupportedCombiningKind(getKind(), eltType))
return emitOpError("unsupported reduction type ")
<< eltType << " for kind '" << stringifyCombiningKind(getKind())
<< "'";
return success();
}

View File

@ -1523,6 +1523,15 @@ func @scan_incompatible_shapes(%arg0: vector<2x3xi32>, %arg1: vector<5xi32>) ->
// -----
func @scan_unsupported_kind(%arg0: vector<2x3xf32>, %arg1: vector<3xf32>) -> vector<2x3xf32> {
// expected-error@+1 {{'vector.scan' op unsupported reduction type 'f32' for kind 'xor'}}
%0:2 = vector.scan <xor>, %arg0, %arg1 {inclusive = true, reduction_dim = 0} :
vector<2x3xf32>, vector<3xf32>
return %0#0 : vector<2x3xf32>
}
// -----
func @invalid_splat(%v : f32) {
// expected-error@+1 {{invalid kind of type specified}}
vector.splat %v : memref<8xf32>