-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SDPatternMatch] Add Matcher m_Undef #122521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-selectiondag Author: Amr Hesham (AmrDeveloper) ChangesAdd Matcher Fixes: 122439 Full diff: https://github.com/llvm/llvm-project/pull/122521.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index fc8ef717c74f6a..a2495267ee3526 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -138,6 +138,8 @@ struct Opcode_match {
inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); }
+inline Opcode_match m_Undef() { return Opcode_match(ISD::UNDEF); }
+
template <unsigned NumUses, typename Pattern> struct NUses_match {
Pattern P;
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index a2e1e588d03dea..bd6420b43cef7c 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -603,3 +603,18 @@ TEST_F(SelectionDAGPatternMatchTest, matchAdvancedProperties) {
EXPECT_TRUE(sd_match(Add, DAG.get(),
m_LegalOp(m_IntegerVT(m_Add(m_Value(), m_Value())))));
}
+
+TEST_F(SelectionDAGPatternMatchTest, matchUndefined) {
+ auto BoolVT = EVT::getIntegerVT(Context, 1);
+ auto Int32VT = EVT::getIntegerVT(Context, 32);
+ auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
+
+ SDValue UndefBoolVT = DAG->getUNDEF(BoolVT);
+ SDValue UndefInt32VT= DAG->getUNDEF(Int32VT);
+ SDValue UndefVInt32VT = DAG->getUNDEF(VInt32VT);
+
+ using namespace SDPatternMatch;
+ EXPECT_TRUE(sd_match(UndefBoolVT, m_Undef()));
+ EXPECT_TRUE(sd_match(UndefInt32VT, m_Undef()));
+ EXPECT_TRUE(sd_match(UndefVInt32VT, m_Undef()));
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
@RKSimon can you suggest a pattern to use this with? I think it would be better to land this with a real use, rather than having it only be used by the UnitTest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM w/ a minor comment
@@ -603,3 +603,18 @@ TEST_F(SelectionDAGPatternMatchTest, matchAdvancedProperties) { | |||
EXPECT_TRUE(sd_match(Add, DAG.get(), | |||
m_LegalOp(m_IntegerVT(m_Add(m_Value(), m_Value()))))); | |||
} | |||
|
|||
TEST_F(SelectionDAGPatternMatchTest, matchUndefined) { | |||
auto BoolVT = EVT::getIntegerVT(Context, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could you put tests in matchConstants instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I know RISC-V's vector ops use undef for its passthrough operand in cases where we don't have or don't care about masks. It would be useful to match those cases. |
f61b976
to
b3d8f5c
Compare
I mentioned the use case on #122439 - the place I hit this was I wanted to match the pattern below and it annoyed me as using m_Opc(ISD::UNDEF) broke the col80 limit:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - cheers!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/11822 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/5573 Here is the relevant piece of the build log for the reference
|
Add Matcher `m_Undef` Fixes: llvm#122439
Add Matcher
m_Undef
Fixes: #122439