[Mlir-commits] [mlir] 80d5400 - [mlir][spirv] Account for type conversion failures in scf-to-spirv
Jakub Kuderski
llvmlistbot at llvm.org
Mon Jan 9 08:36:59 PST 2023
Author: Jakub Kuderski
Date: 2023-01-09T11:35:47-05:00
New Revision: 80d5400d924e543c5420f4e924f5818313605e99
URL: https://github.com/llvm/llvm-project/commit/80d5400d924e543c5420f4e924f5818313605e99
DIFF: https://github.com/llvm/llvm-project/commit/80d5400d924e543c5420f4e924f5818313605e99.diff
LOG: [mlir][spirv] Account for type conversion failures in scf-to-spirv
Fixes: https://github.com/llvm/llvm-project/issues/59136
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D141292
Added:
Modified:
mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
mlir/test/Conversion/SCFToSPIRV/if.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
index c91d2a200df8a..00062ef4a7a91 100644
--- a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
+++ b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
@@ -17,6 +17,7 @@
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Transforms/DialectConversion.h"
+#include "llvm/Support/FormatVariadic.h"
using namespace mlir;
@@ -286,6 +287,10 @@ IfOpConversion::matchAndRewrite(scf::IfOp ifOp, OpAdaptor adaptor,
SmallVector<Type, 8> returnTypes;
for (auto result : ifOp.getResults()) {
auto convertedType = typeConverter.convertType(result.getType());
+ if (!convertedType)
+ return rewriter.notifyMatchFailure(
+ loc, llvm::formatv("failed to convert type '{0}'", result.getType()));
+
returnTypes.push_back(convertedType);
}
replaceSCFOutputValue(ifOp, selectionOp, rewriter, scfToSPIRVContext,
diff --git a/mlir/test/Conversion/SCFToSPIRV/if.mlir b/mlir/test/Conversion/SCFToSPIRV/if.mlir
index 3a2de3338c3f6..2c18da41dc021 100644
--- a/mlir/test/Conversion/SCFToSPIRV/if.mlir
+++ b/mlir/test/Conversion/SCFToSPIRV/if.mlir
@@ -153,4 +153,18 @@ func.func @simple_if_yield_type_change(%arg2 : memref<10xf32, #spirv.storage_cla
return
}
+// Memrefs without a spirv storage class are not supported. The conversion
+// should preserve the `scf.if` and not crash.
+func.func @unsupported_yield_type(%arg0 : memref<8xi32>, %arg1 : memref<8xi32>, %c : i1) {
+// CHECK-LABEL: @unsupported_yield_type
+// CHECK-NEXT: scf.if
+// CHECK: spirv.Return
+ %r = scf.if %c -> (memref<8xi32>) {
+ scf.yield %arg0 : memref<8xi32>
+ } else {
+ scf.yield %arg1 : memref<8xi32>
+ }
+ return
+}
+
} // end module
More information about the Mlir-commits
mailing list