summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/PatternMatch.cpp
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2016-08-12 22:16:05 +0000
committerPete Cooper <peter_cooper@apple.com>2016-08-12 22:16:05 +0000
commitab47fa643b77923322368dc2b8f277080c988c98 (patch)
treed928a27a487910f246f3df6a8118485af1fb98e7 /llvm/unittests/IR/PatternMatch.cpp
parente78e32a443aaaba63d081faaed7e2cb881424458 (diff)
downloadbcm5719-llvm-ab47fa643b77923322368dc2b8f277080c988c98.tar.gz
bcm5719-llvm-ab47fa643b77923322368dc2b8f277080c988c98.zip
Add support to paternmatch for simple const Value cases.
Pattern match has some paths which can operate on constant instructions, but not all. This adds a version of m_value() to return const Value* and changes ICmp matching to use auto so that it can match both constant and mutable instructions. Tests also included for both mutable and constant ICmpInst matching. This will be used in a future commit to constify ValueTracking.cpp. llvm-svn: 278570
Diffstat (limited to 'llvm/unittests/IR/PatternMatch.cpp')
-rw-r--r--llvm/unittests/IR/PatternMatch.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 1121d6554db..2d1321def7e 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -295,4 +295,31 @@ TEST_F(PatternMatchTest, OverflowingBinOps) {
EXPECT_FALSE(m_NUWShl(m_Value(), m_Value()).match(IRB.CreateNUWAdd(L, R)));
}
+template <typename T> struct MutableConstTest : PatternMatchTest { };
+
+typedef ::testing::Types<std::tuple<Value*, Instruction*>,
+ std::tuple<const Value*, const Instruction *>>
+ MutableConstTestTypes;
+TYPED_TEST_CASE(MutableConstTest, MutableConstTestTypes);
+
+TYPED_TEST(MutableConstTest, ICmp) {
+ auto &IRB = PatternMatchTest::IRB;
+
+ typedef typename std::tuple_element<0, TypeParam>::type ValueType;
+ typedef typename std::tuple_element<1, TypeParam>::type InstructionType;
+
+ Value *L = IRB.getInt32(1);
+ Value *R = IRB.getInt32(2);
+ ICmpInst::Predicate Pred = ICmpInst::ICMP_UGT;
+
+ ValueType MatchL;
+ ValueType MatchR;
+ ICmpInst::Predicate MatchPred;
+
+ EXPECT_TRUE(m_ICmp(MatchPred, m_Value(MatchL), m_Value(MatchR))
+ .match((InstructionType)IRB.CreateICmp(Pred, L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+}
+
} // anonymous namespace.
OpenPOWER on IntegriCloud