Skip to content

Commit 44dffa4

Browse files
committed
Try to make f16 legal instead
1 parent 9c0bc36 commit 44dffa4

23 files changed

+906
-246
lines changed

clang/lib/Basic/Targets/SystemZ.h

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
9393
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
9494

9595
// True if the backend supports operations on the half LLVM IR type.
96+
// By setting this to false, conversions will happen for _Float16 around
97+
// a statement by default with operations done in float. However, if
98+
// -ffloat16-excess-precision=none is given, no conversions will be made
99+
// and instead the backend will promote each half operation to float
100+
// individually.
96101
HasLegalHalfType = false;
97102
// Allow half arguments and return values.
98103
HalfArgsAndReturns = true;

clang/lib/Sema/SemaExpr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16548,7 +16548,7 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
1654816548
PromoteType = QualType();
1654916549
}
1655016550
}
16551-
if (TInfo->getType()->isFloat16Type() || TInfo->getType()->isFloat32Type())
16551+
if (TInfo->getType()->isSpecificBuiltinType(BuiltinType::Float))
1655216552
PromoteType = Context.DoubleTy;
1655316553
if (!PromoteType.isNull())
1655416554
DiagRuntimeBehavior(TInfo->getTypeLoc().getBeginLoc(), E,

compiler-rt/test/builtins/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ foreach(arch ${BUILTIN_TEST_ARCH})
5656
string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
5757
endif()
5858
else()
59-
if (${arch} MATCHES "arm|armhf|aarch64|arm64|i?86|x86_64|AMD64|riscv32|riscv64" AND COMPILER_RT_HAS_${arch}_FLOAT16)
59+
if (${arch} MATCHES "arm|armhf|aarch64|arm64|i?86|x86_64|AMD64|riscv32|riscv64|s390x" AND COMPILER_RT_HAS_${arch}_FLOAT16)
6060
list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)
6161
string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
6262
endif()

llvm/lib/IR/RuntimeLibcalls.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
327327
setLibcallName(RTLIB::SRL_I128, nullptr);
328328
setLibcallName(RTLIB::SHL_I128, nullptr);
329329
setLibcallName(RTLIB::SRA_I128, nullptr);
330+
setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
331+
setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
330332
}
331333

332334
if (TT.isX86()) {

llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum RegisterKind {
6060
GRH32Reg,
6161
GR64Reg,
6262
GR128Reg,
63+
FP16Reg,
6364
FP32Reg,
6465
FP64Reg,
6566
FP128Reg,
@@ -356,6 +357,7 @@ class SystemZOperand : public MCParsedAsmOperand {
356357
bool isADDR32() const { return isReg(GR32Reg); }
357358
bool isADDR64() const { return isReg(GR64Reg); }
358359
bool isADDR128() const { return false; }
360+
bool isFP16() const { return isReg(FP16Reg); }
359361
bool isFP32() const { return isReg(FP32Reg); }
360362
bool isFP64() const { return isReg(FP64Reg); }
361363
bool isFP128() const { return isReg(FP128Reg); }
@@ -534,6 +536,9 @@ class SystemZAsmParser : public MCTargetAsmParser {
534536
ParseStatus parseADDR128(OperandVector &Operands) {
535537
llvm_unreachable("Shouldn't be used as an operand");
536538
}
539+
ParseStatus parseFP16(OperandVector &Operands) {
540+
return parseRegister(Operands, FP16Reg);
541+
}
537542
ParseStatus parseFP32(OperandVector &Operands) {
538543
return parseRegister(Operands, FP32Reg);
539544
}
@@ -829,6 +834,7 @@ ParseStatus SystemZAsmParser::parseRegister(OperandVector &Operands,
829834
case GR128Reg:
830835
Group = RegGR;
831836
break;
837+
case FP16Reg:
832838
case FP32Reg:
833839
case FP64Reg:
834840
case FP128Reg:
@@ -882,6 +888,7 @@ ParseStatus SystemZAsmParser::parseRegister(OperandVector &Operands,
882888
case GRH32Reg: Regs = SystemZMC::GRH32Regs; break;
883889
case GR64Reg: Regs = SystemZMC::GR64Regs; break;
884890
case GR128Reg: Regs = SystemZMC::GR128Regs; break;
891+
case FP16Reg: Regs = SystemZMC::FP16Regs; break;
885892
case FP32Reg: Regs = SystemZMC::FP32Regs; break;
886893
case FP64Reg: Regs = SystemZMC::FP64Regs; break;
887894
case FP128Reg: Regs = SystemZMC::FP128Regs; break;

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ const unsigned SystemZMC::GR128Regs[16] = {
6161
SystemZ::R12Q, 0, SystemZ::R14Q, 0
6262
};
6363

64+
const unsigned SystemZMC::FP16Regs[16] = {
65+
SystemZ::F0H, SystemZ::F1H, SystemZ::F2H, SystemZ::F3H,
66+
SystemZ::F4H, SystemZ::F5H, SystemZ::F6H, SystemZ::F7H,
67+
SystemZ::F8H, SystemZ::F9H, SystemZ::F10H, SystemZ::F11H,
68+
SystemZ::F12H, SystemZ::F13H, SystemZ::F14H, SystemZ::F15H
69+
};
70+
6471
const unsigned SystemZMC::FP32Regs[16] = {
6572
SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,
6673
SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern const unsigned GR32Regs[16];
4343
extern const unsigned GRH32Regs[16];
4444
extern const unsigned GR64Regs[16];
4545
extern const unsigned GR128Regs[16];
46+
extern const unsigned FP16Regs[16];
4647
extern const unsigned FP32Regs[16];
4748
extern const unsigned FP64Regs[16];
4849
extern const unsigned FP128Regs[16];

llvm/lib/Target/SystemZ/SystemZCallingConv.td

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ 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, f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
53+
CCIfType<[f16], CCAssignToReg<[F0H, F2H, F4H, F6H]>>,
54+
CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
5455
CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
5556

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

117118
// The first 4 float and double arguments are passed in even registers F0-F6.
118-
CCIfType<[f16, f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
119+
CCIfType<[f16], CCAssignToReg<[F0H, F2H, F4H, F6H]>>,
120+
CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
119121
CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
120122

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

0 commit comments

Comments
 (0)