[Mlir-commits] [mlir] [MLIR][Transforms] add eliminate-explicit-rounding pass (PR #93443)

Krzysztof Drewniak llvmlistbot at llvm.org
Fri Jun 7 08:29:07 PDT 2024


================
@@ -1410,6 +1410,39 @@ bool arith::ExtFOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
 
 LogicalResult arith::ExtFOp::verify() { return verifyExtOp<FloatType>(*this); }
 
+struct SimplifyExtFTruncFOpPair : public OpRewritePattern<ExtFOp> {
+  using OpRewritePattern<ExtFOp>::OpRewritePattern;
+
+  LogicalResult matchAndRewrite(ExtFOp extFOp,
+                                PatternRewriter &rewriter) const override {
+    if (auto truncFOp = extFOp.getOperand().getDefiningOp<TruncFOp>()) {
+      Value input = truncFOp.getOperand();
+      Type inTy = getElementTypeOrSelf(input.getType());
+      Type outTy = getElementTypeOrSelf(extFOp.getType());
+      Type shortTy = getElementTypeOrSelf(truncFOp.getType());
+      if (isa<Float32Type>(inTy) && isa<Float32Type>(outTy) &&
----------------
krzysz00 wrote:

No type  limits.

This should apply to any pair of float types

https://github.com/llvm/llvm-project/pull/93443


More information about the Mlir-commits mailing list