1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[MIPatternMatch]: Add ICstRegMatch

Matches G_CONSTANT and returns its def register.

Differential Revision: https://reviews.llvm.org/D99734
This commit is contained in:
Petar Avramovic 2021-04-27 10:53:17 +02:00
parent 94c4ae8b43
commit 00669818e5
2 changed files with 27 additions and 0 deletions

View File

@ -68,6 +68,22 @@ struct ConstantMatch {
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;

View File

@ -40,6 +40,17 @@ TEST_F(AArch64GISelMITest, MatchIntConstant) {
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)