[Mlir-commits] [mlir] 478b91b - [mlir][ComplexToStandard] Fix Conj and Neg ops fmf propagation (#222622)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 11 01:02:58 PDT 2026
Author: Mattéo Rizza Murgier
Date: 2026-09-11T10:02:53+02:00
New Revision: 478b91b6f8a2b08dce9673555e3f6da8e6e69051
URL: https://github.com/llvm/llvm-project/commit/478b91b6f8a2b08dce9673555e3f6da8e6e69051
DIFF: https://github.com/llvm/llvm-project/commit/478b91b6f8a2b08dce9673555e3f6da8e6e69051.diff
LOG: [mlir][ComplexToStandard] Fix Conj and Neg ops fmf propagation (#222622)
Added:
Modified:
mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index 9804d9d835a97..37876c441b1ae 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -592,13 +592,14 @@ struct NegOpConversion : public OpConversionPattern<complex::NegOp> {
auto loc = op.getLoc();
auto type = cast<ComplexType>(adaptor.getComplex().getType());
auto elementType = cast<FloatType>(type.getElementType());
+ arith::FastMathFlags fmf = op.getFastMathFlagsAttr().getValue();
Value real =
complex::ReOp::create(rewriter, loc, elementType, adaptor.getComplex());
Value imag =
complex::ImOp::create(rewriter, loc, elementType, adaptor.getComplex());
- Value negReal = arith::NegFOp::create(rewriter, loc, real);
- Value negImag = arith::NegFOp::create(rewriter, loc, imag);
+ Value negReal = arith::NegFOp::create(rewriter, loc, real, fmf);
+ Value negImag = arith::NegFOp::create(rewriter, loc, imag, fmf);
rewriter.replaceOpWithNewOp<complex::CreateOp>(op, type, negReal, negImag);
return success();
}
@@ -851,11 +852,13 @@ struct ConjOpConversion : public OpConversionPattern<complex::ConjOp> {
auto loc = op.getLoc();
auto type = cast<ComplexType>(adaptor.getComplex().getType());
auto elementType = cast<FloatType>(type.getElementType());
+ arith::FastMathFlags fmf = op.getFastMathFlagsAttr().getValue();
Value real =
complex::ReOp::create(rewriter, loc, elementType, adaptor.getComplex());
Value imag =
complex::ImOp::create(rewriter, loc, elementType, adaptor.getComplex());
- Value negImag = arith::NegFOp::create(rewriter, loc, elementType, imag);
+ Value negImag =
+ arith::NegFOp::create(rewriter, loc, elementType, imag, fmf);
rewriter.replaceOpWithNewOp<complex::CreateOp>(op, type, real, negImag);
diff --git a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
index 895343fa1baed..10cfe2b061f56 100644
--- a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
+++ b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
@@ -1543,6 +1543,35 @@ func.func @complex_tanh_nnan_ninf(%arg: complex<f32>) -> complex<f32> {
// -----
+// CHECK-LABEL: func @complex_neg_with_fmf
+// CHECK-SAME: %[[ARG:.*]]: complex<f32>
+func.func @complex_neg_with_fmf(%arg: complex<f32>) -> complex<f32> {
+ %neg = complex.neg %arg fastmath<nnan,contract> : complex<f32>
+ return %neg : complex<f32>
+}
+// CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex<f32>
+// CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex<f32>
+// CHECK-DAG: %[[NEG_REAL:.*]] = arith.negf %[[REAL]] fastmath<nnan,contract> : f32
+// CHECK-DAG: %[[NEG_IMAG:.*]] = arith.negf %[[IMAG]] fastmath<nnan,contract> : f32
+// CHECK: %[[RESULT:.*]] = complex.create %[[NEG_REAL]], %[[NEG_IMAG]] : complex<f32>
+// CHECK: return %[[RESULT]] : complex<f32>
+
+// -----
+
+// CHECK-LABEL: func @complex_conj_with_fmf
+// CHECK-SAME: %[[ARG:.*]]: complex<f32>
+func.func @complex_conj_with_fmf(%arg: complex<f32>) -> complex<f32> {
+ %conj = complex.conj %arg fastmath<nnan,contract> : complex<f32>
+ return %conj : complex<f32>
+}
+// CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex<f32>
+// CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex<f32>
+// CHECK: %[[NEG_IMAG:.*]] = arith.negf %[[IMAG]] fastmath<nnan,contract> : f32
+// CHECK: %[[RESULT:.*]] = complex.create %[[REAL]], %[[NEG_IMAG]] : complex<f32>
+// CHECK: return %[[RESULT]] : complex<f32>
+
+// -----
+
// CHECK-LABEL: func.func @complex_angle_with_fmf
// CHECK-SAME: %[[ARG:.*]]: complex<f32>
func.func @complex_angle_with_fmf(%arg: complex<f32>) -> f32 {
More information about the Mlir-commits
mailing list