1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[PatternMatch] Add m_SExtOrSelf(), m_ZExtOrSExtOrSelf() matchers + unittests

m_SExtOrSelf() is for consistency.

m_ZExtOrSExtOrSelf() is motivated by the D68103/r373106 :
sometimes it is useful to look past any extensions of the shift amount,
and m_ZExtOrSExtOrSelf() may be exactly the tool to do that.

llvm-svn: 373128
This commit is contained in:
Roman Lebedev 2019-09-27 21:53:04 +00:00
parent f7a791d80b
commit 13a563c646
2 changed files with 51 additions and 0 deletions

View File

@ -1319,6 +1319,12 @@ m_ZExtOrSelf(const OpTy &Op) {
return m_CombineOr(m_ZExt(Op), Op); return m_CombineOr(m_ZExt(Op), Op);
} }
template <typename OpTy>
inline match_combine_or<CastClass_match<OpTy, Instruction::SExt>, OpTy>
m_SExtOrSelf(const OpTy &Op) {
return m_CombineOr(m_SExt(Op), Op);
}
template <typename OpTy> template <typename OpTy>
inline match_combine_or<CastClass_match<OpTy, Instruction::ZExt>, inline match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
CastClass_match<OpTy, Instruction::SExt>> CastClass_match<OpTy, Instruction::SExt>>
@ -1326,6 +1332,15 @@ m_ZExtOrSExt(const OpTy &Op) {
return m_CombineOr(m_ZExt(Op), m_SExt(Op)); return m_CombineOr(m_ZExt(Op), m_SExt(Op));
} }
template <typename OpTy>
inline match_combine_or<
match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
CastClass_match<OpTy, Instruction::SExt>>,
OpTy>
m_ZExtOrSExtOrSelf(const OpTy &Op) {
return m_CombineOr(m_ZExtOrSExt(Op), Op);
}
/// Matches UIToFP. /// Matches UIToFP.
template <typename OpTy> template <typename OpTy>
inline CastClass_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) { inline CastClass_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {

View File

@ -471,6 +471,42 @@ TEST_F(PatternMatchTest, Unless) {
EXPECT_FALSE(m_Unless(m_c_Add(m_Zero(), m_One())).match(X)); EXPECT_FALSE(m_Unless(m_c_Add(m_Zero(), m_One())).match(X));
} }
TEST_F(PatternMatchTest, ZExtSExtSelf) {
LLVMContext &Ctx = IRB.getContext();
Value *One32 = IRB.getInt32(1);
Value *One64Z = IRB.CreateZExt(One32, IntegerType::getInt64Ty(Ctx));
Value *One64S = IRB.CreateSExt(One32, IntegerType::getInt64Ty(Ctx));
EXPECT_TRUE(m_One().match(One32));
EXPECT_FALSE(m_One().match(One64Z));
EXPECT_FALSE(m_One().match(One64S));
EXPECT_FALSE(m_ZExt(m_One()).match(One32));
EXPECT_TRUE(m_ZExt(m_One()).match(One64Z));
EXPECT_FALSE(m_ZExt(m_One()).match(One64S));
EXPECT_FALSE(m_SExt(m_One()).match(One32));
EXPECT_FALSE(m_SExt(m_One()).match(One64Z));
EXPECT_TRUE(m_SExt(m_One()).match(One64S));
EXPECT_TRUE(m_ZExtOrSelf(m_One()).match(One32));
EXPECT_TRUE(m_ZExtOrSelf(m_One()).match(One64Z));
EXPECT_FALSE(m_ZExtOrSelf(m_One()).match(One64S));
EXPECT_TRUE(m_SExtOrSelf(m_One()).match(One32));
EXPECT_FALSE(m_SExtOrSelf(m_One()).match(One64Z));
EXPECT_TRUE(m_SExtOrSelf(m_One()).match(One64S));
EXPECT_FALSE(m_ZExtOrSExt(m_One()).match(One32));
EXPECT_TRUE(m_ZExtOrSExt(m_One()).match(One64Z));
EXPECT_TRUE(m_ZExtOrSExt(m_One()).match(One64S));
EXPECT_TRUE(m_ZExtOrSExtOrSelf(m_One()).match(One32));
EXPECT_TRUE(m_ZExtOrSExtOrSelf(m_One()).match(One64Z));
EXPECT_TRUE(m_ZExtOrSExtOrSelf(m_One()).match(One64S));
}
TEST_F(PatternMatchTest, Power2) { TEST_F(PatternMatchTest, Power2) {
Value *C128 = IRB.getInt32(128); Value *C128 = IRB.getInt32(128);
Value *CNeg128 = ConstantExpr::getNeg(cast<Constant>(C128)); Value *CNeg128 = ConstantExpr::getNeg(cast<Constant>(C128));