This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Implement lround*/llround*/lrint*/llrint* with fcvt instruction with -fno-math-errno
ClosedPublic

Authored by craig.topper on Jun 30 2021, 9:44 AM.

Details

Summary

These are fp->int conversions using either RMM or dynamic rounding modes.

The lround and lrint opcodes have a return type of either i32 or
i64 depending on sizeof(long) in the frontend which should follow
xlen. llround/llrint should always return i64 so we'll need a libcall
for those on rv32.

The frontend will only emit the intrinsics if -fno-math-errno is in
effect otherwise a libcall will be emitted which will not use
these ISD opcodes.

gcc also does this optimization.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 30 2021, 9:44 AM
craig.topper requested review of this revision.Jun 30 2021, 9:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2021, 9:44 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
arcbbb accepted this revision.Jul 6 2021, 10:07 AM

LGTM

This revision is now accepted and ready to land.Jul 6 2021, 10:07 AM
jrtc27 added inline comments.Jul 6 2021, 10:25 AM
llvm/test/CodeGen/RISCV/double-intrinsics-rv32.ll
2 ↗(On Diff #355603)

We upstreamed support to UTC to let you pre-process with sed 's/iXLEN/i32/' | llc ... so you can have just the template rather than need two copies of the file. Helps keeps things a bit more manageable (though unfortunately you've already burned the time writing both copies...).

craig.topper added inline comments.Jul 6 2021, 10:29 AM
llvm/test/CodeGen/RISCV/double-intrinsics-rv32.ll
2 ↗(On Diff #355603)

Is there an example test that does this?

jrtc27 added inline comments.Jul 6 2021, 10:31 AM
llvm/test/CodeGen/RISCV/double-intrinsics-rv32.ll
2 ↗(On Diff #355603)

Not with update_llc_test_checks.py as it's relatively recent, but there are lots of sed-using tests in llvm/test/CodeGen/Hexagon, and a few in AArch64, ARM, WinEH and X86. It should "just work" if you do the obvious thing.

2 ↗(On Diff #355603)

Well, llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/pre-process.ll also exists as a test for this use case

This revision was landed with ongoing or failed builds.Jul 6 2021, 11:45 AM
This revision was automatically updated to reflect the committed changes.