This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add DAG combine to fold (fp_to_int (ffloor X)) -> (fcvt X, rdn)
ClosedPublic

Authored by craig.topper on Jan 6 2022, 3:08 PM.

Details

Summary

Similar for ceil, trunc, round, and roundeven. This allows us to use
static rounding modes to avoid a libcall.

This optimization is done for AArch64 as isel patterns.
RISCV doesn't have instructions for ceil/floor/trunc/round/roundeven
so the operations don't stick around until isel to enable a pattern
match. Thus I've implemented a DAG combine.

We only handle XLen types except i32 on RV64. i32 will be type
legalized to a RISCVISD node. All other types will be type legalized
to XLen and maintain the FP_TO_SINT/UINT ISD opcode.

Diff Detail

Event Timeline

craig.topper created this revision.Jan 6 2022, 3:08 PM
craig.topper requested review of this revision.Jan 6 2022, 3:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2022, 3:08 PM
Herald added a subscriber: MaskRay. · View Herald Transcript

Remove a change that was only needed due to an earlier implementation.
clang-format

xgupta added a subscriber: xgupta.Jan 7 2022, 7:00 PM

Rename check-prefixes

asb added a comment.Jan 10 2022, 1:18 PM

LGTM, modulo one comment.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
7085

Is it possible to add some test coverage for this?

craig.topper added inline comments.Jan 10 2022, 3:33 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
7085

No because we don't have f16 as a legal type with Zfhmin yet. I was coding defensively assuming that would change in the future and I didn't want someone to have to audit for it.

asb accepted this revision.Jan 11 2022, 2:38 AM
asb added inline comments.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
7085

Thanks for clarifying - I'd forgotten f16 wasn't yet legal for zfhmin. As you suggest coding defensively is obviously the right thing to do even if we can't test it currently.

This revision is now accepted and ready to land.Jan 11 2022, 2:38 AM
This revision was landed with ongoing or failed builds.Jan 11 2022, 9:06 AM
This revision was automatically updated to reflect the committed changes.