This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] [builtins] Use _Float16 on extendhfsf2, truncdfhf2 __truncsfhf2 if available
ClosedPublic

Authored by zatrazz on Nov 18 2020, 11:36 AM.

Details

Summary

On AArch64 it allows use the native FP16 ABI (although libcalls are
not emitted for fptrunc/fpext lowering), while on other architectures
the expected current semantic is preserved (arm for instance).

Diff Detail

Event Timeline

zatrazz created this revision.Nov 18 2020, 11:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2020, 11:36 AM
Herald added subscribers: Restricted Project, kristof.beyls, mgorny, dberris. · View Herald Transcript
zatrazz requested review of this revision.Nov 18 2020, 11:36 AM
This revision is now accepted and ready to land.Nov 19 2020, 1:48 AM
This revision was landed with ongoing or failed builds.Nov 19 2020, 10:15 AM
This revision was automatically updated to reflect the committed changes.

Isn't COMPILER_RT_HAS_FLOAT16 generated using the host compiler? If so, using the same flag for a compiler_rt test could fail if the host compiler supports f16 and the target compiler does not.

This seems to have broken some tests on our Mac bots:
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8863040226745741728/+/steps/package_clang/0/stdout

FAIL: Builtins-x86_64-darwin :: truncsfhf2_test.c (195 of 208)
******************** TEST 'Builtins-x86_64-darwin :: truncsfhf2_test.c' FAILED ********************
Script:
--
: 'RUN: at line 1';       /opt/s/w/ir/cache/builder/src/third_party/llvm-bootstrap/./bin/clang   -gline-tables-only  -arch x86_64 -stdlib=libc++ -mmacosx-version-min=10.10 -isysroot /opt/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -DCOMPILER_RT_HAS_FLOAT16  -fno-builtin -I /opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/builtins -nodefaultlibs /opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/truncsfhf2_test.c /opt/s/w/ir/cache/builder/src/third_party/llvm-bootstrap/./lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a  -lSystem -o /opt/s/w/ir/cache/builder/src/third_party/llvm-bootstrap/projects/compiler-rt/test/builtins/Unit/X86_64DarwinConfig/Output/truncsfhf2_test.c.tmp &&  /opt/s/w/ir/cache/builder/src/third_party/llvm-bootstrap/projects/compiler-rt/test/builtins/Unit/X86_64DarwinConfig/Output/truncsfhf2_test.c.tmp
--
Exit Code: 1

Command Output (stderr):
--
In file included from /opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/truncsfhf2_test.c:6:
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:16:15: error: _Float16 is not supported on this target
static inline TYPE_FP16 fromRep16(uint16_t x)
              ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:19:5: error: _Float16 is not supported on this target
    TYPE_FP16 ret;
    ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:51:32: error: _Float16 is not supported on this target
static inline uint16_t toRep16(TYPE_FP16 x)
                               ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:85:34: error: _Float16 is not supported on this target
static inline int compareResultH(TYPE_FP16 result,
                                 ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:220:15: error: _Float16 is not supported on this target
static inline TYPE_FP16 makeQNaN16(void)
              ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:242:15: error: _Float16 is not supported on this target
static inline TYPE_FP16 makeNaN16(uint16_t rand)
              ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:264:15: error: _Float16 is not supported on this target
static inline TYPE_FP16 makeInf16(void)
              ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/truncsfhf2_test.c:8:1: error: _Float16 is not supported on this target
TYPE_FP16 __truncsfhf2(float a);
^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/truncsfhf2_test.c:12:5: error: _Float16 is not supported on this target
    TYPE_FP16 x = __truncsfhf2(a);
    ^
/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/builtins/Unit/fp_test.h:7:19: note: expanded from macro 'TYPE_FP16'
#define TYPE_FP16 _Float16
                  ^
9 errors generated.

Isn't COMPILER_RT_HAS_FLOAT16 generated using the host compiler? If so, using the same flag for a compiler_rt test could fail if the host compiler supports f16 and the target compiler does not.

Indeed and it seems to be for mac. I will work on a fix, sorry for take to long to notice the issue.