[PATCH] D61979: GlobalISel: Add buildFConstant for APFloat
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 20:12:00 PDT 2019
arsenm created this revision.
arsenm added reviewers: aemerson, paquette, aditya_nandakumar.
Herald added subscribers: Petar.Avramovic, volkan, kristof.beyls, rovka, wdng.
https://reviews.llvm.org/D61979
Files:
include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
Index: unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
===================================================================
--- unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
+++ unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
@@ -19,6 +19,10 @@
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 @@
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;
Index: lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
===================================================================
--- lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -369,6 +369,13 @@
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");
Index: include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
+++ include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
@@ -653,6 +653,7 @@
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
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61979.199721.patch
Type: text/x-patch
Size: 2345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/e99c6945/attachment.bin>
More information about the llvm-commits
mailing list