Skip to content

Commit d5d1417

Browse files
authored
[RISCV][GISel] Use libcalls for rint, nearbyint, trunc, round, and roundeven intrinsics. (#108779)
1 parent 1be4c97 commit d5d1417

File tree

4 files changed

+337
-99
lines changed

4 files changed

+337
-99
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ static RTLIB::Libcall getRTLibDesc(unsigned Opcode, unsigned Size) {
485485
RTLIBCASE(RINT_F);
486486
case TargetOpcode::G_FNEARBYINT:
487487
RTLIBCASE(NEARBYINT_F);
488+
case TargetOpcode::G_INTRINSIC_TRUNC:
489+
RTLIBCASE(TRUNC_F);
490+
case TargetOpcode::G_INTRINSIC_ROUND:
491+
RTLIBCASE(ROUND_F);
488492
case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
489493
RTLIBCASE(ROUNDEVEN_F);
490494
case TargetOpcode::G_INTRINSIC_LRINT:
@@ -1215,6 +1219,8 @@ LegalizerHelper::libcall(MachineInstr &MI, LostDebugLocObserver &LocObserver) {
12151219
case TargetOpcode::G_FSQRT:
12161220
case TargetOpcode::G_FRINT:
12171221
case TargetOpcode::G_FNEARBYINT:
1222+
case TargetOpcode::G_INTRINSIC_TRUNC:
1223+
case TargetOpcode::G_INTRINSIC_ROUND:
12181224
case TargetOpcode::G_INTRINSIC_ROUNDEVEN: {
12191225
LLT LLTy = MRI.getType(MI.getOperand(0).getReg());
12201226
unsigned Size = LLTy.getSizeInBits();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
541541

542542
// FIXME: We can do custom inline expansion like SelectionDAG.
543543
// FIXME: Legal with Zfa.
544-
getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR})
544+
getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR, G_FRINT, G_FNEARBYINT,
545+
G_INTRINSIC_TRUNC, G_INTRINSIC_ROUND,
546+
G_INTRINSIC_ROUNDEVEN})
545547
.libcallFor({s32, s64});
546548

547549
getActionDefinitionsBuilder(G_VASTART).customFor({p0});

llvm/test/CodeGen/RISCV/GlobalISel/legalizer/legalize-fp-ceil-floor.mir

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)