[PATCH] D28116: [NewGVN] Reduce code duplication for load/store equality
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 26 06:06:53 PST 2016
davide created this revision.
davide added a reviewer: dberlin.
davide added a subscriber: llvm-commits.
These two functions are almost exactly the same, so I decided to factor them out.
https://reviews.llvm.org/D28116
Files:
lib/Transforms/Scalar/NewGVN.cpp
Index: lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- lib/Transforms/Scalar/NewGVN.cpp
+++ lib/Transforms/Scalar/NewGVN.cpp
@@ -351,36 +351,26 @@
// createGVNPass - The public interface to this file.
FunctionPass *llvm::createNewGVNPass() { return new NewGVN(); }
-bool LoadExpression::equals(const Expression &Other) const {
- if (!isa<LoadExpression>(Other) && !isa<StoreExpression>(Other))
- return false;
- if (!this->BasicExpression::equals(Other))
+template <typename T>
+static bool equalsLoadStoreHelper(const T &LHS, const Expression &RHS) {
+ if ((!isa<LoadExpression>(RHS) && !isa<StoreExpression>(RHS)) ||
+ !LHS.BasicExpression::equals(RHS))
return false;
- if (const auto *OtherL = dyn_cast<LoadExpression>(&Other)) {
- if (DefiningAccess != OtherL->getDefiningAccess())
+ if (const auto *L = dyn_cast<LoadExpression>(&RHS))
+ if (LHS.getDefiningAccess() != L->getDefiningAccess())
return false;
- } else if (const auto *OtherS = dyn_cast<StoreExpression>(&Other)) {
- if (DefiningAccess != OtherS->getDefiningAccess())
+ if (const auto *S = dyn_cast<StoreExpression>(&RHS))
+ if (LHS.getDefiningAccess() != S->getDefiningAccess())
return false;
- }
-
return true;
}
-bool StoreExpression::equals(const Expression &Other) const {
- if (!isa<LoadExpression>(Other) && !isa<StoreExpression>(Other))
- return false;
- if (!this->BasicExpression::equals(Other))
- return false;
- if (const auto *OtherL = dyn_cast<LoadExpression>(&Other)) {
- if (DefiningAccess != OtherL->getDefiningAccess())
- return false;
- } else if (const auto *OtherS = dyn_cast<StoreExpression>(&Other)) {
- if (DefiningAccess != OtherS->getDefiningAccess())
- return false;
- }
+bool LoadExpression::equals(const Expression &Other) const {
+ return equalsLoadStoreHelper(*this, Other);
+}
- return true;
+bool StoreExpression::equals(const Expression &Other) const {
+ return equalsLoadStoreHelper(*this, Other);
}
#ifndef NDEBUG
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28116.82497.patch
Type: text/x-patch
Size: 2067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161226/4b05c1fa/attachment.bin>
More information about the llvm-commits
mailing list