[flang-commits] [flang] [Flang] Generate math.erfc op for non-precise erfc interinsic calls (PR #128897)
via flang-commits
flang-commits at lists.llvm.org
Wed Feb 26 08:00:37 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Jan Leyonberg (jsjodin)
<details>
<summary>Changes</summary>
This patch changes the codegen for non-precise erfc calls to generate math.erfc ops. This wasn't done before because the math dialect did not have a erfc operation at the time.
---
Full diff: https://github.com/llvm/llvm-project/pull/128897.diff
2 Files Affected:
- (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+4-2)
- (modified) flang/test/Lower/Intrinsics/erfc.f90 (+12-8)
``````````diff
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 537c817e32ad8..69655b9e9139e 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1277,8 +1277,10 @@ static constexpr MathOperation mathOperations[] = {
{"erf", "erf", genFuncType<Ty::Real<8>, Ty::Real<8>>,
genMathOp<mlir::math::ErfOp>},
{"erf", RTNAME_STRING(ErfF128), FuncTypeReal16Real16, genLibF128Call},
- {"erfc", "erfcf", genFuncType<Ty::Real<4>, Ty::Real<4>>, genLibCall},
- {"erfc", "erfc", genFuncType<Ty::Real<8>, Ty::Real<8>>, genLibCall},
+ {"erfc", "erfcf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
+ genMathOp<mlir::math::ErfcOp>},
+ {"erfc", "erfc", genFuncType<Ty::Real<8>, Ty::Real<8>>,
+ genMathOp<mlir::math::ErfcOp>},
{"erfc", RTNAME_STRING(ErfcF128), FuncTypeReal16Real16, genLibF128Call},
{"exp", "expf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
genMathOp<mlir::math::ExpOp>},
diff --git a/flang/test/Lower/Intrinsics/erfc.f90 b/flang/test/Lower/Intrinsics/erfc.f90
index 0f1e05400f5f2..164e958bb2912 100644
--- a/flang/test/Lower/Intrinsics/erfc.f90
+++ b/flang/test/Lower/Intrinsics/erfc.f90
@@ -1,9 +1,9 @@
-! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %s
-! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL %s
-! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %s
-! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL %s
-! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %s
-! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL %s
+! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %s
+! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL,FAST %s
+! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %s
+! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL,RELAXED %s
+! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %s
+! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL,PRECISE %s
function test_real4(x)
real :: x, test_real4
@@ -11,7 +11,9 @@ function test_real4(x)
end function
! ALL-LABEL: @_QPtest_real4
-! ALL: {{%[A-Za-z0-9._]+}} = fir.call @erfcf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
+! FAST: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f32
+! RELAXED: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f32
+! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erfcf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
function test_real8(x)
real(8) :: x, test_real8
@@ -19,4 +21,6 @@ function test_real8(x)
end function
! ALL-LABEL: @_QPtest_real8
-! ALL: {{%[A-Za-z0-9._]+}} = fir.call @erfc({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
+! FAST: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f64
+! RELAXED: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f64
+! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erfc({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
``````````
</details>
https://github.com/llvm/llvm-project/pull/128897
More information about the flang-commits
mailing list