Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions llvm/include/llvm/CodeGen/SDPatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,27 @@ inline SpecificInt_match m_SpecificInt(uint64_t V) {
return SpecificInt_match(APInt(64, V));
}

struct SpecificFP_match {
double Val;

explicit SpecificFP_match(double V) : Val(V) {}

template <typename MatchContext>
bool match(const MatchContext &Ctx, SDValue V) {
if (const auto *CFP = dyn_cast<ConstantFPSDNode>(V.getNode()))
if (CFP->isExactlyValue(Val))
return true;
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add splat handling as well?

}
};

/// Match a specific float constant.
inline SpecificFP_match m_SpecificFP(APFloat V) {
return SpecificFP_match(V.convertToDouble());
}

inline SpecificFP_match m_SpecificFP(double V) { return SpecificFP_match(V); }

struct Zero_match {
bool AllowUndefs;

Expand Down
15 changes: 15 additions & 0 deletions llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,21 @@ TEST_F(SelectionDAGPatternMatchTest, matchBinaryOp) {
sd_match(InsertELT, m_InsertElt(m_Value(), m_Value(), m_SpecificInt(1))));
}

TEST_F(SelectionDAGPatternMatchTest, matchSpecificFpOp) {
SDLoc DL;
APFloat Value(1.5f);
auto Float32VT = EVT::getFloatingPointVT(32);
SDValue Op0 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, Float32VT);
SDValue Op1 = DAG->getConstantFP(Value, DL, Float32VT);
SDValue FAdd = DAG->getNode(ISD::FADD, DL, Float32VT, Op0, Op1);

using namespace SDPatternMatch;

EXPECT_TRUE(sd_match(Op0, m_SpecificFP(Value)));
EXPECT_TRUE(
sd_match(FAdd, m_BinOp(ISD::FADD, m_Specific(Op1), m_SpecificFP(Value))));
}

TEST_F(SelectionDAGPatternMatchTest, matchGenericTernaryOp) {
SDLoc DL;
auto Float32VT = EVT::getFloatingPointVT(32);
Expand Down
Loading