Skip to content

Commit cc53913

Browse files
authored
[CodeGen] Use __extendhfsf2 and __truncsfhf2 by default (llvm#126880)
The standard libcalls for half to float and float to half conversion are __extendhfsf2 and __truncsfhf2. However, LLVM currently uses __gnu_h2f_ieee and __gnu_f2h_ieee instead. As far as I can tell, these libcalls are an ARM-ism and only provided by libgcc on that platform. compiler-rt always provides both libcalls. Use the standard libcalls by default, and only use the __gnu libcalls on ARM.
1 parent 4af8c53 commit cc53913

40 files changed

+1147
-1169
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-S128-ni:1:10:20"
2+
target triple = "wasm32-unknown-emscripten"
3+
4+
define ptr @emscripten_return_address() {
5+
ret ptr null
6+
}

lld/test/wasm/lto/Inputs/libcall-truncsfhf2.ll

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llvm-as %s -o %t.o
2+
; RUN: llvm-as %p/Inputs/libcall-return-addr.ll -o %t.return-addr.o
3+
; RUN: rm -f %t.a
4+
; RUN: llvm-ar rcs %t.a %t.return-addr.o
5+
; RUN: not wasm-ld --export-all %t.o %t.a -o %t.wasm 2>&1 | FileCheck %s
6+
7+
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-S128-ni:1:10:20"
8+
target triple = "wasm32-unknown-emscripten"
9+
10+
@g_ptr = global ptr null
11+
12+
define void @_start() {
13+
%addr = call ptr @llvm.returnaddress(i32 1)
14+
store ptr %addr, ptr @g_ptr
15+
ret void
16+
}
17+
18+
; CHECK: wasm-ld: error: {{.*}}return-addr.o): attempt to add bitcode file after LTO (emscripten_return_address)

lld/test/wasm/lto/libcall-truncsfhf2.ll

Lines changed: 0 additions & 20 deletions
This file was deleted.

llvm/include/llvm/IR/RuntimeLibcalls.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ HANDLE_LIBCALL(FPEXT_F16_F128, "__extendhftf2")
384384
HANDLE_LIBCALL(FPEXT_F16_F80, "__extendhfxf2")
385385
HANDLE_LIBCALL(FPEXT_F32_F64, "__extendsfdf2")
386386
HANDLE_LIBCALL(FPEXT_F16_F64, "__extendhfdf2")
387-
HANDLE_LIBCALL(FPEXT_F16_F32, "__gnu_h2f_ieee")
388-
HANDLE_LIBCALL(FPROUND_F32_F16, "__gnu_f2h_ieee")
387+
HANDLE_LIBCALL(FPEXT_F16_F32, "__extendhfsf2")
388+
HANDLE_LIBCALL(FPROUND_F32_F16, "__truncsfhf2")
389389
HANDLE_LIBCALL(FPROUND_F64_F16, "__truncdfhf2")
390390
HANDLE_LIBCALL(FPROUND_F80_F16, "__truncxfhf2")
391391
HANDLE_LIBCALL(FPROUND_F128_F16, "__trunctfhf2")

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
170170
// TODO: BridgeOS should be included in isOSDarwin.
171171
setLibcallName(RTLIB::EXP10_F32, "__exp10f");
172172
setLibcallName(RTLIB::EXP10_F64, "__exp10");
173-
} else {
174-
setLibcallName(RTLIB::FPEXT_F16_F32, "__gnu_h2f_ieee");
175-
setLibcallName(RTLIB::FPROUND_F32_F16, "__gnu_f2h_ieee");
176173
}
177174

178175
if (TT.isGNUEnvironment() || TT.isOSFuchsia() ||

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
767767
setLibcallName(LC.Op, LC.Name);
768768
setLibcallCallingConv(LC.Op, LC.CC);
769769
}
770+
} else if (!Subtarget->isTargetMachO()) {
771+
setLibcallName(RTLIB::FPROUND_F32_F16, "__gnu_f2h_ieee");
772+
setLibcallName(RTLIB::FPEXT_F16_F32, "__gnu_h2f_ieee");
770773
}
771774

772775
if (Subtarget->isThumb1Only())

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,11 +1886,6 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
18861886
setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf");
18871887
else
18881888
setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf");
1889-
1890-
// Routines to handle fp16 storage type.
1891-
setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
1892-
setLibcallName(RTLIB::FPROUND_F64_F16, "__truncdfhf2");
1893-
setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
18941889
}
18951890

18961891
const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const {

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,9 +1549,6 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
15491549
if (Subtarget.useRVVForFixedLengthVectors())
15501550
setTargetDAGCombine(ISD::BITCAST);
15511551

1552-
setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
1553-
setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
1554-
15551552
// Disable strict node mutation.
15561553
IsStrictFPEnabled = true;
15571554
EnableExtLdPromotion = true;

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
377377

378378
setMaxAtomicSizeInBitsSupported(64);
379379

380-
// Override the __gnu_f2h_ieee/__gnu_h2f_ieee names so that the f32 name is
381-
// consistent with the f64 and f128 names.
382-
setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
383-
setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
384-
385380
// Define the emscripten name for return address helper.
386381
// TODO: when implementing other Wasm backends, make this generic or only do
387382
// this on emscripten depending on what they end up doing.

0 commit comments

Comments
 (0)