Skip to content

Commit 110c22f

Browse files
[ExpandLargeFpConvert] Support bfloat. (#87619)
The conversion expansions did not properly handle bfloat types. I'm not certain that these expansions are completely correct; I don't have any experience with AMDGPU or the ability to run anything to test it. Note that it doesn't seem like AMDGPU with GlobalISel can handle fptrunc of float to bfloat, which is needed for itofp. I've omitted the GISEL run for the bfloat case. This fixes #85379.
1 parent eaa063f commit 110c22f

File tree

4 files changed

+979
-21
lines changed

4 files changed

+979
-21
lines changed

llvm/lib/CodeGen/ExpandLargeFpConvert.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ static void expandFPToI(Instruction *FPToI) {
116116
// fp80 conversion is implemented by fpext to fp128 first then do the
117117
// conversion.
118118
FPMantissaWidth = FPMantissaWidth == 63 ? 112 : FPMantissaWidth;
119-
unsigned FloatWidth = PowerOf2Ceil(FPMantissaWidth);
119+
unsigned FloatWidth =
120+
PowerOf2Ceil(FloatVal->getType()->getScalarSizeInBits());
120121
unsigned ExponentWidth = FloatWidth - FPMantissaWidth - 1;
121122
unsigned ExponentBias = (1 << (ExponentWidth - 1)) - 1;
122123
Value *ImplicitBit = Builder.CreateShl(
@@ -319,6 +320,7 @@ static void expandIToFP(Instruction *IToFP) {
319320
// FIXME: As there is no related builtins added in compliler-rt,
320321
// here currently utilized the fp32 <-> fp16 lib calls to implement.
321322
FPMantissaWidth = FPMantissaWidth == 10 ? 23 : FPMantissaWidth;
323+
FPMantissaWidth = FPMantissaWidth == 7 ? 23 : FPMantissaWidth;
322324
unsigned FloatWidth = PowerOf2Ceil(FPMantissaWidth);
323325
bool IsSigned = IToFP->getOpcode() == Instruction::SIToFP;
324326

@@ -547,7 +549,7 @@ static void expandIToFP(Instruction *IToFP) {
547549
Value *A40 =
548550
Builder.CreateBitCast(Or35, Type::getFP128Ty(Builder.getContext()));
549551
A4 = Builder.CreateFPTrunc(A40, IToFP->getType());
550-
} else if (IToFP->getType()->isHalfTy()) {
552+
} else if (IToFP->getType()->isHalfTy() || IToFP->getType()->isBFloatTy()) {
551553
// Deal with "half" situation. This is a workaround since we don't have
552554
// floattihf.c currently as referring.
553555
Value *A40 =

0 commit comments

Comments
 (0)