[flang-commits] [flang] 070dd18 - [Flang] [PowerPC} Implement the floating-point conversion PowerPC intrinsics

Paul Scoropan via flang-commits flang-commits at lists.llvm.org
Mon Mar 6 07:02:13 PST 2023


Author: Paul Scoropan
Date: 2023-03-06T09:50:48-05:00
New Revision: 070dd18e3112b5393a6e001e875fec2e3704efff

URL: https://github.com/llvm/llvm-project/commit/070dd18e3112b5393a6e001e875fec2e3704efff
DIFF: https://github.com/llvm/llvm-project/commit/070dd18e3112b5393a6e001e875fec2e3704efff.diff

LOG: [Flang] [PowerPC} Implement the floating-point conversion PowerPC intrinsics

All the fc* floating point conversion PowerPC intrinsics are simply lowered to their LLVM IR intrinsic counterparts and do not require any additional error checking.

Reviewed By: klausler, jeanPerier

Differential Revision: https://reviews.llvm.org/D145080

Added: 
    

Modified: 
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp
    flang/module/__fortran_ppc_intrinsics.f90
    flang/test/Lower/ppc-intrinsics.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 84d534febdba5..eff53b3975093 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1348,6 +1348,16 @@ static constexpr MathOperation mathOperations[] = {
 };
 
 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<mlir::math::FmaOp>},
     {"__ppc_fmadd", "llvm.fma.f64", genF64F64F64F64FuncType,

diff  --git a/flang/module/__fortran_ppc_intrinsics.f90 b/flang/module/__fortran_ppc_intrinsics.f90
index 9b83239731020..fff18aa36d2fe 100644
--- a/flang/module/__fortran_ppc_intrinsics.f90
+++ b/flang/module/__fortran_ppc_intrinsics.f90
@@ -52,4 +52,72 @@ end function func_r8r8r8r8
   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
index 293a35a63b061..8410fbdd86aa1 100644
--- a/flang/test/Lower/ppc-intrinsics.f90
+++ b/flang/test/Lower/ppc-intrinsics.f90
@@ -65,3 +65,75 @@ subroutine fnmsub_testd(a, x, y)
 ! 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


        


More information about the flang-commits mailing list