GlobalISel: Add buildFConstant for APFloat

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360853 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault 2019-05-16 04:09:06 +00:00
parent 786b357990
commit 974b6989da
3 changed files with 13 additions and 0 deletions

View File

@ -632,6 +632,7 @@ public:
const ConstantFP &Val);
MachineInstrBuilder buildFConstant(const DstOp &Res, double Val);
MachineInstrBuilder buildFConstant(const DstOp &Res, const APFloat &Val);
/// Build and insert \p Res = COPY Op
///

View File

@ -312,6 +312,13 @@ MachineInstrBuilder MachineIRBuilder::buildFConstant(const DstOp &Res,
return buildFConstant(Res, *CFP);
}
MachineInstrBuilder MachineIRBuilder::buildFConstant(const DstOp &Res,
const APFloat &Val) {
auto &Ctx = getMF().getFunction().getContext();
auto *CFP = ConstantFP::get(Ctx, Val);
return buildFConstant(Res, *CFP);
}
MachineInstrBuilder MachineIRBuilder::buildBrCond(unsigned Tst,
MachineBasicBlock &Dest) {
assert(getMRI()->getType(Tst).isScalar() && "invalid operand type");

View File

@ -19,6 +19,10 @@ TEST_F(GISelMITest, TestBuildConstantFConstant) {
B.buildConstant(LLT::vector(2, 32), 99);
B.buildFConstant(LLT::vector(2, 32), 2.0);
// Test APFloat overload.
APFloat KVal(APFloat::IEEEdouble(), "4.0");
B.buildFConstant(LLT::scalar(64), KVal);
auto CheckStr = R"(
CHECK: [[CONST0:%[0-9]+]]:_(s32) = G_CONSTANT i32 42
CHECK: [[FCONST0:%[0-9]+]]:_(s32) = G_FCONSTANT float 1.000000e+00
@ -26,6 +30,7 @@ TEST_F(GISelMITest, TestBuildConstantFConstant) {
CHECK: [[VEC0:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[CONST1]]:_(s32), [[CONST1]]:_(s32)
CHECK: [[FCONST1:%[0-9]+]]:_(s32) = G_FCONSTANT float 2.000000e+00
CHECK: [[VEC1:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[FCONST1]]:_(s32), [[FCONST1]]:_(s32)
CHECK: [[FCONST2:%[0-9]+]]:_(s64) = G_FCONSTANT double 4.000000e+00
)";
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;