[Mlir-commits] [mlir] [mlir][arith] Preserve fast-math flags when lowering floating casts (PR #211173)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 31 18:47:38 PDT 2026


https://github.com/1sgtpepper updated https://github.com/llvm/llvm-project/pull/211173

>From de3ca016aba065e494a6a78ca108fde0b08dfa16 Mon Sep 17 00:00:00 2001
From: 1sgtpepper <cynejarviszarceno at gmail.com>
Date: Wed, 22 Jul 2026 13:37:20 +0800
Subject: [PATCH] [mlir][arith] Preserve fast-math flags when lowering floating
 casts

---
 mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp     | 9 +++++----
 mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir | 4 ++++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
index d164f0e7f6d17..982b1e5e9a8d1 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -114,9 +114,10 @@ using DivSIOpLowering =
     VectorConvertToLLVMPattern<arith::DivSIOp, LLVM::SDivOp>;
 using DivUIOpLowering =
     VectorConvertToLLVMPattern<arith::DivUIOp, LLVM::UDivOp>;
-using ExtFOpLowering = VectorConvertToLLVMPattern<arith::ExtFOp, LLVM::FPExtOp,
-                                                  AttrConvertPassThrough,
-                                                  /*FailOnUnsupportedFP=*/true>;
+using ExtFOpLowering =
+    VectorConvertToLLVMPattern<arith::ExtFOp, LLVM::FPExtOp,
+                               arith::AttrConvertFastMathToLLVM,
+                               /*FailOnUnsupportedFP=*/true>;
 using ExtSIOpLowering =
     VectorConvertToLLVMPattern<arith::ExtSIOp, LLVM::SExtOp>;
 using ExtUIOpLowering =
@@ -203,7 +204,7 @@ using SubIOpLowering =
 using TruncFOpLowering =
     ConstrainedVectorConvertToLLVMPattern<arith::TruncFOp, LLVM::FPTruncOp,
                                           /*HasRoundingMode=*/false,
-                                          AttrConvertPassThrough,
+                                          arith::AttrConvertFastMathToLLVM,
                                           /*FailOnUnsupportedFP=*/true>;
 using ConstrainedTruncFOpLowering = ConstrainedVectorConvertToLLVMPattern<
     arith::TruncFOp, LLVM::ConstrainedFPTruncIntr, /*HasRoundingMode=*/true,
diff --git a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
index c21e967976e4c..fac1ff2c7525a 100644
--- a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
+++ b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
@@ -878,6 +878,10 @@ func.func @ops_supporting_fastmath(%arg0: f32, %arg1: f32, %arg2: i32) {
   %6 = arith.remf %arg0, %arg1 fastmath<fast> : f32
 // CHECK: llvm.fsub %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
   %7 = arith.subf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.fpext %arg0 fastmath<fast> : f32 to f64
+  %8 = arith.extf %arg0 fastmath<fast> : f32 to f64
+// CHECK: llvm.fptrunc %arg0 fastmath<fast> : f32 to f16
+  %9 = arith.truncf %arg0 fastmath<fast> : f32 to f16
   return
 }
 



More information about the Mlir-commits mailing list