This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Map `ieee_fma` intrinsic to `llvm.fma`
ClosedPublic

Authored by sunshaoce on Jun 1 2023, 2:47 AM.

Details

Summary

Map ieee_fma intrinsic to LLVM IR as llvm.fma.

Diff Detail

Event Timeline

sunshaoce created this revision.Jun 1 2023, 2:47 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 1 2023, 2:47 AM
sunshaoce requested review of this revision.Jun 1 2023, 2:47 AM

Most target architectures support FMA and related instructions, and there's a standard IEEE_FMA generic function in the intrinsic module IEEE_ARITHMETIC in Fortran 2018. Please implement FMA in a way that is not just for RISC-V.

sunshaoce updated this revision to Diff 527656.Jun 1 2023, 4:02 PM

Address @klausler's comment. And, I’m not sure if the fmadd intrinsic is in the right place in the intrinsic.md.

sunshaoce retitled this revision from [Flang][RISCV] Adding fmadd intrinsic to [Flang] Adding fmadd intrinsic.Jun 1 2023, 4:02 PM
sunshaoce edited the summary of this revision. (Show Details)

Don't add a new nonstandard intrinsic when the standard already has a standard name for FMA, namely the procedure IEEE_FMA in the intrinsic module IEEE_ARITHMETIC. See subclause 17.11.4 in Fortran 2018.

The technique that has worked for us in the implementation of other procedures in intrinsic modules is to first declare a builtin intrinsic procedure, say "builtin_fma", in the module fortran_builtins, and then rename it in the intrinsic module via "use fortran_builtins, only: ieee_fma => builtin_fma". Then implement "builtin_fma" like any other standard intrinsic function. If you look in fortran_builtins for declarations of other INTRINSIC procedures, you'll be able to find useful examples.

sunshaoce updated this revision to Diff 528435.Jun 5 2023, 7:27 AM

@klausler, thanks for your detailed comments. I have tried to follow them.

sunshaoce retitled this revision from [Flang] Adding fmadd intrinsic to [Flang] Map `ieee_fma` intrinsic to `llvm.fma`.Jun 5 2023, 7:34 AM
sunshaoce edited the summary of this revision. (Show Details)
klausler added inline comments.Jun 5 2023, 8:59 AM
flang/lib/Evaluate/intrinsics.cpp
884 ↗(On Diff #528435)

IEEE_FMA doesn't work for COMPLEX. Use "SameReal" here, not "SameFloating".

sunshaoce updated this revision to Diff 528502.Jun 5 2023, 10:30 AM
sunshaoce marked an inline comment as done.

Replace SameFloating with SameReal

klausler accepted this revision.Jun 5 2023, 10:41 AM
This revision is now accepted and ready to land.Jun 5 2023, 10:41 AM
This revision was landed with ongoing or failed builds.Jun 5 2023, 11:01 AM
This revision was automatically updated to reflect the committed changes.