@@ -225,6 +225,18 @@ struct IfOpConversion : SCFToSPIRVPattern<scf::IfOp> {
225225 // subsequently converges.
226226 auto loc = ifOp.getLoc ();
227227
228+ // Compute return types.
229+ SmallVector<Type, 8 > returnTypes;
230+ for (auto result : ifOp.getResults ()) {
231+ auto convertedType = typeConverter.convertType (result.getType ());
232+ if (!convertedType)
233+ return rewriter.notifyMatchFailure (
234+ loc,
235+ llvm::formatv (" failed to convert type '{0}'" , result.getType ()));
236+
237+ returnTypes.push_back (convertedType);
238+ }
239+
228240 // Create `spirv.selection` operation, selection header block and merge
229241 // block.
230242 auto selectionOp =
@@ -261,16 +273,6 @@ struct IfOpConversion : SCFToSPIRVPattern<scf::IfOp> {
261273 thenBlock, ArrayRef<Value>(),
262274 elseBlock, ArrayRef<Value>());
263275
264- SmallVector<Type, 8 > returnTypes;
265- for (auto result : ifOp.getResults ()) {
266- auto convertedType = typeConverter.convertType (result.getType ());
267- if (!convertedType)
268- return rewriter.notifyMatchFailure (
269- loc,
270- llvm::formatv (" failed to convert type '{0}'" , result.getType ()));
271-
272- returnTypes.push_back (convertedType);
273- }
274276 replaceSCFOutputValue (ifOp, selectionOp, rewriter, scfToSPIRVContext,
275277 returnTypes);
276278 return success ();
0 commit comments