forked from OSchip/llvm-project
GlobalISel: support legalization of G_FCONSTANTs
llvm-svn: 279341
This commit is contained in:
parent
ea904f9424
commit
a11be04769
|
@ -302,6 +302,15 @@ public:
|
|||
MachineInstrBuilder buildIntrinsic(ArrayRef<LLT> Tys, Intrinsic::ID ID,
|
||||
unsigned Res, bool HasSideEffects);
|
||||
|
||||
/// Build and insert \p Res<def> = G_FPTRUNC \p Ty \p Op
|
||||
///
|
||||
/// G_FPTRUNC converts a floating-point value into one with a smaller type.
|
||||
///
|
||||
/// \pre setBasicBlock or setMI must have been called.
|
||||
///
|
||||
/// \return The newly created instruction.
|
||||
MachineInstrBuilder buildFPTrunc(LLT Ty, unsigned Res, unsigned Op);
|
||||
|
||||
/// Build and insert \p Res<def> = G_TRUNC \p Ty \p Op
|
||||
///
|
||||
/// G_TRUNC extracts the low bits of a type. For a vector type each element is
|
||||
|
|
|
@ -211,6 +211,11 @@ MachineInstrBuilder MachineIRBuilder::buildTrunc(LLT Ty, unsigned Res,
|
|||
return buildInstr(TargetOpcode::G_TRUNC, Ty).addDef(Res).addUse(Op);
|
||||
}
|
||||
|
||||
MachineInstrBuilder MachineIRBuilder::buildFPTrunc(LLT Ty, unsigned Res,
|
||||
unsigned Op) {
|
||||
return buildInstr(TargetOpcode::G_FPTRUNC, Ty).addDef(Res).addUse(Op);
|
||||
}
|
||||
|
||||
MachineInstrBuilder MachineIRBuilder::buildICmp(ArrayRef<LLT> Tys,
|
||||
CmpInst::Predicate Pred,
|
||||
unsigned Res, unsigned Op0,
|
||||
|
|
|
@ -141,6 +141,14 @@ MachineLegalizeHelper::widenScalar(MachineInstr &MI, LLT WideTy) {
|
|||
MI.eraseFromParent();
|
||||
return Legalized;
|
||||
}
|
||||
case TargetOpcode::G_FCONSTANT: {
|
||||
MIRBuilder.setInstr(MI);
|
||||
unsigned DstExt = MRI.createGenericVirtualRegister(WideSize);
|
||||
MIRBuilder.buildFConstant(WideTy, DstExt, *MI.getOperand(1).getFPImm());
|
||||
MIRBuilder.buildFPTrunc(MI.getType(), MI.getOperand(0).getReg(), DstExt);
|
||||
MI.eraseFromParent();
|
||||
return Legalized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ AArch64MachineLegalizer::AArch64MachineLegalizer() {
|
|||
for (auto Ty : {s1, s8, s16})
|
||||
setAction(TargetOpcode::G_CONSTANT, Ty, WidenScalar);
|
||||
|
||||
setAction(TargetOpcode::G_FCONSTANT, s16, WidenScalar);
|
||||
|
||||
setAction(G_BR, LLT::unsized(), Legal);
|
||||
|
||||
|
|
|
@ -53,7 +53,10 @@ body: |
|
|||
; CHECK-LABEL: name: test_fconstant
|
||||
; CHECK: %0(32) = G_FCONSTANT s32 float 1.000000e+00
|
||||
; CHECK: %1(64) = G_FCONSTANT s64 double 2.000000e+00
|
||||
; CHECK: [[TMP:%[0-9]+]](32) = G_FCONSTANT s32 half 0xH0000
|
||||
; CHECK; %2(16) = G_FPTRUNC s16 [[TMP]]
|
||||
|
||||
%0(32) = G_FCONSTANT s32 float 1.0
|
||||
%1(64) = G_FCONSTANT s64 double 2.0
|
||||
%2(16) = G_FCONSTANT s16 half 0.0
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue