aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
diff options
context:
space:
mode:
authorAbinav Puthan Purayil <abinav.puthanpurayil@amd.com>2021-11-26 16:31:37 +0530
committerAbinav Puthan Purayil <abinav.puthanpurayil@amd.com>2021-11-30 15:18:50 +0530
commitbc5dbb0baee357649c3132254ca6766b5cd6f15b (patch)
tree2ce0067b689d204bfc21ce4ff9912bf1d2d0f773 /llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
parent5d602120c3a3c175f606d6ce599cfb60239d904c (diff)
downloadllvm-bc5dbb0baee357649c3132254ca6766b5cd6f15b.zip
llvm-bc5dbb0baee357649c3132254ca6766b5cd6f15b.tar.gz
llvm-bc5dbb0baee357649c3132254ca6766b5cd6f15b.tar.bz2
[GlobalISel] Add matchers for constant splat.
This change exposes isBuildVectorConstantSplat() to the llvm namespace and uses it to implement the constant splat versions of m_SpecificICst(). CombinerHelper::matchOrShiftToFunnelShift() can now work with vector types and CombinerHelper::matchMulOBy2()'s match for a constant splat is simplified. Differential Revision: https://reviews.llvm.org/D114625
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
index da56cb2..da0aee6 100644
--- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -533,6 +533,67 @@ TEST_F(AArch64GISelMITest, MatchSpecificConstant) {
EXPECT_FALSE(mi_match(MIBAdd.getReg(1), *MRI, m_SpecificICst(42)));
}
+TEST_F(AArch64GISelMITest, MatchSpecificConstantSplat) {
+ setUp();
+ if (!TM)
+ return;
+
+ LLT s64 = LLT::scalar(64);
+ LLT v4s64 = LLT::fixed_vector(4, s64);
+
+ MachineInstrBuilder FortyTwoSplat =
+ B.buildSplatVector(v4s64, B.buildConstant(s64, 42));
+ MachineInstrBuilder FortyTwo = B.buildConstant(s64, 42);
+
+ EXPECT_TRUE(mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstSplat(42)));
+ EXPECT_FALSE(
+ mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstSplat(43)));
+ EXPECT_FALSE(mi_match(FortyTwo.getReg(0), *MRI, m_SpecificICstSplat(42)));
+
+ MachineInstrBuilder NonConstantSplat =
+ B.buildBuildVector(v4s64, {Copies[0], Copies[0], Copies[0], Copies[0]});
+
+ MachineInstrBuilder AddSplat =
+ B.buildAdd(v4s64, NonConstantSplat, FortyTwoSplat);
+ EXPECT_TRUE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstSplat(42)));
+ EXPECT_FALSE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstSplat(43)));
+ EXPECT_FALSE(mi_match(AddSplat.getReg(1), *MRI, m_SpecificICstSplat(42)));
+
+ MachineInstrBuilder Add = B.buildAdd(s64, Copies[0], FortyTwo);
+ EXPECT_FALSE(mi_match(Add.getReg(2), *MRI, m_SpecificICstSplat(42)));
+}
+
+TEST_F(AArch64GISelMITest, MatchSpecificConstantOrSplat) {
+ setUp();
+ if (!TM)
+ return;
+
+ LLT s64 = LLT::scalar(64);
+ LLT v4s64 = LLT::fixed_vector(4, s64);
+
+ MachineInstrBuilder FortyTwoSplat =
+ B.buildSplatVector(v4s64, B.buildConstant(s64, 42));
+ MachineInstrBuilder FortyTwo = B.buildConstant(s64, 42);
+
+ EXPECT_TRUE(
+ mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstOrSplat(42)));
+ EXPECT_FALSE(
+ mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstOrSplat(43)));
+ EXPECT_TRUE(mi_match(FortyTwo.getReg(0), *MRI, m_SpecificICstOrSplat(42)));
+
+ MachineInstrBuilder NonConstantSplat =
+ B.buildBuildVector(v4s64, {Copies[0], Copies[0], Copies[0], Copies[0]});
+
+ MachineInstrBuilder AddSplat =
+ B.buildAdd(v4s64, NonConstantSplat, FortyTwoSplat);
+ EXPECT_TRUE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstOrSplat(42)));
+ EXPECT_FALSE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstOrSplat(43)));
+ EXPECT_FALSE(mi_match(AddSplat.getReg(1), *MRI, m_SpecificICstOrSplat(42)));
+
+ MachineInstrBuilder Add = B.buildAdd(s64, Copies[0], FortyTwo);
+ EXPECT_TRUE(mi_match(Add.getReg(2), *MRI, m_SpecificICstOrSplat(42)));
+}
+
TEST_F(AArch64GISelMITest, MatchZeroInt) {
setUp();
if (!TM)