[llvm] r360853 - GlobalISel: Add buildFConstant for APFloat
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 21:09:06 PDT 2019
Author: arsenm
Date: Wed May 15 21:09:06 2019
New Revision: 360853
URL: http://llvm.org/viewvc/llvm-project?rev=360853&view=rev
Log:
GlobalISel: Add buildFConstant for APFloat
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
llvm/trunk/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h?rev=360853&r1=360852&r2=360853&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h Wed May 15 21:09:06 2019
@@ -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
///
Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp?rev=360853&r1=360852&r2=360853&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp Wed May 15 21:09:06 2019
@@ -312,6 +312,13 @@ MachineInstrBuilder MachineIRBuilder::bu
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");
Modified: llvm/trunk/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp?rev=360853&r1=360852&r2=360853&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp Wed May 15 21:09:06 2019
@@ -19,6 +19,10 @@ TEST_F(GISelMITest, TestBuildConstantFCo
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, TestBuildConstantFCo
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;
More information about the llvm-commits
mailing list