This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Inline scalar ceil/floor/trunc/rint/round/roundeven.
ClosedPublic

Authored by craig.topper on Oct 21 2022, 3:32 PM.

Details

Summary

This avoids the call overhead as well as the the save/restore of
fflags and the snan handling in the libm function.

The save/restore of fflags and snan handling are needed to be
correct for -ftrapping-math. I think we can ignore them in the
default environment.

The inline sequence will generate an invalid exception for nan
and an inexact exception if fractional bits are discarded.

I've used a custom inserter to explicitly create the control flow
around the float->int->float conversion.

We can probably avoid the final fsgnj after the conversion for
no signed zeros FMF, but I'll leave that for future work.

Note the comparison constant is slightly different than glibc uses.
They use 1<<53 for double, I'm using 1<<52. I believe either are valid.
Numbers >= 1<<52 can't have any fractional bits. It's ok to do the
float->int->float conversion on numbers between 1<<53 and 1<<52 since
they will all fit in 64. We only have a problem if the double can't fit
in i64

Diff Detail

Event Timeline

craig.topper created this revision.Oct 21 2022, 3:32 PM
craig.topper requested review of this revision.Oct 21 2022, 3:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 3:32 PM
reames added inline comments.Oct 24 2022, 8:16 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
4102

Can you precommit a change to add the vector naming so that disappears from this diff?

10813

Are SinkMBB and TailMBB the same?

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
528

Can you precommit the style change here?

craig.topper added inline comments.Oct 24 2022, 1:51 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
10813

Yeah. I was looking at multiple custom inserters across multiple targets and must have copied the comment from one and used the name from another.

reames accepted this revision.Oct 25 2022, 3:26 PM

LGTM

This revision is now accepted and ready to land.Oct 25 2022, 3:26 PM
craig.topper edited the summary of this revision. (Show Details)Oct 26 2022, 11:22 AM
enh added a subscriber: enh.Oct 26 2022, 11:58 AM