Skip to content

Commit

Permalink
[ExpandLargeFpConvert] Support bfloat. (#87619)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bevin-hansson committed Apr 8, 2024
1 parent eaa063f commit 110c22f
Show file tree
Hide file tree
Showing 4 changed files with 979 additions and 21 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/ExpandLargeFpConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ static void expandFPToI(Instruction *FPToI) {
// fp80 conversion is implemented by fpext to fp128 first then do the
// conversion.
FPMantissaWidth = FPMantissaWidth == 63 ? 112 : FPMantissaWidth;
unsigned FloatWidth = PowerOf2Ceil(FPMantissaWidth);
unsigned FloatWidth =
PowerOf2Ceil(FloatVal->getType()->getScalarSizeInBits());
unsigned ExponentWidth = FloatWidth - FPMantissaWidth - 1;
unsigned ExponentBias = (1 << (ExponentWidth - 1)) - 1;
Value *ImplicitBit = Builder.CreateShl(
Expand Down Expand Up @@ -319,6 +320,7 @@ static void expandIToFP(Instruction *IToFP) {
// FIXME: As there is no related builtins added in compliler-rt,
// here currently utilized the fp32 <-> fp16 lib calls to implement.
FPMantissaWidth = FPMantissaWidth == 10 ? 23 : FPMantissaWidth;
FPMantissaWidth = FPMantissaWidth == 7 ? 23 : FPMantissaWidth;
unsigned FloatWidth = PowerOf2Ceil(FPMantissaWidth);
bool IsSigned = IToFP->getOpcode() == Instruction::SIToFP;

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

0 comments on commit 110c22f

Please sign in to comment.