This is an archive of the discontinued LLVM Phabricator instance.

[X86] Promote f16 STRICT_FROUND to f32 and call libc.
ClosedPublic

Authored by craig.topper on Nov 12 2021, 4:16 PM.

Diff Detail

Event Timeline

craig.topper created this revision.Nov 12 2021, 4:16 PM
craig.topper requested review of this revision.Nov 12 2021, 4:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2021, 4:16 PM
pengfei added inline comments.Nov 12 2021, 6:55 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

What't the concern we can't emulate for STRICT_FROUND. I wonder if we have the same problem when promoting.

craig.topper added inline comments.Nov 12 2021, 7:06 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

I believe we can't emulate STRICT_FROUND the way we emulate FROUND because adding 0.4999999999 to a value that has no fractional bits will generate a spurious inexact exception when it gets truncated.

If the libcall is ok for f32 it should be ok for f16.

pengfei accepted this revision.Nov 12 2021, 7:23 PM

LGTM.

llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

I see, thanks. But we may raise one more inexact exception when truncating back from f32, e.g. 2048.5
Not sure if it matters given we don't emulate the exception well in library too.

This revision is now accepted and ready to land.Nov 12 2021, 7:23 PM
craig.topper added inline comments.Nov 12 2021, 7:35 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

I don't follow. The f32 libcall should always give back a number with no fractional bits.

pengfei added inline comments.Nov 12 2021, 7:39 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

Yes, but 2049 cannot be represented in FP16. The nearest one is 2050.

craig.topper added inline comments.Nov 12 2021, 7:47 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

We started from f16 which couldn’t have contained 2048.5 right?

pengfei added inline comments.Nov 12 2021, 7:56 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
22440–22443

Oh, yes. I missed that. Thank you.

This revision was landed with ongoing or failed builds.Nov 12 2021, 9:46 PM
This revision was automatically updated to reflect the committed changes.