1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

GlobalISel: support legalization of G_FCONSTANTs

llvm-svn: 279341
This commit is contained in:
Tim Northover 2016-08-19 22:40:08 +00:00
parent d06212d835
commit 4b401c9e91
5 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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,

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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
...