This is an archive of the discontinued LLVM Phabricator instance.

[Clang][FP16] Add 4 builtins for _Float16
ClosedPublic

Authored by pengfei on Jun 4 2022, 6:20 AM.

Details

Summary

We are lacking builtins support for _Float16. In most cases, we can use other floating-type builtins and truncate them to _Float16.
But it's a problem to SNaN, e.g., https://gcc.godbolt.org/z/cqr5nG1jh
This patch adds __builtin_nansf16 support as well as other 3 ones since they are usually used together.

Diff Detail

Event Timeline

pengfei created this revision.Jun 4 2022, 6:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2022, 6:20 AM
pengfei requested review of this revision.Jun 4 2022, 6:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2022, 6:20 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
LuoYuanke added inline comments.Jun 4 2022, 6:04 PM
clang/include/clang/Basic/Builtins.def
145

Is the builtin sorted in alphabet order?

pengfei added inline comments.Jun 4 2022, 6:46 PM
clang/include/clang/Basic/Builtins.def
145

No, I think there's no strict order requirment here. The xxxf128 builtins have already not met it.

LuoYuanke added inline comments.Jun 4 2022, 7:13 PM
clang/test/CodeGen/builtin_Float16.c
8

Is _Float16 a legal type for target armv7a and aarch64?

LuoYuanke added inline comments.Jun 4 2022, 8:01 PM
clang/test/CodeGen/builtin_Float16.c
8

Maybe use __fp16 because it is supported on every target.

pengfei added inline comments.Jun 4 2022, 8:37 PM
clang/test/CodeGen/builtin_Float16.c
8

No, I intentionally use _Float16 here because I want to make it correspond to the type define x in Builtins.def
I think we should always use x (represents _Float16) rather than h (represents __fp16) when defining FP16 builtins. It doesn't make sense to to add new buildins for storage type, because all arithmetic operations should be promoted to float.

Allen added a subscriber: Allen.Jun 4 2022, 8:55 PM
LuoYuanke accepted this revision.Jun 5 2022, 4:29 PM
This revision is now accepted and ready to land.Jun 5 2022, 4:29 PM
This revision was automatically updated to reflect the committed changes.