summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/PatternMatch.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-07-25 13:34:24 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2019-07-25 13:34:24 +0000
commit9f88fef51a770bf664089e26a7feded2afb15607 (patch)
tree0013145aa440ad2f86af863e0e291014e7d4aca9 /llvm/unittests/IR/PatternMatch.cpp
parent6df3fc543303bf6755474b0c9ec669e67eef56cc (diff)
downloadbcm5719-llvm-9f88fef51a770bf664089e26a7feded2afb15607.tar.gz
bcm5719-llvm-9f88fef51a770bf664089e26a7feded2afb15607.zip
[IR][PatternMatch] Introduce m_NegatedPower2() matcher
Summary: It is a good idea to do as much matching inside of `match()` as possible. If some checking is done afterwards, and we don't fold because of it, chances are we may have missed some commutative pattern. Reviewers: spatel, craig.topper, RKSimon Reviewed By: spatel, RKSimon Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64038 llvm-svn: 367017
Diffstat (limited to 'llvm/unittests/IR/PatternMatch.cpp')
-rw-r--r--llvm/unittests/IR/PatternMatch.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 8263acb59a0..fe8c518fa82 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/IR/PatternMatch.h"
+#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
@@ -470,6 +471,26 @@ TEST_F(PatternMatchTest, Unless) {
EXPECT_FALSE(m_Unless(m_c_Add(m_Zero(), m_One())).match(X));
}
+TEST_F(PatternMatchTest, Power2) {
+ Value *C128 = IRB.getInt32(128);
+ Value *CNeg128 = ConstantExpr::getNeg(cast<Constant>(C128));
+
+ EXPECT_TRUE(m_Power2().match(C128));
+ EXPECT_FALSE(m_Power2().match(CNeg128));
+
+ EXPECT_FALSE(m_NegatedPower2().match(C128));
+ EXPECT_TRUE(m_NegatedPower2().match(CNeg128));
+
+ Value *CIntMin = IRB.getInt64(APSInt::getSignedMinValue(64).getSExtValue());
+ Value *CNegIntMin = ConstantExpr::getNeg(cast<Constant>(CIntMin));
+
+ EXPECT_TRUE(m_Power2().match(CIntMin));
+ EXPECT_TRUE(m_Power2().match(CNegIntMin));
+
+ EXPECT_TRUE(m_NegatedPower2().match(CIntMin));
+ EXPECT_TRUE(m_NegatedPower2().match(CNegIntMin));
+}
+
TEST_F(PatternMatchTest, CommutativeDeferredValue) {
Value *X = IRB.getInt32(1);
Value *Y = IRB.getInt32(2);
OpenPOWER on IntegriCloud