This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Lower the sqrt intrinsics
ClosedPublic

Authored by kiranchandramohan on Mar 18 2022, 9:56 AM.

Details

Summary

The intrinsic computes the square root for real and complex numbers. By
default they are lowered to runtime calls to libpgmath. With the llvm
option, it can be lowered to llvm intrinsics (not all types .eg. complex
are supported for llvm lowering).

This is part of the upstreaming effort from the fir-dev branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: mehdi_amini. · View Herald Transcript
kiranchandramohan requested review of this revision.Mar 18 2022, 9:56 AM
schweitz accepted this revision.Mar 18 2022, 11:18 AM
schweitz added inline comments.
flang/lib/Lower/IntrinsicCall.cpp
1040

What happens with KIND=10? Does it fall back to a TODO message?

This revision is now accepted and ready to land.Mar 18 2022, 11:18 AM
flang/lib/Lower/IntrinsicCall.cpp
1040

Yes, it hits a TODO, but code is generated as well.

But fir-dev has the following behaviour. A release build adds a convert to 32 bit and calls llvm.sqrt.f32. A debug build will trigger an assertion.
Assertion `!bestMatchDistance.isLosingPrecision() && "runtime selection loses precision"' failed. I have posted the following issue to capture this.
https://github.com/flang-compiler/f18-llvm-project/issues/1497

This revision was automatically updated to reflect the committed changes.