[Mlir-commits] [mlir] [mlir][Transforms][NFC] Dialect Conversion: Replace after legalizing constants (PR #134384)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Apr 4 07:06:01 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
When folding an op during a conversion, first try to legalize all generated constants, then replace the original operation. This is slightly more efficient because fewer rewrites must be rolled back in case a generated constant could not be legalized.
Note: This is in preparation of the One-Shot Dialect Conversion refactoring.
---
Full diff: https://github.com/llvm/llvm-project/pull/134384.diff
1 Files Affected:
- (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+3-3)
``````````diff
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 444c505b64232..0b342a0e5d4bc 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2109,9 +2109,6 @@ OperationLegalizer::legalizeWithFold(Operation *op,
if (replacementValues.empty())
return legalize(op, rewriter);
- // Insert a replacement for 'op' with the folded replacement values.
- rewriter.replaceOp(op, replacementValues);
-
// Recursively legalize any new constant operations.
for (unsigned i = curState.numRewrites, e = rewriterImpl.rewrites.size();
i != e; ++i) {
@@ -2128,6 +2125,9 @@ OperationLegalizer::legalizeWithFold(Operation *op,
}
}
+ // Insert a replacement for 'op' with the folded replacement values.
+ rewriter.replaceOp(op, replacementValues);
+
LLVM_DEBUG(logSuccess(rewriterImpl.logger, ""));
return success();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/134384
More information about the Mlir-commits
mailing list