@@ -945,6 +945,7 @@ struct TanhOpConversion : public OpConversionPattern<complex::TanhOp> {
945
945
auto loc = op.getLoc ();
946
946
auto type = cast<ComplexType>(adaptor.getComplex ().getType ());
947
947
auto elementType = cast<FloatType>(type.getElementType ());
948
+ arith::FastMathFlagsAttr fmf = op.getFastMathFlagsAttr ();
948
949
949
950
// The hyperbolic tangent for complex number can be calculated as follows.
950
951
// tanh(x + i * y) = (tanh(x) + i * tan(y)) / (1 + tanh(x) * tan(y))
@@ -953,17 +954,18 @@ struct TanhOpConversion : public OpConversionPattern<complex::TanhOp> {
953
954
rewriter.create <complex::ReOp>(loc, elementType, adaptor.getComplex ());
954
955
Value imag =
955
956
rewriter.create <complex::ImOp>(loc, elementType, adaptor.getComplex ());
956
- Value tanhA = rewriter.create <math::TanhOp>(loc, real);
957
- Value cosB = rewriter.create <math::CosOp>(loc, imag);
958
- Value sinB = rewriter.create <math::SinOp>(loc, imag);
959
- Value tanB = rewriter.create <arith::DivFOp>(loc, sinB, cosB);
957
+ Value tanhA = rewriter.create <math::TanhOp>(loc, real, fmf );
958
+ Value cosB = rewriter.create <math::CosOp>(loc, imag, fmf );
959
+ Value sinB = rewriter.create <math::SinOp>(loc, imag, fmf );
960
+ Value tanB = rewriter.create <arith::DivFOp>(loc, sinB, cosB, fmf );
960
961
Value numerator =
961
962
rewriter.create <complex::CreateOp>(loc, type, tanhA, tanB);
962
963
Value one = rewriter.create <arith::ConstantOp>(
963
964
loc, elementType, rewriter.getFloatAttr (elementType, 1 ));
964
- Value mul = rewriter.create <arith::MulFOp>(loc, tanhA, tanB);
965
+ Value mul = rewriter.create <arith::MulFOp>(loc, tanhA, tanB, fmf );
965
966
Value denominator = rewriter.create <complex::CreateOp>(loc, type, one, mul);
966
- rewriter.replaceOpWithNewOp <complex::DivOp>(op, numerator, denominator);
967
+ rewriter.replaceOpWithNewOp <complex::DivOp>(op, numerator, denominator,
968
+ fmf);
967
969
return success ();
968
970
}
969
971
};
0 commit comments