Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point llvm lowering of intrinsics #1497

Open
kiranchandramohan opened this issue Feb 24, 2022 · 2 comments
Open

Floating point llvm lowering of intrinsics #1497

kiranchandramohan opened this issue Feb 24, 2022 · 2 comments

Comments

@kiranchandramohan
Copy link
Collaborator

The floating-point lowering of Fortran intrinsics like abs uses the llvm intrinsics. Currently, we only have the f32 and f64 floating types handled. If a quad precision or a half-precision then this will result in being converted to a 32 bit type and then the llvm.fabs.f32 llvm intrinsic is used to handle the conversion. For a precision higher than 64 this will cause an assert in a build with assert but will proceed with conversions in a release build. The documentation for llvm.fabs mentions several types that can be used with the fabs intrinsic but also cautions that all targets might not support these.

I am in the process of upstreaming this code, and I have the following questions,

  1. Is this a first-cut implementation handling the most commonly used types (32, 64)?
  2. Or was a conclusion reached that the 32 and 64 bit types are the only ones that are handled by all targets?
@sscalpone
Copy link
Member

It's a first-cut implementation that handles only 32- and 64-bit types.

I've been thinking we might adjust the implementation of the numeric intrinsics. Roughly, I think we should implement the Fortran intrinsics using the available intrinsics from the standard and quadmath libraries. The focus of this library would be coverage of all of the intrinsics across all of the KINDs we which to support. The resulting library would be used in the compiler for folding and also in the runtime when llvm intrinsics are not available. Perhaps the mlir math dialect needs extending with more intrinsics or fir can be used.

@kiranchandramohan kiranchandramohan changed the title Floating point llvm lowering of abs intrinsic Floating point llvm lowering of intrinsics Mar 18, 2022
@kiranchandramohan
Copy link
Collaborator Author

kiranchandramohan commented Mar 18, 2022

Thanks @sscalpone for the reply. Apologies for the delay in my response.

It's a first-cut implementation that handles only 32- and 64-bit types.
OK

I've been thinking we might adjust the implementation of the numeric intrinsics. Roughly, I think we should implement the Fortran intrinsics using the available intrinsics from the standard and quadmath libraries.

I am guessing you mean the standard math library here when you mention standard.

The focus of this library would be coverage of all of the intrinsics across all of the KINDs we which to support. The resulting library would be used in the compiler for folding and also in the runtime when llvm intrinsics are not available.

Are you suggesting a wrapper library (like pgmath) here?

Perhaps the mlir math dialect needs extending with more intrinsics or fir can be used.

And since math library subsequently lowers to LLVM or makes calls to the math library, can we effective replace the existing lowering to llvm intrinsics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants