Skip to content

Commit d21f300

Browse files
authored
[MIPatternMatch] Fix incorrect argument type of m_Type (#121074)
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.
1 parent 4a92c27 commit d21f300

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ template <> struct bind_helper<MachineInstr *> {
338338
};
339339

340340
template <> struct bind_helper<LLT> {
341-
static bool bind(const MachineRegisterInfo &MRI, LLT Ty, Register Reg) {
341+
static bool bind(const MachineRegisterInfo &MRI, LLT &Ty, Register Reg) {
342342
Ty = MRI.getType(Reg);
343343
if (Ty.isValid())
344344
return true;
@@ -368,7 +368,7 @@ template <typename Class> struct bind_ty {
368368

369369
inline bind_ty<Register> m_Reg(Register &R) { return R; }
370370
inline bind_ty<MachineInstr *> m_MInstr(MachineInstr *&MI) { return MI; }
371-
inline bind_ty<LLT> m_Type(LLT Ty) { return Ty; }
371+
inline bind_ty<LLT> m_Type(LLT &Ty) { return Ty; }
372372
inline bind_ty<CmpInst::Predicate> m_Pred(CmpInst::Predicate &P) { return P; }
373373
inline operand_type_match m_Pred() { return operand_type_match(); }
374374

llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ TEST_F(AArch64GISelMITest, MatchMiscellaneous) {
576576
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
577577
Register Reg = MIBAdd.getReg(0);
578578

579+
// Extract the type.
580+
LLT Ty;
581+
EXPECT_TRUE(mi_match(Reg, *MRI, m_GAdd(m_Type(Ty), m_Reg())));
582+
EXPECT_EQ(Ty, s64);
583+
579584
// Only one use of Reg.
580585
B.buildCast(LLT::pointer(0, 32), MIBAdd);
581586
EXPECT_TRUE(mi_match(Reg, *MRI, m_OneUse(m_GAdd(m_Reg(), m_Reg()))));

0 commit comments

Comments
 (0)