summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-09-27 21:53:04 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2019-09-27 21:53:04 +0000
commit8c39d016705e04be7dcfddae8997a36fcd0ee30d (patch)
tree23e90dfe83050aff6cf758a5a33a064209816680 /llvm/unittests/IR
parent0b1b3c6068dfacd267dded0395ef1fa262cb3f8c (diff)
downloadbcm5719-llvm-8c39d016705e04be7dcfddae8997a36fcd0ee30d.tar.gz
bcm5719-llvm-8c39d016705e04be7dcfddae8997a36fcd0ee30d.zip
[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
Diffstat (limited to 'llvm/unittests/IR')
-rw-r--r--llvm/unittests/IR/PatternMatch.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index d52d4fe980f..c2c38b73a27 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -471,6 +471,42 @@ TEST_F(PatternMatchTest, Unless) {
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) {
Value *C128 = IRB.getInt32(128);
Value *CNeg128 = ConstantExpr::getNeg(cast<Constant>(C128));
OpenPOWER on IntegriCloud