[Mlir-commits] [mlir] [MLIR][Math] add canonicalize-f32-promotion pass (PR #92482)
Krzysztof Drewniak
llvmlistbot at llvm.org
Tue May 21 09:22:42 PDT 2024
================
@@ -109,4 +135,14 @@ void LegalizeToF32Pass::runOnOperation() {
math::populateLegalizeToF32Patterns(patterns, typeConverter);
if (failed(applyPartialConversion(op, target, std::move(patterns))))
return signalPassFailure();
+
+ if (useCanonicalizeF32Promotion) {
----------------
krzysz00 wrote:
I don't really like this approach.
How about going up to `matchAndRewrite()` and doing this:
```c++
SmallVector<Value> extendedWidthOperands(operands);
for (auto [extended, original] : llvm::zip_equal(extendedWidthOperands, op->getOperands()) {
// match trunc/ext pair. The inelegant version is.
if (auto short = extended.getDefiningOp<arith::TruncFOp>()) {
auto maybeOriginal = extended.getIn().getDefiningOp<arith;:ExtFOp>());
if (maybeOriginal && maybeOriginal.getIn() == original)
extended = original;
}
convertOpResultTypes(..., extendedWidthOperands, ...);
```
Now, you don't need a pass option, and all you're doing is "if this is the extension of the truncation of my original argument, use that original argument instead".
https://github.com/llvm/llvm-project/pull/92482
More information about the Mlir-commits
mailing list