Skip to content

Commit 5f97537

Browse files
Add G_FPTRUNC_ODD to generic opcodes & check legality before emitting G_FPTRUNC_ODD
1 parent a5635b7 commit 5f97537

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

llvm/docs/GlobalISel/GenericOpcode.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ G_FPTRUNC
536536

537537
Convert a floating point value to a narrower type.
538538

539+
G_FPTRUNC_ODD
540+
^^^^^^^^^^^^^
541+
542+
Convert a floating point value to a narrower type using round-to-odd rounding
543+
mode.
544+
539545
G_FPTOSI, G_FPTOUI, G_SITOFP, G_UITOFP
540546
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
541547

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8489,27 +8489,24 @@ LegalizerHelper::lowerFPTRUNC_F64_TO_F16(MachineInstr &MI) {
84898489
MRI.getType(Src).getScalarType() == LLT::scalar(64));
84908490

84918491
if (MRI.getType(Src).isVector()) {
8492-
Register Dst = MI.getOperand(0).getReg();
8493-
Register Src = MI.getOperand(1).getReg();
8494-
LLT DstTy = MRI.getType(Dst);
84958492
LLT SrcTy = MRI.getType(Src);
84968493

84978494
LLT MidTy = LLT::fixed_vector(SrcTy.getNumElements(), LLT::scalar(32));
84988495

8499-
MachineInstrBuilder Mid;
8500-
MachineInstrBuilder Fin;
8501-
MIRBuilder.setInstrAndDebugLoc(MI);
8502-
switch (MI.getOpcode()) {
8503-
default:
8496+
// Check if G_FPTRUNC_ODD has been added to the legalizer and the resultant
8497+
// types can be legalized.
8498+
auto LegalizeAction =
8499+
LI.getAction({TargetOpcode::G_FPTRUNC_ODD, {MidTy, SrcTy}}).Action;
8500+
8501+
if (LegalizeAction == LegalizeActions::Unsupported ||
8502+
LegalizeAction == LegalizeActions::NotFound)
85048503
return UnableToLegalize;
8505-
case TargetOpcode::G_FPTRUNC: {
8506-
Mid = MIRBuilder.buildFPTruncOdd(MidTy, Src);
8507-
Fin = MIRBuilder.buildFPTrunc(DstTy, Mid.getReg(0));
8508-
break;
8509-
}
8510-
}
85118504

8512-
MRI.replaceRegWith(Dst, Fin.getReg(0));
8505+
MIRBuilder.setInstrAndDebugLoc(MI);
8506+
8507+
MachineInstrBuilder Mid = MIRBuilder.buildFPTruncOdd(MidTy, Src);
8508+
MIRBuilder.buildFPTrunc(Dst, Mid.getReg(0));
8509+
85138510
MI.eraseFromParent();
85148511
return Legalized;
85158512
}

0 commit comments

Comments
 (0)