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 @@ -1348,6 +1348,16 @@ }; static constexpr MathOperation ppcMathOperations[] = { + // fcfi is just another name for fcfid, there is no llvm.ppc.fcfi. + {"__ppc_fcfi", "llvm.ppc.fcfid", genF64F64FuncType, genLibCall}, + {"__ppc_fcfid", "llvm.ppc.fcfid", genF64F64FuncType, genLibCall}, + {"__ppc_fcfud", "llvm.ppc.fcfud", genF64F64FuncType, genLibCall}, + {"__ppc_fctid", "llvm.ppc.fctid", genF64F64FuncType, genLibCall}, + {"__ppc_fctidz", "llvm.ppc.fctidz", genF64F64FuncType, genLibCall}, + {"__ppc_fctiw", "llvm.ppc.fctiw", genF64F64FuncType, genLibCall}, + {"__ppc_fctiwz", "llvm.ppc.fctiwz", genF64F64FuncType, genLibCall}, + {"__ppc_fctudz", "llvm.ppc.fctudz", genF64F64FuncType, genLibCall}, + {"__ppc_fctuwz", "llvm.ppc.fctuwz", genF64F64FuncType, genLibCall}, {"__ppc_fmadd", "llvm.fma.f32", genF32F32F32F32FuncType, genMathOp}, {"__ppc_fmadd", "llvm.fma.f64", genF64F64F64F64FuncType, diff --git a/flang/module/__fortran_ppc_intrinsics.f90 b/flang/module/__fortran_ppc_intrinsics.f90 --- a/flang/module/__fortran_ppc_intrinsics.f90 +++ b/flang/module/__fortran_ppc_intrinsics.f90 @@ -52,4 +52,72 @@ end interface fnmsub public :: fnmsub +! fctid, fctidz, fctiw, fctiwz, fctudz, fctuwz + abstract interface + elemental real(8) function func_r8r8x(x) + real(8), intent(in) :: x + end function func_r8r8x + end interface + + procedure(func_r8r8x) :: __ppc_fctid + interface fctid + procedure :: __ppc_fctid + end interface fctid + public :: fctid + + procedure(func_r8r8x) :: __ppc_fctidz + interface fctidz + procedure :: __ppc_fctidz + end interface fctidz + public :: fctidz + + procedure(func_r8r8x) :: __ppc_fctiw + interface fctiw + procedure :: __ppc_fctiw + end interface fctiw + public :: fctiw + + procedure(func_r8r8x) :: __ppc_fctiwz + interface fctiwz + procedure :: __ppc_fctiwz + end interface fctiwz + public :: fctiwz + + procedure(func_r8r8x) :: __ppc_fctudz + interface fctudz + procedure :: __ppc_fctudz + end interface fctudz + public :: fctudz + + procedure(func_r8r8x) :: __ppc_fctuwz + interface fctuwz + procedure :: __ppc_fctuwz + end interface fctuwz + public :: fctuwz + +! fcfi, fcfid, fcfud + abstract interface + elemental real(8) function func_r8r8i(i) + real(8), intent(in) :: i + end function func_r8r8i + end interface + + procedure(func_r8r8i) :: __ppc_fcfi + interface fcfi + procedure :: __ppc_fcfi + end interface fcfi + public :: fcfi + + procedure(func_r8r8i) :: __ppc_fcfid + interface fcfid + procedure :: __ppc_fcfid + end interface fcfid + public :: fcfid + + procedure(func_r8r8i) :: __ppc_fcfud + interface fcfud + procedure :: __ppc_fcfud + end interface fcfud + public :: fcfud + end module __Fortran_PPC_intrinsics diff --git a/flang/test/Lower/ppc-intrinsics.f90 b/flang/test/Lower/ppc-intrinsics.f90 --- a/flang/test/Lower/ppc-intrinsics.f90 +++ b/flang/test/Lower/ppc-intrinsics.f90 @@ -65,3 +65,75 @@ ! CHECK-FIR: fir.call @fir.__ppc_fnmsub.f64.f64.f64.f64 ! CHECK-LLVMIR: call contract double @llvm.ppc.fnmsub.f64(double %{{[0-9]}}, double %{{[0-9]}}, double %{{[0-9]}}) end + +! CHECK-LABEL: fctid_test +subroutine fctid_test(x) + real(8) :: x, r + r = fctid(x) +! CHECK-FIR: fir.call @fir.__ppc_fctid.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fctid(double %{{[0-9]}}) +end + +! CHECK-LABEL: fctidz_test +subroutine fctidz_test(x) + real(8) :: x, r + r = fctidz(x) +! CHECK-FIR: fir.call @fir.__ppc_fctidz.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fctidz(double %{{[0-9]}}) +end + +! CHECK-LABEL: fctiw_test +subroutine fctiw_test(x) + real(8) :: x, r + r = fctiw(x) +! CHECK-FIR: fir.call @fir.__ppc_fctiw.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fctiw(double %{{[0-9]}}) +end + +! CHECK-LABEL: fctiwz_test +subroutine fctiwz_test(x) + real(8) :: x, r + r = fctiwz(x) +! CHECK-FIR: fir.call @fir.__ppc_fctiwz.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fctiwz(double %{{[0-9]}}) +end + +! CHECK-LABEL: fctudz_test +subroutine fctudz_test(x) + real(8) :: x, r + r = fctudz(x) +! CHECK-FIR: fir.call @fir.__ppc_fctudz.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fctudz(double %{{[0-9]}}) +end + +! CHECK-LABEL: fctuwz_test +subroutine fctuwz_test(x) + real(8) :: x, r + r = fctuwz(x) +! CHECK-FIR: fir.call @fir.__ppc_fctuwz.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fctuwz(double %{{[0-9]}}) +end + +! CHECK-LABEL: fcfi_test +subroutine fcfi_test(i) + real(8) :: i, r + r = fcfi(i) +! CHECK-FIR: fir.call @fir.__ppc_fcfi.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fcfid(double %{{[0-9]}}) +end + +! CHECK-LABEL: fcfid_test +subroutine fcfid_test(i) + real(8) :: i, r + r = fcfid(i) +! CHECK-FIR: fir.call @fir.__ppc_fcfid.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fcfid(double %{{[0-9]}}) +end + +! CHECK-LABEL: fcfud_test +subroutine fcfud_test(i) + real(8) :: i, r + r = fcfud(i) +! CHECK-FIR: fir.call @fir.__ppc_fcfud.f64.f64 +! CHECK-LLVMIR: call contract double @llvm.ppc.fcfud(double %{{[0-9]}}) +end