diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -1624,6 +1624,7 @@ // its calls will be. auto localBuilder = std::make_unique(function, builder.getKindMap()); + localBuilder->setFastMathFlags(builder.getFastMathFlags()); localBuilder->setInsertionPointToStart(&function.front()); // Location of code inside wrapper of the wrapper is independent from // the location of the intrinsic call. diff --git a/flang/test/Lower/Intrinsics/exp.f90 b/flang/test/Lower/Intrinsics/exp.f90 --- a/flang/test/Lower/Intrinsics/exp.f90 +++ b/flang/test/Lower/Intrinsics/exp.f90 @@ -47,12 +47,12 @@ ! CHECK-LABEL: private @fir.exp.f32.f32 ! CHECK-SAME: (%[[ARG32_OUTLINE:.*]]: f32) -> f32 -! CHECK: %[[RESULT32_OUTLINE:.*]] = math.exp %[[ARG32_OUTLINE]] : f32 +! CHECK: %[[RESULT32_OUTLINE:.*]] = math.exp %[[ARG32_OUTLINE]] fastmath : f32 ! CHECK: return %[[RESULT32_OUTLINE]] : f32 ! CHECK-LABEL: private @fir.exp.f64.f64 ! CHECK-SAME: (%[[ARG64_OUTLINE:.*]]: f64) -> f64 -! CHECK: %[[RESULT64_OUTLINE:.*]] = math.exp %[[ARG64_OUTLINE]] : f64 +! CHECK: %[[RESULT64_OUTLINE:.*]] = math.exp %[[ARG64_OUTLINE]] fastmath : f64 ! CHECK: return %[[RESULT64_OUTLINE]] : f64 ! CMPLX-LABEL: private @fir.exp.z4.z4 @@ -60,7 +60,7 @@ ! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG32_OUTLINE]] : (!fir.complex<4>) -> complex ! CMPLX-FAST: %[[E:.*]] = complex.exp %[[C]] : complex ! CMPLX-FAST: %[[RESULT32_OUTLINE:.*]] = fir.convert %[[E]] : (complex) -> !fir.complex<4> -! CMPLX-PRECISE: %[[RESULT32_OUTLINE:.*]] = fir.call @cexpf(%[[ARG32_OUTLINE]]) : (!fir.complex<4>) -> !fir.complex<4> +! CMPLX-PRECISE: %[[RESULT32_OUTLINE:.*]] = fir.call @cexpf(%[[ARG32_OUTLINE]]) fastmath : (!fir.complex<4>) -> !fir.complex<4> ! CMPLX: return %[[RESULT32_OUTLINE]] : !fir.complex<4> ! CMPLX-LABEL: private @fir.exp.z8.z8 @@ -68,5 +68,5 @@ ! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG64_OUTLINE]] : (!fir.complex<8>) -> complex ! CMPLX-FAST: %[[E:.*]] = complex.exp %[[C]] : complex ! CMPLX-FAST: %[[RESULT64_OUTLINE:.*]] = fir.convert %[[E]] : (complex) -> !fir.complex<8> -! CMPLX-PRECISE: %[[RESULT64_OUTLINE:.*]] = fir.call @cexp(%[[ARG64_OUTLINE]]) : (!fir.complex<8>) -> !fir.complex<8> +! CMPLX-PRECISE: %[[RESULT64_OUTLINE:.*]] = fir.call @cexp(%[[ARG64_OUTLINE]]) fastmath : (!fir.complex<8>) -> !fir.complex<8> ! CMPLX: return %[[RESULT64_OUTLINE]] : !fir.complex<8> diff --git a/flang/test/Lower/Intrinsics/log.f90 b/flang/test/Lower/Intrinsics/log.f90 --- a/flang/test/Lower/Intrinsics/log.f90 +++ b/flang/test/Lower/Intrinsics/log.f90 @@ -67,12 +67,12 @@ ! CHECK-LABEL: private @fir.log.f32.f32 ! CHECK-SAME: (%[[ARG32_OUTLINE:.*]]: f32) -> f32 -! CHECK: %[[RESULT32_OUTLINE:.*]] = math.log %[[ARG32_OUTLINE]] : f32 +! CHECK: %[[RESULT32_OUTLINE:.*]] = math.log %[[ARG32_OUTLINE]] fastmath : f32 ! CHECK: return %[[RESULT32_OUTLINE]] : f32 ! CHECK-LABEL: private @fir.log.f64.f64 ! CHECK-SAME: (%[[ARG64_OUTLINE:.*]]: f64) -> f64 -! CHECK: %[[RESULT64_OUTLINE:.*]] = math.log %[[ARG64_OUTLINE]] : f64 +! CHECK: %[[RESULT64_OUTLINE:.*]] = math.log %[[ARG64_OUTLINE]] fastmath : f64 ! CHECK: return %[[RESULT64_OUTLINE]] : f64 ! CMPLX-LABEL: private @fir.log.z4.z4 @@ -80,7 +80,7 @@ ! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG32_OUTLINE]] : (!fir.complex<4>) -> complex ! CMPLX-FAST: %[[E:.*]] = complex.log %[[C]] : complex ! CMPLX-FAST: %[[RESULT32_OUTLINE:.*]] = fir.convert %[[E]] : (complex) -> !fir.complex<4> -! CMPLX-PRECISE: %[[RESULT32_OUTLINE:.*]] = fir.call @clogf(%[[ARG32_OUTLINE]]) : (!fir.complex<4>) -> !fir.complex<4> +! CMPLX-PRECISE: %[[RESULT32_OUTLINE:.*]] = fir.call @clogf(%[[ARG32_OUTLINE]]) fastmath : (!fir.complex<4>) -> !fir.complex<4> ! CMPLX: return %[[RESULT32_OUTLINE]] : !fir.complex<4> ! CMPLX-LABEL: private @fir.log.z8.z8 @@ -88,15 +88,15 @@ ! CMPLX-FAST: %[[C:.*]] = fir.convert %[[ARG64_OUTLINE]] : (!fir.complex<8>) -> complex ! CMPLX-FAST: %[[E:.*]] = complex.log %[[C]] : complex ! CMPLX-FAST: %[[RESULT64_OUTLINE:.*]] = fir.convert %[[E]] : (complex) -> !fir.complex<8> -! CMPLX-PRECISE: %[[RESULT64_OUTLINE:.*]] = fir.call @clog(%[[ARG64_OUTLINE]]) : (!fir.complex<8>) -> !fir.complex<8> +! CMPLX-PRECISE: %[[RESULT64_OUTLINE:.*]] = fir.call @clog(%[[ARG64_OUTLINE]]) fastmath : (!fir.complex<8>) -> !fir.complex<8> ! CMPLX: return %[[RESULT64_OUTLINE]] : !fir.complex<8> ! CHECK-LABEL: private @fir.log10.f32.f32 ! CHECK-SAME: (%[[ARG32_OUTLINE:.*]]: f32) -> f32 -! CHECK: %[[RESULT32_OUTLINE:.*]] = math.log10 %[[ARG32_OUTLINE]] : f32 +! CHECK: %[[RESULT32_OUTLINE:.*]] = math.log10 %[[ARG32_OUTLINE]] fastmath : f32 ! CHECK: return %[[RESULT32_OUTLINE]] : f32 ! CHECK-LABEL: private @fir.log10.f64.f64 ! CHECK-SAME: (%[[ARG64_OUTLINE:.*]]: f64) -> f64 -! CHECK: %[[RESULT64_OUTLINE:.*]] = math.log10 %[[ARG64_OUTLINE]] : f64 +! CHECK: %[[RESULT64_OUTLINE:.*]] = math.log10 %[[ARG64_OUTLINE]] fastmath : f64 ! CHECK: return %[[RESULT64_OUTLINE]] : f64 diff --git a/flang/test/Lower/Intrinsics/math-runtime-options.f90 b/flang/test/Lower/Intrinsics/math-runtime-options.f90 --- a/flang/test/Lower/Intrinsics/math-runtime-options.f90 +++ b/flang/test/Lower/Intrinsics/math-runtime-options.f90 @@ -20,10 +20,10 @@ end subroutine ! FIR: @fir.cos.f32.f32(%arg0: f32) -> f32 attributes -! FAST: math.cos %arg0 : f32 -! RELAXED: math.cos %arg0 : f32 -! PRECISE: fir.call @cosf(%arg0) : (f32) -> f32 +! FAST: math.cos %arg0 fastmath : f32 +! RELAXED: math.cos %arg0 fastmath : f32 +! PRECISE: fir.call @cosf(%arg0) fastmath : (f32) -> f32 ! FIR: @fir.cos.f64.f64(%arg0: f64) -> f64 -! FAST: math.cos %arg0 : f64 -! RELAXED: math.cos %arg0 : f64 -! PRECISE: fir.call @cos(%arg0) : (f64) -> f64 +! FAST: math.cos %arg0 fastmath : f64 +! RELAXED: math.cos %arg0 fastmath : f64 +! PRECISE: fir.call @cos(%arg0) fastmath : (f64) -> f64 diff --git a/flang/test/Lower/dummy-procedure.f90 b/flang/test/Lower/dummy-procedure.f90 --- a/flang/test/Lower/dummy-procedure.f90 +++ b/flang/test/Lower/dummy-procedure.f90 @@ -154,14 +154,14 @@ ! CHECK-LABEL: func private @fir.acos.f32.ref_f32(%arg0: !fir.ref) -> f32 !CHECK: %[[load:.*]] = fir.load %arg0 - !CHECK: %[[res:.*]] = fir.call @acosf(%[[load]]) : (f32) -> f32 + !CHECK: %[[res:.*]] = fir.call @acosf(%[[load]]) fastmath : (f32) -> f32 !CHECK: return %[[res]] : f32 ! CHECK-LABEL: func private @fir.atan2.f32.ref_f32.ref_f32( ! CHECK-SAME: %[[x:.*]]: !fir.ref, %[[y:.*]]: !fir.ref) -> f32 ! CHECK-DAG: %[[xload:.*]] = fir.load %[[x]] : !fir.ref ! CHECK-DAG: %[[yload:.*]] = fir.load %[[y]] : !fir.ref - ! CHECK: %[[atan2:.*]] = math.atan2 %[[xload]], %[[yload]] : f32 + ! CHECK: %[[atan2:.*]] = math.atan2 %[[xload]], %[[yload]] fastmath : f32 ! CHECK: return %[[atan2]] : f32 !CHECK-LABEL: func private @fir.aimag.f32.ref_z4(%arg0: !fir.ref>)