From 9fc00cf8402ea6b9866479e704db6ecd29e9f95b Mon Sep 17 00:00:00 2001 From: River Riddle Date: Wed, 5 Jun 2019 10:08:47 -0700 Subject: [PATCH] Always remap results when replacing an operation. This prevents a crash when lowering identity(passthrough) operations to the same resultant type as the original operation. PiperOrigin-RevId: 251665492 --- mlir/lib/Transforms/DialectConversion.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mlir/lib/Transforms/DialectConversion.cpp b/mlir/lib/Transforms/DialectConversion.cpp index 333214efcc05..66474348ca22 100644 --- a/mlir/lib/Transforms/DialectConversion.cpp +++ b/mlir/lib/Transforms/DialectConversion.cpp @@ -171,11 +171,14 @@ struct DialectConversionRewriter final : public PatternRewriter { void replaceOp(Operation *op, ArrayRef newValues, ArrayRef valuesToRemoveIfDead) override { assert(newValues.size() == op->getNumResults()); - // Create mappings for any type changes. - for (unsigned i = 0, e = newValues.size(); i < e; ++i) - if (newValues[i] && - op->getResult(i)->getType() != newValues[i]->getType()) + + // Create mappings for each of the new result values. + for (unsigned i = 0, e = newValues.size(); i < e; ++i) { + assert((newValues[i] || op->getResult(i)->use_empty()) && + "result value has remaining uses that must be replaced"); + if (newValues[i]) mapping.map(op->getResult(i), newValues[i]); + } // Record the requested operation replacement. replacements.emplace_back(op, newValues);