diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -720,9 +720,20 @@ Block *newBlock = block->splitBlock(block->begin()); block->replaceAllUsesWith(newBlock); - // FIXME: We should map the new arguments to proper locations. - SmallVector newLocs(convertedTypes.size(), - rewriter.getUnknownLoc()); + // Map all new arguments to the location of the argument they originate from. + SmallVector newLocs; + for (unsigned i = 0; i != origArgCount; ++i) { + auto inputMap = signatureConversion.getInputMapping(i); + if (!inputMap || inputMap->replacementValue) + continue; + Location origLoc = block->getArgument(i).getLoc(); + for (unsigned j = 0; j < inputMap->size; ++j) + newLocs.push_back(origLoc); + } + // Add unknown locations for newly-added argument. + for (unsigned i = newLocs.size(), n = convertedTypes.size(); i < n; ++i) + newLocs.push_back(rewriter.getUnknownLoc()); + SmallVector newArgRange( newBlock->addArguments(convertedTypes, newLocs)); ArrayRef newArgs(newArgRange);