Skip to content

Commit 9c0bc36

Browse files
committed
Experiment with soft-promotion in FP regs (not working).
1 parent d12b868 commit 9c0bc36

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

llvm/lib/Target/SystemZ/SystemZCallingConv.td

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def RetCC_SystemZ_ELF : CallingConv<[
5050
// other floating-point argument registers available for code that
5151
// doesn't care about the ABI. All floating-point argument registers
5252
// are call-clobbered, so we can use all of them here.
53-
CCIfType<[f16], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
54-
CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
53+
CCIfType<[f16, f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
5554
CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
5655

5756
// Similarly for vectors, with V24 being the ABI-compliant choice.
@@ -116,8 +115,7 @@ def CC_SystemZ_ELF : CallingConv<[
116115
CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
117116

118117
// The first 4 float and double arguments are passed in even registers F0-F6.
119-
CCIfType<[f16], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
120-
CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
118+
CCIfType<[f16, f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
121119
CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
122120

123121
// The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ MVT SystemZTargetLowering::getRegisterTypeForCallingConv(
799799
if (VT.isVector() && VT.getSizeInBits() == 128 &&
800800
VT.getVectorNumElements() == 1)
801801
return MVT::v16i8;
802-
// Keep f16 so that they can be recognized and handled.
802+
// Keep f16 so it can be recognized and handled.
803803
if (VT == MVT::f16)
804804
return MVT::f16;
805805
return TargetLowering::getRegisterTypeForCallingConv(Context, CC, VT);
@@ -1625,10 +1625,13 @@ bool SystemZTargetLowering::splitValueIntoRegisterParts(
16251625

16261626
// Convert f16 to f32 (Out-arg).
16271627
if (PartVT == MVT::f16) {
1628-
assert(NumParts == 1 && "");
1629-
SDValue I16Val = DAG.getBitcast(MVT::i16, Val);
1630-
SDValue I32Val = DAG.getAnyExtOrTrunc(I16Val, DL, MVT::i32);
1631-
Parts[0] = DAG.getBitcast(MVT::f32, I32Val);
1628+
assert(NumParts == 1 && "f16 only needs one register.");
1629+
SDValue F16Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, MVT::v8f16,
1630+
DAG.getUNDEF(MVT::v8f16), Val,
1631+
DAG.getVectorIdxConstant(0, DL));
1632+
SDValue F32Vec = DAG.getBitcast(MVT::v4f32, F16Vec);
1633+
Parts[0] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32,
1634+
F32Vec, DAG.getVectorIdxConstant(0, DL));
16321635
return true;
16331636
}
16341637

@@ -1654,9 +1657,13 @@ static SDValue convertF32ToF16(SDValue F32Val, SelectionDAG &DAG,
16541657
const SDLoc &DL) {
16551658
assert(F32Val->getOpcode() == ISD::CopyFromReg &&
16561659
"Only expecting to handle f16 with CopyFromReg here.");
1657-
SDValue I32Val = DAG.getBitcast(MVT::i32, F32Val);
1658-
SDValue I16Val = DAG.getAnyExtOrTrunc(I32Val, DL, MVT::i16);
1659-
return DAG.getBitcast(MVT::f16, I16Val);
1660+
1661+
SDValue F32Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, MVT::v4f32,
1662+
DAG.getUNDEF(MVT::v4f32), F32Val,
1663+
DAG.getVectorIdxConstant(0, DL));
1664+
SDValue F16Vec = DAG.getBitcast(MVT::v8f16, F32Vec);
1665+
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f16,
1666+
F16Vec, DAG.getVectorIdxConstant(0, DL));
16601667
}
16611668

16621669
SDValue SystemZTargetLowering::LowerFormalArguments(

llvm/lib/Target/SystemZ/SystemZISelLowering.h

-5
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,6 @@ class SystemZTargetLowering : public TargetLowering {
471471
}
472472
bool softPromoteHalfType() const override { return true; }
473473
bool useFPRegsForHalfType() const override { return true; }
474-
bool shouldKeepZExtForFP16Conv() const override {
475-
// Keep the zero extension from 16 bits if present (as with incoming
476-
// arguments).
477-
return true;
478-
}
479474
bool hasInlineStackProbe(const MachineFunction &MF) const override;
480475
AtomicExpansionKind shouldCastAtomicLoadInIR(LoadInst *LI) const override;
481476
AtomicExpansionKind shouldCastAtomicStoreInIR(StoreInst *SI) const override;

llvm/test/CodeGen/SystemZ/fp-half.ll

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ define half @fun3(half %Op0, ptr %Dst, ptr %Src) {
119119
; CHECK-NEXT: br %r14
120120
entry:
121121
store half %Op0, ptr %Dst
122-
123122
%Res = load half, ptr %Src
124123
ret half %Res
125124
}

0 commit comments

Comments
 (0)