Skip to content

Commit 116db1f

Browse files
toppercarsenm
authored andcommitted
[RISCV][GISel] Support fptoi and itofp for Zfh. (#96707)
1 parent eb0a391 commit 116db1f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,19 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
423423
.legalIf(typeIsScalarFPArith(0, ST))
424424
.lowerFor({s32, s64});
425425

426-
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
427-
.legalIf(all(typeInSet(0, {s32, sXLen}), typeIsScalarFPArith(1, ST)))
428-
.widenScalarToNextPow2(0)
429-
.clampScalar(0, s32, sXLen)
430-
.libcall();
426+
auto &FPToIActions =
427+
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
428+
.legalIf(all(typeInSet(0, {s32, sXLen}), typeIsScalarFPArith(1, ST)));
429+
if (ST.hasStdExtZfh())
430+
FPToIActions.legalFor({{s32, s16}, {sXLen, s16}});
431+
FPToIActions.widenScalarToNextPow2(0).clampScalar(0, s32, sXLen).libcall();
431432

432-
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
433-
.legalIf(all(typeIsScalarFPArith(0, ST), typeInSet(1, {s32, sXLen})))
434-
.widenScalarToNextPow2(1)
435-
.clampScalar(1, s32, sXLen);
433+
auto &IToFPActions =
434+
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
435+
.legalIf(all(typeIsScalarFPArith(0, ST), typeInSet(1, {s32, sXLen})));
436+
if (ST.hasStdExtZfh())
437+
IToFPActions.legalFor({{s16, s32}, {s16, sXLen}});
438+
IToFPActions.widenScalarToNextPow2(1).clampScalar(1, s32, sXLen);
436439

437440
// FIXME: We can do custom inline expansion like SelectionDAG.
438441
// FIXME: Legal with Zfa.

0 commit comments

Comments
 (0)