-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MIPatternMatch] Fix incorrect argument type of m_Type #121074
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
[MIPatternMatch] Fix incorrect argument type of m_Type #121074
Conversation
m_Type should extract the underlying value type, therefore it should take a LLT reference as its argument rather than passing by value. This is an oversight of de25647, which refactors out a good chunk of LLT reference usages. And it's just so happen that (for some reasons) no one is using m_Type and no test covered it either.
|
@llvm/pr-subscribers-llvm-globalisel Author: Min-Yih Hsu (mshockwave) Changesm_Type is supposed to extract the underlying value type (equality type comparison is covered by m_SpecificType), therefore it should take a LLT reference as its argument rather than passing by value. This is an oversight of de25647, which refactors out a good chunk of LLT reference usages. And it's just so happen that (for some reasons) no one is using m_Type and no test was covering it. Full diff: https://github.com/llvm/llvm-project/pull/121074.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
index ea6ed322e9b192..80d1fef7533c9f 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -338,7 +338,7 @@ template <> struct bind_helper<MachineInstr *> {
};
template <> struct bind_helper<LLT> {
- static bool bind(const MachineRegisterInfo &MRI, LLT Ty, Register Reg) {
+ static bool bind(const MachineRegisterInfo &MRI, LLT &Ty, Register Reg) {
Ty = MRI.getType(Reg);
if (Ty.isValid())
return true;
@@ -368,7 +368,7 @@ template <typename Class> struct bind_ty {
inline bind_ty<Register> m_Reg(Register &R) { return R; }
inline bind_ty<MachineInstr *> m_MInstr(MachineInstr *&MI) { return MI; }
-inline bind_ty<LLT> m_Type(LLT Ty) { return Ty; }
+inline bind_ty<LLT> m_Type(LLT &Ty) { return Ty; }
inline bind_ty<CmpInst::Predicate> m_Pred(CmpInst::Predicate &P) { return P; }
inline operand_type_match m_Pred() { return operand_type_match(); }
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
index 59a86fa5646f36..bcaa321e49c10c 100644
--- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -576,6 +576,11 @@ TEST_F(AArch64GISelMITest, MatchMiscellaneous) {
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
Register Reg = MIBAdd.getReg(0);
+ // Extract the type.
+ LLT Ty;
+ EXPECT_TRUE(mi_match(Reg, *MRI, m_GAdd(m_Type(Ty), m_Reg())));
+ EXPECT_EQ(Ty, s64);
+
// Only one use of Reg.
B.buildCast(LLT::pointer(0, 32), MIBAdd);
EXPECT_TRUE(mi_match(Reg, *MRI, m_OneUse(m_GAdd(m_Reg(), m_Reg()))));
|
arsenm
left a comment
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.
I don't really know what use m_Type is useful for.
I am not actively using it either (found this bug when I was adding another feature). The only uses I can think of are matching the types of pre-legalized extension/truncations |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/8250 Here is the relevant piece of the build log for the reference |
m_Type is supposed to extract the underlying value type (equality type comparison is covered by m_SpecificType), therefore it should take a LLT reference as its argument rather than passing by value.
This was originated from de25647, which refactored out a good chunk of LLT reference usages. And it's just so happen that (for some reasons) no one is using m_Type and no test was covering it.