summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-01-05 09:14:53 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-01-05 09:14:53 +0000
commita2a28517f1d1fe41b6509e817f3e5a3a24c1bede (patch)
treec50f0c83a1de01f090d21d2ed450e4380029556a /unittests
parent9005d2a842ff72a02e2e1283ca8c9352544d0c2d (diff)
downloadllvm-a2a28517f1d1fe41b6509e817f3e5a3a24c1bede.tar.gz
llvm-a2a28517f1d1fe41b6509e817f3e5a3a24c1bede.tar.bz2
llvm-a2a28517f1d1fe41b6509e817f3e5a3a24c1bede.tar.xz
Add in a unittest for the one-use pattern matcher.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198552 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/PatternMatch.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/unittests/IR/PatternMatch.cpp b/unittests/IR/PatternMatch.cpp
index 150f1657b9..985135d2db 100644
--- a/unittests/IR/PatternMatch.cpp
+++ b/unittests/IR/PatternMatch.cpp
@@ -45,6 +45,26 @@ struct PatternMatchTest : ::testing::Test {
BB(BasicBlock::Create(Ctx, "entry", F)), IRB(BB) {}
};
+TEST_F(PatternMatchTest, OneUse) {
+ // Build up a little tree of values:
+ //
+ // One = (1 + 2) + 42
+ // Two = One + 42
+ // Leaf = (Two + 8) + (Two + 13)
+ Value *One = IRB.CreateAdd(IRB.CreateAdd(IRB.getInt32(1), IRB.getInt32(2)),
+ IRB.getInt32(42));
+ Value *Two = IRB.CreateAdd(One, IRB.getInt32(42));
+ Value *Leaf = IRB.CreateAdd(IRB.CreateAdd(Two, IRB.getInt32(8)),
+ IRB.CreateAdd(Two, IRB.getInt32(13)));
+ Value *V;
+
+ EXPECT_TRUE(m_OneUse(m_Value(V)).match(One));
+ EXPECT_EQ(One, V);
+
+ EXPECT_FALSE(m_OneUse(m_Value()).match(Two));
+ EXPECT_FALSE(m_OneUse(m_Value()).match(Leaf));
+}
+
TEST_F(PatternMatchTest, FloatingPointOrderedMin) {
Type *FltTy = IRB.getFloatTy();
Value *L = ConstantFP::get(FltTy, 1.0);