Skip to content

Commit 14de5a2

Browse files
committed
[mlir][complex] Initial support for FastMath flag when converting to LLVM
This change contains the initial support of FastMath flag in complex dialect. Similar to what we did in [Arith dialect](https://reviews.llvm.org/rGb56e65d31825fe4a1ae02fdcbad58bb7993d63a7), `fastmath` attributes in the complex dialect are directly mapped to the corresponding LLVM fastmath flags. In this diff, - Definition of FastMathAttr as a custom attribute in the Complex dialect that inherits from the EnumAttr class. - Definition of ComplexFastMathInterface, which is an interface that is implemented by operations that have a complex::fastmath attribute. - Declaration of a default-valued fastmath attribute for unary and arithmetic operations in the Complex dialect. - Conversion code to lower arithmetic fastmath flags to LLVM fastmath flags NOT in this diff (but planned and progressively implemented): - Documentation of flag meanings - Support the fastmath flag conversion to Arith dialect - Folding/rewrite implementations that are enabled by fastmath flags (although it's the original motivation to support the flag) RFC: https://discourse.llvm.org/t/rfc-fastmath-flags-support-in-complex-dialect/71981 Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D156310
1 parent 6acff53 commit 14de5a2

File tree

9 files changed

+183
-22
lines changed

9 files changed

+183
-22
lines changed

flang/test/Lower/Intrinsics/abs.f90

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s --check-prefixes="CHECK,CMPLX,CMPLX-PRECISE"
55
! RUN: %flang_fc1 -emit-fir -mllvm --math-runtime=precise %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-PRECISE"
66
! RUN: %flang_fc1 -emit-fir -mllvm --force-mlir-complex %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST"
7-
! RUN: %flang_fc1 -fapprox-func -emit-fir %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST"
7+
! RUN: %flang_fc1 -fapprox-func -emit-fir %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-APPROX"
88

99
! Test abs intrinsic for various types (int, float, complex)
1010

@@ -100,7 +100,9 @@ subroutine abs_testr16(a, b)
100100
subroutine abs_testzr(a, b)
101101
! CMPLX: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.complex<4>>
102102
! CMPLX-FAST: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<4>) -> complex<f32>
103-
! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] : complex<f32>
103+
! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract> : complex<f32>
104+
! CMPLX-APPROX: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<4>) -> complex<f32>
105+
! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract,afn> : complex<f32>
104106
! CMPLX-PRECISE: %[[VAL_4:.*]] = fir.call @cabsf(%[[VAL_2]]) {{.*}}: (!fir.complex<4>) -> f32
105107
! CMPLX: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f32>
106108
! CMPLX: return
@@ -114,7 +116,9 @@ end subroutine abs_testzr
114116
subroutine abs_testzd(a, b)
115117
! CMPLX: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.complex<8>>
116118
! CMPLX-FAST: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<8>) -> complex<f64>
117-
! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] : complex<f64>
119+
! CMPLX-FAST: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract> : complex<f64>
120+
! CMPLX-APPROX: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.complex<8>) -> complex<f64>
121+
! CMPLX-APPROX: %[[VAL_4:.*]] = complex.abs %[[VAL_3]] fastmath<contract,afn> : complex<f64>
118122
! CMPLX-PRECISE: %[[VAL_4:.*]] = fir.call @cabs(%[[VAL_2]]) {{.*}}: (!fir.complex<8>) -> f64
119123
! CMPLX: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<f64>
120124
! CMPLX: return

flang/test/Lower/Intrinsics/exp.f90

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
! RUN: bbc -emit-fir --math-runtime=precise -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-PRECISE"
33
! RUN: bbc -emit-fir --force-mlir-complex -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST,CMPLX-MLIR"
44
! RUN: %flang_fc1 -emit-fir -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CHECK,CMPLX,CMPLX-PRECISE"
5-
! RUN: %flang_fc1 -fapprox-func -emit-fir -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST,CMPLX-APPROX"
5+
! RUN: %flang_fc1 -fapprox-func -emit-fir -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-APPROX"
66
! RUN: %flang_fc1 -emit-fir -mllvm -outline-intrinsics -mllvm --math-runtime=precise %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-PRECISE"
77
! RUN: %flang_fc1 -emit-fir -mllvm -outline-intrinsics -mllvm --force-mlir-complex %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST,CMPLX-MLIR"
88

@@ -61,8 +61,11 @@ subroutine exp_testcd(a, b)
6161
! CMPLX-MLIR-LABEL: private @fir.exp.contract.z4.z4
6262
! CMPLX-SAME: (%[[ARG32_OUTLINE:.*]]: !fir.complex<4>) -> !fir.complex<4>
6363
! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG32_OUTLINE]] : (!fir.complex<4>) -> complex<f32>
64-
! CMPLX-FAST: %[[E:.*]] = complex.exp %[[C]] : complex<f32>
64+
! CMPLX-FAST: %[[E:.*]] = complex.exp %[[C]] fastmath<contract> : complex<f32>
6565
! CMPLX-FAST: %[[RESULT32_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f32>) -> !fir.complex<4>
66+
! CMPLX-APPROX: %[[C:.*]] = fir.convert %[[ARG32_OUTLINE]] : (!fir.complex<4>) -> complex<f32>
67+
! CMPLX-APPROX: %[[E:.*]] = complex.exp %[[C]] fastmath<contract,afn> : complex<f32>
68+
! CMPLX-APPROX: %[[RESULT32_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f32>) -> !fir.complex<4>
6669
! CMPLX-PRECISE: %[[RESULT32_OUTLINE:.*]] = fir.call @cexpf(%[[ARG32_OUTLINE]]) fastmath<contract> : (!fir.complex<4>) -> !fir.complex<4>
6770
! CMPLX: return %[[RESULT32_OUTLINE]] : !fir.complex<4>
6871

@@ -71,7 +74,10 @@ subroutine exp_testcd(a, b)
7174
! CMPLX-MLIR-LABEL: private @fir.exp.contract.z8.z8
7275
! CMPLX-SAME: (%[[ARG64_OUTLINE:.*]]: !fir.complex<8>) -> !fir.complex<8>
7376
! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG64_OUTLINE]] : (!fir.complex<8>) -> complex<f64>
74-
! CMPLX-FAST: %[[E:.*]] = complex.exp %[[C]] : complex<f64>
77+
! CMPLX-FAST: %[[E:.*]] = complex.exp %[[C]] fastmath<contract> : complex<f64>
7578
! CMPLX-FAST: %[[RESULT64_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f64>) -> !fir.complex<8>
79+
! CMPLX-APPROX: %[[C:.*]] = fir.convert %[[ARG64_OUTLINE]] : (!fir.complex<8>) -> complex<f64>
80+
! CMPLX-APPROX: %[[E:.*]] = complex.exp %[[C]] fastmath<contract,afn> : complex<f64>
81+
! CMPLX-APPROX: %[[RESULT64_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f64>) -> !fir.complex<8>
7682
! CMPLX-PRECISE: %[[RESULT64_OUTLINE:.*]] = fir.call @cexp(%[[ARG64_OUTLINE]]) fastmath<contract> : (!fir.complex<8>) -> !fir.complex<8>
7783
! CMPLX: return %[[RESULT64_OUTLINE]] : !fir.complex<8>

flang/test/Lower/Intrinsics/log.f90

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
! RUN: %flang_fc1 -emit-fir -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CHECK,CMPLX,CMPLX-PRECISE"
55
! RUN: %flang_fc1 -emit-fir -mllvm -outline-intrinsics -mllvm --math-runtime=precise %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-PRECISE"
66
! RUN: %flang_fc1 -emit-fir -mllvm -outline-intrinsics -mllvm --force-mlir-complex %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST,CMPLX-MLIR"
7-
! RUN: %flang_fc1 -fapprox-func -emit-fir -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-FAST,CMPLX-APPROX"
7+
! RUN: %flang_fc1 -fapprox-func -emit-fir -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="CMPLX,CMPLX-APPROX"
88

99
! CHECK-LABEL: log_testr
1010
! CHECK-SAME: (%[[AREF:.*]]: !fir.ref<f32> {{.*}}, %[[BREF:.*]]: !fir.ref<f32> {{.*}})
@@ -81,8 +81,11 @@ subroutine log10_testd(a, b)
8181
! CMPLX-MLIR-LABEL: private @fir.log.contract.z4.z4
8282
! CMPLX-SAME: (%[[ARG32_OUTLINE:.*]]: !fir.complex<4>) -> !fir.complex<4>
8383
! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG32_OUTLINE]] : (!fir.complex<4>) -> complex<f32>
84-
! CMPLX-FAST: %[[E:.*]] = complex.log %[[C]] : complex<f32>
84+
! CMPLX-FAST: %[[E:.*]] = complex.log %[[C]] fastmath<contract> : complex<f32>
8585
! CMPLX-FAST: %[[RESULT32_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f32>) -> !fir.complex<4>
86+
! CMPLX-APPROX: %[[C:.*]] = fir.convert %[[ARG32_OUTLINE]] : (!fir.complex<4>) -> complex<f32>
87+
! CMPLX-APPROX: %[[E:.*]] = complex.log %[[C]] fastmath<contract,afn> : complex<f32>
88+
! CMPLX-APPROX: %[[RESULT32_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f32>) -> !fir.complex<4>
8689
! CMPLX-PRECISE: %[[RESULT32_OUTLINE:.*]] = fir.call @clogf(%[[ARG32_OUTLINE]]) fastmath<contract> : (!fir.complex<4>) -> !fir.complex<4>
8790
! CMPLX: return %[[RESULT32_OUTLINE]] : !fir.complex<4>
8891

@@ -91,8 +94,11 @@ subroutine log10_testd(a, b)
9194
! CMPLX-MLIR-LABEL: private @fir.log.contract.z8.z8
9295
! CMPLX-SAME: (%[[ARG64_OUTLINE:.*]]: !fir.complex<8>) -> !fir.complex<8>
9396
! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG64_OUTLINE]] : (!fir.complex<8>) -> complex<f64>
94-
! CMPLX-FAST: %[[E:.*]] = complex.log %[[C]] : complex<f64>
97+
! CMPLX-FAST: %[[E:.*]] = complex.log %[[C]] fastmath<contract> : complex<f64>
9598
! CMPLX-FAST: %[[RESULT64_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f64>) -> !fir.complex<8>
99+
! CMPLX-APPROX: %[[C:.*]] = fir.convert %[[ARG64_OUTLINE]] : (!fir.complex<8>) -> complex<f64>
100+
! CMPLX-APPROX: %[[E:.*]] = complex.log %[[C]] fastmath<contract,afn> : complex<f64>
101+
! CMPLX-APPROX: %[[RESULT64_OUTLINE:.*]] = fir.convert %[[E]] : (complex<f64>) -> !fir.complex<8>
96102
! CMPLX-PRECISE: %[[RESULT64_OUTLINE:.*]] = fir.call @clog(%[[ARG64_OUTLINE]]) fastmath<contract> : (!fir.complex<8>) -> !fir.complex<8>
97103
! CMPLX: return %[[RESULT64_OUTLINE]] : !fir.complex<8>
98104

flang/test/Lower/complex-operations.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end subroutine mul_test
3333
! CHECK: %[[CVAL:.*]] = fir.load %[[CREF]] : !fir.ref<!fir.complex<2>>
3434
! CHECK: %[[BVAL_CVT:.*]] = fir.convert %[[BVAL]] : (!fir.complex<2>) -> complex<f16>
3535
! CHECK: %[[CVAL_CVT:.*]] = fir.convert %[[CVAL]] : (!fir.complex<2>) -> complex<f16>
36-
! CHECK: %[[AVAL_CVT:.*]] = complex.div %[[BVAL_CVT]], %[[CVAL_CVT]] : complex<f16>
36+
! CHECK: %[[AVAL_CVT:.*]] = complex.div %[[BVAL_CVT]], %[[CVAL_CVT]] fastmath<contract> : complex<f16>
3737
! CHECK: %[[AVAL:.*]] = fir.convert %[[AVAL_CVT]] : (complex<f16>) -> !fir.complex<2>
3838
! CHECK: fir.store %[[AVAL]] to %[[AREF]] : !fir.ref<!fir.complex<2>>
3939
subroutine div_test_half(a,b,c)
@@ -47,7 +47,7 @@ end subroutine div_test_half
4747
! CHECK: %[[CVAL:.*]] = fir.load %[[CREF]] : !fir.ref<!fir.complex<3>>
4848
! CHECK: %[[BVAL_CVT:.*]] = fir.convert %[[BVAL]] : (!fir.complex<3>) -> complex<bf16>
4949
! CHECK: %[[CVAL_CVT:.*]] = fir.convert %[[CVAL]] : (!fir.complex<3>) -> complex<bf16>
50-
! CHECK: %[[AVAL_CVT:.*]] = complex.div %[[BVAL_CVT]], %[[CVAL_CVT]] : complex<bf16>
50+
! CHECK: %[[AVAL_CVT:.*]] = complex.div %[[BVAL_CVT]], %[[CVAL_CVT]] fastmath<contract> : complex<bf16>
5151
! CHECK: %[[AVAL:.*]] = fir.convert %[[AVAL_CVT]] : (complex<bf16>) -> !fir.complex<3>
5252
! CHECK: fir.store %[[AVAL]] to %[[AREF]] : !fir.ref<!fir.complex<3>>
5353
subroutine div_test_bfloat(a,b,c)

mlir/include/mlir/Dialect/Complex/IR/Complex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define MLIR_DIALECT_COMPLEX_IR_COMPLEX_H_
1111

1212
#include "mlir/Bytecode/BytecodeOpInterface.h"
13+
#include "mlir/Dialect/Arith/IR/Arith.h"
1314
#include "mlir/IR/BuiltinTypes.h"
1415
#include "mlir/IR/OpImplementation.h"
1516
#include "mlir/Interfaces/InferTypeOpInterface.h"

mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef COMPLEX_OPS
1010
#define COMPLEX_OPS
1111

12+
include "mlir/Dialect/Arith/IR/ArithBase.td"
13+
include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.td"
1214
include "mlir/Dialect/Complex/IR/ComplexBase.td"
1315
include "mlir/IR/OpAsmInterface.td"
1416
include "mlir/Interfaces/InferTypeOpInterface.td"
@@ -22,19 +24,21 @@ class Complex_Op<string mnemonic, list<Trait> traits = []>
2224
// one result, all of which must be complex numbers of the same type.
2325
class ComplexArithmeticOp<string mnemonic, list<Trait> traits = []> :
2426
Complex_Op<mnemonic, traits # [Pure, SameOperandsAndResultType,
25-
Elementwise]> {
26-
let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs);
27+
Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>]> {
28+
let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs, DefaultValuedAttr<
29+
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath);
2730
let results = (outs Complex<AnyFloat>:$result);
28-
let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($result)";
31+
let assemblyFormat = "$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)";
2932
}
3033

3134
// Base class for standard unary operations on complex numbers with a
3235
// floating-point element type. These operations take one operand and return
3336
// one result; the operand must be a complex number.
3437
class ComplexUnaryOp<string mnemonic, list<Trait> traits = []> :
35-
Complex_Op<mnemonic, traits # [Pure, Elementwise]> {
36-
let arguments = (ins Complex<AnyFloat>:$complex);
37-
let assemblyFormat = "$complex attr-dict `:` type($complex)";
38+
Complex_Op<mnemonic, traits # [Pure, Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>]> {
39+
let arguments = (ins Complex<AnyFloat>:$complex, DefaultValuedAttr<
40+
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath);
41+
let assemblyFormat = "$complex (`fastmath` `` $fastmath^)? attr-dict `:` type($complex)";
3842
}
3943

4044
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "mlir/Conversion/ComplexToLLVM/ComplexToLLVM.h"
1010

1111
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
12+
#include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
1213
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
1314
#include "mlir/Conversion/LLVMCommon/Pattern.h"
1415
#include "mlir/Dialect/Arith/IR/Arith.h"
@@ -23,6 +24,7 @@ namespace mlir {
2324

2425
using namespace mlir;
2526
using namespace mlir::LLVM;
27+
using namespace mlir::arith;
2628

2729
//===----------------------------------------------------------------------===//
2830
// ComplexStructBuilder implementation.
@@ -73,7 +75,10 @@ struct AbsOpConversion : public ConvertOpToLLVMPattern<complex::AbsOp> {
7375
Value real = complexStruct.real(rewriter, op.getLoc());
7476
Value imag = complexStruct.imaginary(rewriter, op.getLoc());
7577

76-
auto fmf = LLVM::FastmathFlagsAttr::get(op.getContext(), {});
78+
arith::FastMathFlagsAttr complexFMFAttr = op.getFastMathFlagsAttr();
79+
LLVM::FastmathFlagsAttr fmf = LLVM::FastmathFlagsAttr::get(
80+
op.getContext(),
81+
convertArithFastMathFlagsToLLVM(complexFMFAttr.getValue()));
7782
Value sqNorm = rewriter.create<LLVM::FAddOp>(
7883
loc, rewriter.create<LLVM::FMulOp>(loc, real, real, fmf),
7984
rewriter.create<LLVM::FMulOp>(loc, imag, imag, fmf), fmf);
@@ -181,7 +186,10 @@ struct AddOpConversion : public ConvertOpToLLVMPattern<complex::AddOp> {
181186
auto result = ComplexStructBuilder::undef(rewriter, loc, structType);
182187

183188
// Emit IR to add complex numbers.
184-
auto fmf = LLVM::FastmathFlagsAttr::get(op.getContext(), {});
189+
arith::FastMathFlagsAttr complexFMFAttr = op.getFastMathFlagsAttr();
190+
LLVM::FastmathFlagsAttr fmf = LLVM::FastmathFlagsAttr::get(
191+
op.getContext(),
192+
convertArithFastMathFlagsToLLVM(complexFMFAttr.getValue()));
185193
Value real =
186194
rewriter.create<LLVM::FAddOp>(loc, arg.lhs.real(), arg.rhs.real(), fmf);
187195
Value imag =
@@ -209,7 +217,10 @@ struct DivOpConversion : public ConvertOpToLLVMPattern<complex::DivOp> {
209217
auto result = ComplexStructBuilder::undef(rewriter, loc, structType);
210218

211219
// Emit IR to add complex numbers.
212-
auto fmf = LLVM::FastmathFlagsAttr::get(op.getContext(), {});
220+
arith::FastMathFlagsAttr complexFMFAttr = op.getFastMathFlagsAttr();
221+
LLVM::FastmathFlagsAttr fmf = LLVM::FastmathFlagsAttr::get(
222+
op.getContext(),
223+
convertArithFastMathFlagsToLLVM(complexFMFAttr.getValue()));
213224
Value rhsRe = arg.rhs.real();
214225
Value rhsIm = arg.rhs.imag();
215226
Value lhsRe = arg.lhs.real();
@@ -254,7 +265,10 @@ struct MulOpConversion : public ConvertOpToLLVMPattern<complex::MulOp> {
254265
auto result = ComplexStructBuilder::undef(rewriter, loc, structType);
255266

256267
// Emit IR to add complex numbers.
257-
auto fmf = LLVM::FastmathFlagsAttr::get(op.getContext(), {});
268+
arith::FastMathFlagsAttr complexFMFAttr = op.getFastMathFlagsAttr();
269+
LLVM::FastmathFlagsAttr fmf = LLVM::FastmathFlagsAttr::get(
270+
op.getContext(),
271+
convertArithFastMathFlagsToLLVM(complexFMFAttr.getValue()));
258272
Value rhsRe = arg.rhs.real();
259273
Value rhsIm = arg.rhs.imag();
260274
Value lhsRe = arg.lhs.real();
@@ -291,7 +305,10 @@ struct SubOpConversion : public ConvertOpToLLVMPattern<complex::SubOp> {
291305
auto result = ComplexStructBuilder::undef(rewriter, loc, structType);
292306

293307
// Emit IR to substract complex numbers.
294-
auto fmf = LLVM::FastmathFlagsAttr::get(op.getContext(), {});
308+
arith::FastMathFlagsAttr complexFMFAttr = op.getFastMathFlagsAttr();
309+
LLVM::FastmathFlagsAttr fmf = LLVM::FastmathFlagsAttr::get(
310+
op.getContext(),
311+
convertArithFastMathFlagsToLLVM(complexFMFAttr.getValue()));
295312
Value real =
296313
rewriter.create<LLVM::FSubOp>(loc, arg.lhs.real(), arg.rhs.real(), fmf);
297314
Value imag =

mlir/lib/Dialect/Complex/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_mlir_dialect_library(MLIRComplexDialect
1010
MLIRComplexAttributesIncGen
1111

1212
LINK_LIBS PUBLIC
13+
MLIRArithAttrToLLVMConversion
1314
MLIRArithDialect
1415
MLIRDialect
1516
MLIRInferTypeOpInterface

0 commit comments

Comments
 (0)