From b11140901552c2e3c4e50096ecbe1931b1324fbf Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Wed, 28 Dec 2016 13:37:17 +0000 Subject: [PATCH] [NewGVN] equals() for loads/stores is the same. Unify. Differential Revision: https://reviews.llvm.org/D28116 llvm-svn: 290667 --- llvm/lib/Transforms/Scalar/NewGVN.cpp | 36 ++++++++++----------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 6abca9177ea2..bf72a6465f8b 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -350,36 +350,26 @@ char NewGVN::ID = 0; // createGVNPass - The public interface to this file. FunctionPass *llvm::createNewGVNPass() { return new NewGVN(); } -bool LoadExpression::equals(const Expression &Other) const { - if (!isa(Other) && !isa(Other)) +template +static bool equalsLoadStoreHelper(const T &LHS, const Expression &RHS) { + if ((!isa(RHS) && !isa(RHS)) || + !LHS.BasicExpression::equals(RHS)) return false; - if (!this->BasicExpression::equals(Other)) - return false; - if (const auto *OtherL = dyn_cast(&Other)) { - if (DefiningAccess != OtherL->getDefiningAccess()) + if (const auto *L = dyn_cast(&RHS)) + if (LHS.getDefiningAccess() != L->getDefiningAccess()) return false; - } else if (const auto *OtherS = dyn_cast(&Other)) { - if (DefiningAccess != OtherS->getDefiningAccess()) + if (const auto *S = dyn_cast(&RHS)) + if (LHS.getDefiningAccess() != S->getDefiningAccess()) return false; - } - return true; } -bool StoreExpression::equals(const Expression &Other) const { - if (!isa(Other) && !isa(Other)) - return false; - if (!this->BasicExpression::equals(Other)) - return false; - if (const auto *OtherL = dyn_cast(&Other)) { - if (DefiningAccess != OtherL->getDefiningAccess()) - return false; - } else if (const auto *OtherS = dyn_cast(&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