This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support llvm.lround intrinsics with i32 return type on RV64.
ClosedPublic

Authored by craig.topper on Mar 29 2023, 7:12 PM.

Details

Summary

It seems that flang expects this to work. Even though long isn't
i32 on RV64 or most X86-64 platforms.

It's easy for us to support when we have native FP instructions.
I fell back to i64 and truncated the result otherwise. The
documentation for lround says it returns an unspecified value if
doesn't fit in the integer type. I have no idea what flang is
expecting. I really only did the libcall to avoid forking a test.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 29 2023, 7:12 PM
Herald added a project: Restricted Project. · View Herald Transcript
craig.topper requested review of this revision.Mar 29 2023, 7:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 7:12 PM
asb accepted this revision.Apr 12 2023, 2:24 AM

Seems weird that Flang needs this, but LGTM.

This revision is now accepted and ready to land.Apr 12 2023, 2:24 AM

Seems weird that Flang needs this, but LGTM.

Here is the table from flang where this is used.

lib/Optimizer/Builder/IntrinsicCall.cpp
1375: // llvm.lround behaves the same way as libm's lround.
1376: {"nint", "llvm.lround.i64.f64", genIntF64FuncType<64>, genLibCall},
1377: {"nint", "llvm.lround.i64.f32", genIntF32FuncType<64>, genLibCall},
1378: {"nint", "llvm.lround.i32.f64", genIntF64FuncType<32>, genLibCall},
1379: {"nint", "llvm.lround.i32.f32", genIntF32FuncType<32>, genLibCall},