diff options
author | Min-Yih Hsu <min.hsu@sifive.com> | 2024-12-30 09:23:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-30 09:23:51 -0800 |
commit | a74f825a7acec4962bb4c172da7ed0028f7b4d44 (patch) | |
tree | 59aff730121290a578d27497e59d55c0d2530ffb /llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | |
parent | c7d237085bf9102ecf0c9105d8cc7fd94b752a3a (diff) | |
download | llvm-a74f825a7acec4962bb4c172da7ed0028f7b4d44.zip llvm-a74f825a7acec4962bb4c172da7ed0028f7b4d44.tar.gz llvm-a74f825a7acec4962bb4c172da7ed0028f7b4d44.tar.bz2 |
[MIPatternMatch] Add m_DeferredReg/Type (#121218)
This pattern does the same thing as m_SpecificReg/Type except the value
it matches against origniated from an earlier pattern in the same
mi_match expression.
This patch also changes how commutative patterns are handled: in order
to support m_DefferedReg/Type, we always have to run the LHS-pattern
before the RHS one.
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp index fc76d40..40cd055 100644 --- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -920,6 +920,36 @@ TEST_F(AArch64GISelMITest, MatchSpecificReg) { EXPECT_TRUE(mi_match(Add.getReg(0), *MRI, m_GAdd(m_SpecificReg(Reg), m_Reg()))); } +TEST_F(AArch64GISelMITest, DeferredMatching) { + setUp(); + if (!TM) + GTEST_SKIP(); + auto s64 = LLT::scalar(64); + auto s32 = LLT::scalar(32); + + auto Cst1 = B.buildConstant(s64, 42); + auto Cst2 = B.buildConstant(s64, 314); + auto Add = B.buildAdd(s64, Cst1, Cst2); + auto Sub = B.buildSub(s64, Add, Cst1); + + auto TruncAdd = B.buildTrunc(s32, Add); + auto TruncSub = B.buildTrunc(s32, Sub); + auto NarrowAdd = B.buildAdd(s32, TruncAdd, TruncSub); + + Register X; + EXPECT_TRUE(mi_match(Sub.getReg(0), *MRI, + m_GSub(m_GAdd(m_Reg(X), m_Reg()), m_DeferredReg(X)))); + LLT Ty; + EXPECT_TRUE( + mi_match(NarrowAdd.getReg(0), *MRI, + m_GAdd(m_GTrunc(m_Type(Ty)), m_GTrunc(m_DeferredType(Ty))))); + + // Test commutative. + auto Add2 = B.buildAdd(s64, Sub, Cst1); + EXPECT_TRUE(mi_match(Add2.getReg(0), *MRI, + m_GAdd(m_Reg(X), m_GSub(m_Reg(), m_DeferredReg(X))))); +} + } // namespace int main(int argc, char **argv) { |