Skip to content

Commit ade22fc

Browse files
lei137EsmeYi
andauthored
[PowerPC] Support conversion between f16 and f128 (llvm#130158)
Enables conversion between f16 and f128. Expanding on pre-Power9 targets and using HW instructions on Power9. Fixes llvm#92866 Commandeer of: llvm#97677 --------- Co-authored-by: esmeyi <[email protected]>
1 parent be0a3b2 commit ade22fc

File tree

5 files changed

+215
-300
lines changed

5 files changed

+215
-300
lines changed

llvm/lib/IR/RuntimeLibcalls.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
8282
setLibcallName(RTLIB::POWI_F128, "__powikf2");
8383
setLibcallName(RTLIB::FPEXT_F32_F128, "__extendsfkf2");
8484
setLibcallName(RTLIB::FPEXT_F64_F128, "__extenddfkf2");
85+
setLibcallName(RTLIB::FPROUND_F128_F16, "__trunckfhf2");
8586
setLibcallName(RTLIB::FPROUND_F128_F32, "__trunckfsf2");
8687
setLibcallName(RTLIB::FPROUND_F128_F64, "__trunckfdf2");
8788
setLibcallName(RTLIB::FPTOSINT_F128_I32, "__fixkfsi");

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,19 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
223223
setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i8, Expand);
224224
}
225225

226+
setTruncStoreAction(MVT::f128, MVT::f16, Expand);
227+
setOperationAction(ISD::FP_TO_FP16, MVT::f128, Expand);
228+
226229
if (Subtarget.isISA3_0()) {
230+
setLoadExtAction(ISD::EXTLOAD, MVT::f128, MVT::f16, Legal);
227231
setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f16, Legal);
228232
setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Legal);
229233
setTruncStoreAction(MVT::f64, MVT::f16, Legal);
230234
setTruncStoreAction(MVT::f32, MVT::f16, Legal);
231235
} else {
232236
// No extending loads from f16 or HW conversions back and forth.
237+
setLoadExtAction(ISD::EXTLOAD, MVT::f128, MVT::f16, Expand);
238+
setOperationAction(ISD::FP16_TO_FP, MVT::f128, Expand);
233239
setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f16, Expand);
234240
setOperationAction(ISD::FP16_TO_FP, MVT::f64, Expand);
235241
setOperationAction(ISD::FP_TO_FP16, MVT::f64, Expand);

llvm/lib/Target/PowerPC/PPCInstrVSX.td

+4
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,8 @@ defm : ScalToVecWPermute<
39953995
(SUBREG_TO_REG (i64 1), (VEXTSH2Ds (LXSIHZX ForceXForm:$src)), sub_64)>;
39963996

39973997
// Load/convert and convert/store patterns for f16.
3998+
def : Pat<(f128 (extloadf16 ForceXForm:$src)),
3999+
(f128 (XSCVDPQP (XSCVHPDP (LXSIHZX ForceXForm:$src))))>;
39984000
def : Pat<(f64 (extloadf16 ForceXForm:$src)),
39994001
(f64 (XSCVHPDP (LXSIHZX ForceXForm:$src)))>;
40004002
def : Pat<(truncstoref16 f64:$src, ForceXForm:$dst),
@@ -4003,6 +4005,8 @@ def : Pat<(f32 (extloadf16 ForceXForm:$src)),
40034005
(f32 (COPY_TO_REGCLASS (XSCVHPDP (LXSIHZX ForceXForm:$src)), VSSRC))>;
40044006
def : Pat<(truncstoref16 f32:$src, ForceXForm:$dst),
40054007
(STXSIHX (XSCVDPHP (COPY_TO_REGCLASS $src, VSFRC)), ForceXForm:$dst)>;
4008+
def : Pat<(f128 (f16_to_fp i32:$A)),
4009+
(f128 (XSCVDPQP (XSCVHPDP (MTVSRWZ $A))))>;
40064010
def : Pat<(f64 (f16_to_fp i32:$A)),
40074011
(f64 (XSCVHPDP (MTVSRWZ $A)))>;
40084012
def : Pat<(f32 (f16_to_fp i32:$A)),

0 commit comments

Comments
 (0)