This is an archive of the discontinued LLVM Phabricator instance.

[flang] Use libm over pgmath for complex number intrinsics
ClosedPublic

Authored by DavidTruby on Sep 26 2022, 10:08 AM.

Details

Summary

This patch changes the handling of complex number intrinsics that
have C libm equivalents to call into those instead of calling the
external pgmath library.

Currently complex numbers to integer powers are excluded as libm
has no powi equivalent function.

Diff Detail

Event Timeline

DavidTruby created this revision.Sep 26 2022, 10:08 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 26 2022, 10:08 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
DavidTruby requested review of this revision.Sep 26 2022, 10:08 AM

Mostly looks good to me. And thank you for doing this!

I have minor concern about abs and conjg: it probably does not make sense to add entries that cannot be triggered.
Can you please also add LIT tests for entries that are not covered by existing tests (e.g. acos*, asin*)?

flang/lib/Lower/IntrinsicCall.cpp
1312

This is a no-op change, since IntrinsicLibrary::genAbs() lowers abs for complex into a call to libm's hypot.

1366

Same here because of IntrinsicLibrary::genConjg().

Thanks for the review!
Why do we call hypot instead of cabs already? Wouldn't it be better to use the direct libm function?

Thanks for the review!
Why do we call hypot instead of cabs already? Wouldn't it be better to use the direct libm function?

No deep reason. I used hypot because we already needed it to implement HYPOT, so it avoided adding and maintaining another runtime entry point. But I am not particularly attached to using one or the other (it may have consequences in LLVM, I have not tested). I agree with Slava though that the entries should only be added if you modify the related code to trigger them.

Otherwise LGTM.

Changed lowering of abs to use cabs instead of direct calls to hypot.
Added missing tests.

I've changed the abs lowering to go direct to cabs as I think this will make experimenting with/switching to the MLIR complex dialect simpler in future

jeanPerier accepted this revision.Sep 27 2022, 4:59 AM

LGTM, thanks

This revision is now accepted and ready to land.Sep 27 2022, 4:59 AM
vzakhari accepted this revision.Sep 27 2022, 8:39 AM

Thanks!