diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -1285,7 +1285,12 @@ << refName << "'"; return failure(); } + auto *tempMD = cast(descNode->getOperand(opNum).get()); descNode->replaceOperandWith(opNum, refNode); + // Deallocate temporary MDNode's explicitly. + // Note that each temporary node has a single use by creation, + // so it is valid to deallocate it here. + llvm::MDNode::deleteTemporary(tempMD); } } }