This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use softPromoteHalf legalization for fp16 without Zfh rather than PromoteFloat.
ClosedPublic

Authored by craig.topper on Mar 22 2021, 11:53 PM.

Details

Summary

The default legalization strategy is PromoteFloat which keeps
half in single precision format through multiple floating point
operations. Conversion to/from float is done at loads, stores,
bitcasts, and other places that care about the exact size being 16
bits.

This patches switches to the alternative method softPromoteHalf.
This aims to keep the type in 16-bit format between every operation.
So we promote to float and immediately round for any arithmetic
operation. This should be closer to the IR semantics since we
are rounding after each operation and not accumulating extra
precision across multiple operations. X86 is the only other
target that enables this today. See https://reviews.llvm.org/D73749

I had to update getRegisterTypeForCallingConv to force f16 to
use f32 when the F extension is enabled. This way we can still
pass it in the lower bits of an FPR for ilp32f and lp64f ABIs.
The softPromoteHalf would otherwise always give i16 as the
argument type.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 22 2021, 11:53 PM
craig.topper requested review of this revision.Mar 22 2021, 11:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2021, 11:53 PM
Herald added a subscriber: MaskRay. · View Herald Transcript

LGTM. Waiting for the consent of others.

asb accepted this revision.Apr 1 2021, 3:46 AM

Let's mention it in the community call today just in case anyone has strong differing opinions, but this lowering strategy makes much more intuitive sense to me.

This revision is now accepted and ready to land.Apr 1 2021, 3:46 AM

General code gen behavior change is look good to me.

frasercrmck accepted this revision.Apr 1 2021, 8:53 AM

Indeed. And it is also good to have a second in-tree target test this strategy.

This revision was landed with ongoing or failed builds.Apr 1 2021, 12:42 PM
This revision was automatically updated to reflect the committed changes.