diff --git a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp --- a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp +++ b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp @@ -96,6 +96,9 @@ Location loc = scfOp.getLoc(); auto &allocas = scfToSPIRVContext->outputVars[newOp]; + // Clearing the allocas is necessary in case a dialect conversion path failed + // previously, and this is the second attempt of this conversion. + allocas.clear(); SmallVector resultValue; for (Type convertedType : returnTypes) { auto pointerType = @@ -214,12 +217,13 @@ auto selectionControl = rewriter.getI32IntegerAttr( static_cast(spirv::SelectionControl::None)); auto selectionOp = rewriter.create(loc, selectionControl); - selectionOp.addMergeBlock(); - auto *mergeBlock = selectionOp.getMergeBlock(); + auto *mergeBlock = + rewriter.createBlock(&selectionOp.body(), selectionOp.body().end()); + rewriter.create(loc); OpBuilder::InsertionGuard guard(rewriter); - auto *selectionHeaderBlock = new Block(); - selectionOp.body().getBlocks().push_front(selectionHeaderBlock); + auto *selectionHeaderBlock = + rewriter.createBlock(&selectionOp.body().front()); // Inline `then` region before the merge block and branch to it. auto &thenRegion = ifOp.thenRegion();