diff --git a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp index 31d8cd2206148..baac1b374b126 100644 --- a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp +++ b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp @@ -225,6 +225,18 @@ struct IfOpConversion : SCFToSPIRVPattern { // subsequently converges. auto loc = ifOp.getLoc(); + // Compute return types. + SmallVector 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); + } + // Create `spirv.selection` operation, selection header block and merge // block. auto selectionOp = @@ -261,16 +273,6 @@ struct IfOpConversion : SCFToSPIRVPattern { thenBlock, ArrayRef(), elseBlock, ArrayRef()); - SmallVector 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, returnTypes); return success();