[llvm] r198552 - Add in a unittest for the one-use pattern matcher.
Chandler Carruth
chandlerc at gmail.com
Sun Jan 5 01:14:54 PST 2014
Author: chandlerc
Date: Sun Jan 5 03:14:53 2014
New Revision: 198552
URL: http://llvm.org/viewvc/llvm-project?rev=198552&view=rev
Log:
Add in a unittest for the one-use pattern matcher.
Modified:
llvm/trunk/unittests/IR/PatternMatch.cpp
Modified: llvm/trunk/unittests/IR/PatternMatch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/PatternMatch.cpp?rev=198552&r1=198551&r2=198552&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/PatternMatch.cpp (original)
+++ llvm/trunk/unittests/IR/PatternMatch.cpp Sun Jan 5 03:14:53 2014
@@ -45,6 +45,26 @@ struct PatternMatchTest : ::testing::Tes
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);
More information about the llvm-commits
mailing list