Skip to content

Commit ee4ae7b

Browse files
committed
[Z80] Legalize G_FFREXP/G_FLDEXP for {s64,s24}
1 parent 6720b48 commit ee4ae7b

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

llvm/lib/Target/Z80/GISel/Z80LegalizerInfo.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ Z80LegalizerInfo::Z80LegalizerInfo(const Z80Subtarget &STI,
328328

329329
getActionDefinitionsBuilder(G_FCOPYSIGN).libcallFor({{s32, s32}, {s64, s64}});
330330

331-
getActionDefinitionsBuilder(G_FFREXP).customFor({{s32, s24}});
331+
getActionDefinitionsBuilder(G_FFREXP).customFor({{s32, s24}, {s64, s24}});
332332

333-
getActionDefinitionsBuilder(G_FLDEXP).customFor({{s32, s24}});
333+
getActionDefinitionsBuilder(G_FLDEXP).customFor({{s32, s24}, {s64, s24}});
334334

335335
getActionDefinitionsBuilder({G_LOAD, G_STORE})
336336
.legalForCartesianProduct(LegalTypes, {p[0]})
@@ -1441,11 +1441,21 @@ Z80LegalizerInfo::legalizeFFrexp(LegalizerHelper &Helper,
14411441

14421442
LLT MantTy = MRI.getType(DstMantReg);
14431443
LLT ExpTy = MRI.getType(DstExpReg);
1444-
if (MantTy != LLT::scalar(32) || ExpTy != LLT::scalar(24))
1444+
if (ExpTy != LLT::scalar(24))
14451445
return LegalizerHelper::UnableToLegalize;
14461446

14471447
LLVMContext &Ctx = MIRBuilder.getMF().getFunction().getContext();
1448-
Type *MantIRTy = Type::getFloatTy(Ctx);
1448+
Type *MantIRTy = nullptr;
1449+
RTLIB::Libcall Libcall;
1450+
if (MantTy == LLT::scalar(32)) {
1451+
MantIRTy = Type::getFloatTy(Ctx);
1452+
Libcall = RTLIB::FREXP_F32;
1453+
} else if (MantTy == LLT::scalar(64)) {
1454+
MantIRTy = Type::getDoubleTy(Ctx);
1455+
Libcall = RTLIB::FREXP_F64;
1456+
} else {
1457+
return LegalizerHelper::UnableToLegalize;
1458+
}
14491459
Type *PtrIRTy = PointerType::get(Ctx, 0);
14501460

14511461
MachineFunction &MF = MIRBuilder.getMF();
@@ -1457,9 +1467,9 @@ Z80LegalizerInfo::legalizeFFrexp(LegalizerHelper &Helper,
14571467
.buildFrameIndex(LLT::pointer(0, TM.getPointerSizeInBits(0)), ExpFI)
14581468
.getReg(0);
14591469

1460-
auto CallResult = createLibcall(
1461-
MIRBuilder, RTLIB::FREXP_F32, {DstMantReg, MantIRTy, 0},
1462-
{{SrcReg, MantIRTy, 0}, {ExpAddr, PtrIRTy, 1}});
1470+
auto CallResult =
1471+
createLibcall(MIRBuilder, Libcall, {DstMantReg, MantIRTy, 0},
1472+
{{SrcReg, MantIRTy, 0}, {ExpAddr, PtrIRTy, 1}});
14631473
if (CallResult != LegalizerHelper::Legalized)
14641474
return CallResult;
14651475

@@ -1485,16 +1495,26 @@ Z80LegalizerInfo::legalizeFLdexp(LegalizerHelper &Helper,
14851495

14861496
LLT DstTy = MRI.getType(DstReg);
14871497
LLT ExpTy = MRI.getType(ExpReg);
1488-
if (DstTy != LLT::scalar(32) || ExpTy != LLT::scalar(24))
1498+
if (ExpTy != LLT::scalar(24))
14891499
return LegalizerHelper::UnableToLegalize;
14901500

14911501
LLVMContext &Ctx = MIRBuilder.getMF().getFunction().getContext();
1492-
Type *FloatTy = Type::getFloatTy(Ctx);
1502+
Type *FloatTy = nullptr;
1503+
RTLIB::Libcall Libcall;
1504+
if (DstTy == LLT::scalar(32)) {
1505+
FloatTy = Type::getFloatTy(Ctx);
1506+
Libcall = RTLIB::LDEXP_F32;
1507+
} else if (DstTy == LLT::scalar(64)) {
1508+
FloatTy = Type::getDoubleTy(Ctx);
1509+
Libcall = RTLIB::LDEXP_F64;
1510+
} else {
1511+
return LegalizerHelper::UnableToLegalize;
1512+
}
14931513
Type *ExpIRTy = IntegerType::get(Ctx, 24);
14941514

1495-
auto CallResult = createLibcall(
1496-
MIRBuilder, RTLIB::LDEXP_F32, {DstReg, FloatTy, 0},
1497-
{{SrcReg, FloatTy, 0}, {ExpReg, ExpIRTy, 1}});
1515+
auto CallResult =
1516+
createLibcall(MIRBuilder, Libcall, {DstReg, FloatTy, 0},
1517+
{{SrcReg, FloatTy, 0}, {ExpReg, ExpIRTy, 1}});
14981518
if (CallResult != LegalizerHelper::Legalized)
14991519
return CallResult;
15001520

0 commit comments

Comments
 (0)