[Mlir-commits] [mlir] [MLIR] Handle materializeConstant failure in GreedyPatternRewriteDriver (PR #77258)
Billy Zhu
llvmlistbot at llvm.org
Mon Jan 8 09:57:46 PST 2024
================
@@ -462,18 +463,38 @@ bool GreedyPatternRewriteDriver::processWorklist() {
// Materialize Attributes as SSA values.
Operation *constOp = op->getDialect()->materializeConstant(
*this, ofr.get<Attribute>(), resultType, op->getLoc());
+
+ if (!constOp) {
+ // If materialization fails, cleanup any operations generated for
+ // the previous results.
+ llvm::SmallDenseSet<Operation *> replacementOps;
+ std::transform(replacements.begin(), replacements.end(),
+ replacementOps.begin(), [](Value replacement) {
+ return replacement.getDefiningOp();
+ });
+ for (Operation *op : replacementOps)
+ eraseOp(op);
----------------
zyx-billy wrote:
Ah good point. Let me add the check.
https://github.com/llvm/llvm-project/pull/77258
More information about the Mlir-commits
mailing list