Skip to content

Commit c1a8c37

Browse files
jsjodinjoaosaffran
authored andcommitted
[Flang] Generate math.erfc op for non-precise erfc interinsic calls (llvm#128897)
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.
1 parent 662ba0d commit c1a8c37

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,10 @@ static constexpr MathOperation mathOperations[] = {
12771277
{"erf", "erf", genFuncType<Ty::Real<8>, Ty::Real<8>>,
12781278
genMathOp<mlir::math::ErfOp>},
12791279
{"erf", RTNAME_STRING(ErfF128), FuncTypeReal16Real16, genLibF128Call},
1280-
{"erfc", "erfcf", genFuncType<Ty::Real<4>, Ty::Real<4>>, genLibCall},
1281-
{"erfc", "erfc", genFuncType<Ty::Real<8>, Ty::Real<8>>, genLibCall},
1280+
{"erfc", "erfcf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
1281+
genMathOp<mlir::math::ErfcOp>},
1282+
{"erfc", "erfc", genFuncType<Ty::Real<8>, Ty::Real<8>>,
1283+
genMathOp<mlir::math::ErfcOp>},
12821284
{"erfc", RTNAME_STRING(ErfcF128), FuncTypeReal16Real16, genLibF128Call},
12831285
{"exp", "expf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
12841286
genMathOp<mlir::math::ExpOp>},

flang/test/Lower/Intrinsics/erfc.f90

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %s
2-
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL %s
3-
! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %s
4-
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL %s
5-
! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %s
6-
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL %s
1+
! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %s
2+
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL,FAST %s
3+
! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %s
4+
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL,RELAXED %s
5+
! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %s
6+
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL,PRECISE %s
77

88
function test_real4(x)
99
real :: x, test_real4
1010
test_real4 = erfc(x)
1111
end function
1212

1313
! ALL-LABEL: @_QPtest_real4
14-
! ALL: {{%[A-Za-z0-9._]+}} = fir.call @erfcf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
14+
! FAST: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f32
15+
! RELAXED: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f32
16+
! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erfcf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
1517

1618
function test_real8(x)
1719
real(8) :: x, test_real8
1820
test_real8 = erfc(x)
1921
end function
2022

2123
! ALL-LABEL: @_QPtest_real8
22-
! ALL: {{%[A-Za-z0-9._]+}} = fir.call @erfc({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
24+
! FAST: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f64
25+
! RELAXED: {{%[A-Za-z0-9._]+}} = math.erfc {{%[A-Za-z0-9._]+}} {{.*}}: f64
26+
! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erfc({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64

0 commit comments

Comments
 (0)