[PATCH] D99734: [MIPatternMatch]: Add ICstRegMatch
Petar Avramovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 26 07:06:57 PDT 2021
Petar.Avramovic updated this revision to Diff 340512.
Petar.Avramovic added a comment.
Add unit test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99734/new/
https://reviews.llvm.org/D99734
Files:
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
Index: llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
===================================================================
--- llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -40,6 +40,17 @@
EXPECT_EQ(Cst, 42);
}
+TEST_F(AArch64GISelMITest, MatchIntConstantRegister) {
+ setUp();
+ if (!TM)
+ return;
+ auto MIBCst = B.buildConstant(LLT::scalar(64), 42);
+ Register Src0;
+ bool match = mi_match(MIBCst.getReg(0), *MRI, m_ICst(Src0));
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, MIBCst.getReg(0));
+}
+
TEST_F(AArch64GISelMITest, MatchBinaryOp) {
setUp();
if (!TM)
Index: llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -68,6 +68,22 @@
inline ConstantMatch m_ICst(int64_t &Cst) { return ConstantMatch(Cst); }
+struct ICstRegMatch {
+ Register &CR;
+ ICstRegMatch(Register &C) : CR(C) {}
+ bool match(const MachineRegisterInfo &MRI, Register Reg) {
+ if (auto MaybeCst = getConstantVRegValWithLookThrough(
+ Reg, MRI, /*LookThroughInstrs*/ true,
+ /*HandleFConstants*/ false)) {
+ CR = MaybeCst->VReg;
+ return true;
+ }
+ return false;
+ }
+};
+
+inline ICstRegMatch m_ICst(Register &Reg) { return ICstRegMatch(Reg); }
+
/// Matcher for a specific constant value.
struct SpecificConstantMatch {
int64_t RequestedVal;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99734.340512.patch
Type: text/x-patch
Size: 1560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210426/7694375c/attachment.bin>
More information about the llvm-commits
mailing list