Skip to content

Commit 8c9d814

Browse files
authored
1 parent 8c9f45e commit 8c9d814

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,13 +1289,14 @@ struct AngleOpConversion : public OpConversionPattern<complex::AngleOp> {
12891289
ConversionPatternRewriter &rewriter) const override {
12901290
auto loc = op.getLoc();
12911291
auto type = op.getType();
1292+
arith::FastMathFlagsAttr fmf = op.getFastMathFlagsAttr();
12921293

12931294
Value real =
12941295
rewriter.create<complex::ReOp>(loc, type, adaptor.getComplex());
12951296
Value imag =
12961297
rewriter.create<complex::ImOp>(loc, type, adaptor.getComplex());
12971298

1298-
rewriter.replaceOpWithNewOp<math::Atan2Op>(op, imag, real);
1299+
rewriter.replaceOpWithNewOp<math::Atan2Op>(op, imag, real, fmf);
12991300

13001301
return success();
13011302
}

mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,3 +2187,16 @@ func.func @complex_tanh_nnan_ninf(%arg: complex<f32>) -> complex<f32> {
21872187

21882188
// CHECK-COUNT-1: arith.select
21892189
// CHECK-NOT: arith.select
2190+
2191+
// -----
2192+
2193+
// CHECK-LABEL: func.func @complex_angle_with_fmf
2194+
// CHECK-SAME: %[[ARG:.*]]: complex<f32>
2195+
func.func @complex_angle_with_fmf(%arg: complex<f32>) -> f32 {
2196+
%angle = complex.angle %arg fastmath<nnan,contract> : complex<f32>
2197+
return %angle : f32
2198+
}
2199+
// CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex<f32>
2200+
// CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex<f32>
2201+
// CHECK: %[[RESULT:.*]] = math.atan2 %[[IMAG]], %[[REAL]] fastmath<nnan,contract> : f32
2202+
// CHECK: return %[[RESULT]] : f32

0 commit comments

Comments
 (0)