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(Other) && !isa(Other)) - return false; - if (!this->BasicExpression::equals(Other)) +template +static bool equalsLoadStoreHelper(const T &LHS, const Expression &RHS) { + if ((!isa(RHS) && !isa(RHS)) || + !LHS.BasicExpression::equals(RHS)) 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