summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-01-05 03:28:29 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-01-05 03:28:29 +0000
commit272690897ed88b0a53538aefafd7d084b3a7243c (patch)
tree6e8366fed7759721a622f36ba0adb47754b4a647 /unittests
parentb54a0ac20ac76f845026eab8fca112d1d40927de (diff)
Add support to the pattern match library for matching NSW and NUW
instructions. I needed this for a quick experiment I was making, and while I've no idea if that will ever get committed, I didn't want to throw away the pattern match code and for anyone else to have to write it again. I've added unittests to make sure this works correctly. In fun news, this also uncovered the IRBuilder bug. Doh! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198541 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/PatternMatch.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/unittests/IR/PatternMatch.cpp b/unittests/IR/PatternMatch.cpp
index b593648bb32..150f1657b9c 100644
--- a/unittests/IR/PatternMatch.cpp
+++ b/unittests/IR/PatternMatch.cpp
@@ -201,4 +201,78 @@ TEST_F(PatternMatchTest, FloatingPointUnorderedMax) {
EXPECT_EQ(R, MatchR);
}
+TEST_F(PatternMatchTest, OverflowingBinOps) {
+ Value *L = IRB.getInt32(1);
+ Value *R = IRB.getInt32(2);
+ Value *MatchL, *MatchR;
+
+ EXPECT_TRUE(
+ m_NSWAdd(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNSWAdd(L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+ MatchL = MatchR = 0;
+ EXPECT_TRUE(
+ m_NSWSub(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNSWSub(L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+ MatchL = MatchR = 0;
+ EXPECT_TRUE(
+ m_NSWMul(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNSWMul(L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+ MatchL = MatchR = 0;
+ EXPECT_TRUE(m_NSWShl(m_Value(MatchL), m_Value(MatchR)).match(
+ IRB.CreateShl(L, R, "", /* NUW */ false, /* NSW */ true)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+
+ EXPECT_TRUE(
+ m_NUWAdd(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNUWAdd(L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+ MatchL = MatchR = 0;
+ EXPECT_TRUE(
+ m_NUWSub(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNUWSub(L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+ MatchL = MatchR = 0;
+ EXPECT_TRUE(
+ m_NUWMul(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNUWMul(L, R)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+ MatchL = MatchR = 0;
+ EXPECT_TRUE(m_NUWShl(m_Value(MatchL), m_Value(MatchR)).match(
+ IRB.CreateShl(L, R, "", /* NUW */ true, /* NSW */ false)));
+ EXPECT_EQ(L, MatchL);
+ EXPECT_EQ(R, MatchR);
+
+ EXPECT_FALSE(m_NSWAdd(m_Value(), m_Value()).match(IRB.CreateAdd(L, R)));
+ EXPECT_FALSE(m_NSWAdd(m_Value(), m_Value()).match(IRB.CreateNUWAdd(L, R)));
+ EXPECT_FALSE(m_NSWAdd(m_Value(), m_Value()).match(IRB.CreateNSWSub(L, R)));
+ EXPECT_FALSE(m_NSWSub(m_Value(), m_Value()).match(IRB.CreateSub(L, R)));
+ EXPECT_FALSE(m_NSWSub(m_Value(), m_Value()).match(IRB.CreateNUWSub(L, R)));
+ EXPECT_FALSE(m_NSWSub(m_Value(), m_Value()).match(IRB.CreateNSWAdd(L, R)));
+ EXPECT_FALSE(m_NSWMul(m_Value(), m_Value()).match(IRB.CreateMul(L, R)));
+ EXPECT_FALSE(m_NSWMul(m_Value(), m_Value()).match(IRB.CreateNUWMul(L, R)));
+ EXPECT_FALSE(m_NSWMul(m_Value(), m_Value()).match(IRB.CreateNSWAdd(L, R)));
+ EXPECT_FALSE(m_NSWShl(m_Value(), m_Value()).match(IRB.CreateShl(L, R)));
+ EXPECT_FALSE(m_NSWShl(m_Value(), m_Value()).match(
+ IRB.CreateShl(L, R, "", /* NUW */ true, /* NSW */ false)));
+ EXPECT_FALSE(m_NSWShl(m_Value(), m_Value()).match(IRB.CreateNSWAdd(L, R)));
+
+ EXPECT_FALSE(m_NUWAdd(m_Value(), m_Value()).match(IRB.CreateAdd(L, R)));
+ EXPECT_FALSE(m_NUWAdd(m_Value(), m_Value()).match(IRB.CreateNSWAdd(L, R)));
+ EXPECT_FALSE(m_NUWAdd(m_Value(), m_Value()).match(IRB.CreateNUWSub(L, R)));
+ EXPECT_FALSE(m_NUWSub(m_Value(), m_Value()).match(IRB.CreateSub(L, R)));
+ EXPECT_FALSE(m_NUWSub(m_Value(), m_Value()).match(IRB.CreateNSWSub(L, R)));
+ EXPECT_FALSE(m_NUWSub(m_Value(), m_Value()).match(IRB.CreateNUWAdd(L, R)));
+ EXPECT_FALSE(m_NUWMul(m_Value(), m_Value()).match(IRB.CreateMul(L, R)));
+ EXPECT_FALSE(m_NUWMul(m_Value(), m_Value()).match(IRB.CreateNSWMul(L, R)));
+ EXPECT_FALSE(m_NUWMul(m_Value(), m_Value()).match(IRB.CreateNUWAdd(L, R)));
+ EXPECT_FALSE(m_NUWShl(m_Value(), m_Value()).match(IRB.CreateShl(L, R)));
+ EXPECT_FALSE(m_NUWShl(m_Value(), m_Value()).match(
+ IRB.CreateShl(L, R, "", /* NUW */ false, /* NSW */ true)));
+ EXPECT_FALSE(m_NUWShl(m_Value(), m_Value()).match(IRB.CreateNUWAdd(L, R)));
+}
+
} // anonymous namespace.