From 7d615b50bb994842ce7d7806300ae746a8a9c697 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Thu, 27 May 2021 17:24:33 -0700 Subject: [PATCH] Include more types of opcodes in strength reduction; run hdse phase after strength reduction; mark as SR candidate only if occuring in loops --- src/mapleall/maple_me/include/me_hdse.h | 3 +++ src/mapleall/maple_me/src/me_ir.cpp | 16 ++++++++++++++-- src/mapleall/maple_me/src/me_ssa_epre.cpp | 13 +++++++++++++ src/mapleall/maple_me/src/ssa_pre.cpp | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_me/include/me_hdse.h b/src/mapleall/maple_me/include/me_hdse.h index a8434b1b63..7b9dab50f7 100644 --- a/src/mapleall/maple_me/include/me_hdse.h +++ b/src/mapleall/maple_me/include/me_hdse.h @@ -31,6 +31,9 @@ class MeHDSE : public HDSE { virtual ~MeHDSE() = default; void BackwardSubstitution(); + std::string PhaseName() const { + return "hdse"; + } }; class MeDoHDSE : public MeFuncPhase { diff --git a/src/mapleall/maple_me/src/me_ir.cpp b/src/mapleall/maple_me/src/me_ir.cpp index c257bf5317..87d89bd04e 100644 --- a/src/mapleall/maple_me/src/me_ir.cpp +++ b/src/mapleall/maple_me/src/me_ir.cpp @@ -568,14 +568,26 @@ MeExpr *OpMeExpr::GetIdenticalExpr(MeExpr &expr, bool isConstructor) const { } bool OpMeExpr::StrengthReducible() { - if (op != OP_mul || !IsPrimitiveInteger(primType)) { + if (!IsPrimitiveInteger(primType)) { return false; } - return GetOpnd(1)->GetOp() == OP_constval; + switch (op) { + case OP_cvt: { + return IsPrimitiveInteger(opndType) && GetPrimTypeSize(primType) >= GetPrimTypeSize(opndType); + } + case OP_mul: + return GetOpnd(1)->GetOp() == OP_constval; + case OP_add: + return true; + default: return false; + } } int64 OpMeExpr::SRMultiplier() { ASSERT(StrengthReducible(), "OpMeExpr::SRMultiplier: operation is not strength reducible"); + if (op != OP_mul) { + return 1; + } MIRConst *constVal = static_cast(GetOpnd(1))->GetConstVal(); ASSERT(constVal->GetKind() == kConstInt, "OpMeExpr::SRMultiplier: multiplier not an integer constant"); return static_cast(constVal)->GetValueUnderType(); diff --git a/src/mapleall/maple_me/src/me_ssa_epre.cpp b/src/mapleall/maple_me/src/me_ssa_epre.cpp index 737ea7ee76..a7badd23c1 100644 --- a/src/mapleall/maple_me/src/me_ssa_epre.cpp +++ b/src/mapleall/maple_me/src/me_ssa_epre.cpp @@ -16,6 +16,8 @@ #include "me_dominance.h" #include "me_ssa_update.h" #include "me_placement_rc.h" +#include "me_loop_analysis.h" +#include "me_hdse.h" namespace { const std::set propWhiteList { @@ -74,6 +76,9 @@ AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); CHECK_FATAL(kh != nullptr, "KlassHierarchy phase has problem"); } + auto *identLoops = static_cast(m->GetAnalysisResult(MeFuncPhase_MELOOP, func)); + CHECK_NULL_FATAL(identLoops); + bool eprePULimitSpecified = MeOption::eprePULimit != UINT32_MAX; uint32 epreLimitUsed = (eprePULimitSpecified && puCount != MeOption::eprePULimit) ? UINT32_MAX : MeOption::epreLimit; @@ -109,6 +114,14 @@ AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes placeRC.preKind = MeSSUPre::kSecondDecrefPre; placeRC.ApplySSUPre(); } + if (MeOption::strengthReduction) { // for deleting redundant injury repairs + MeHDSE hdse(*func, *dom, *func->GetIRMap(), DEBUGFUNC(func)); + if (!MeOption::quiet) { + LogInfo::MapleLogger() << " == " << PhaseName() << " invokes [ " << hdse.PhaseName() << " ] ==\n"; + } + hdse.hdseKeepRef = MeOption::dseKeepRef; + hdse.DoHDSE(); + } if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "\n============== EPRE =============" << "\n"; func->Dump(false); diff --git a/src/mapleall/maple_me/src/ssa_pre.cpp b/src/mapleall/maple_me/src/ssa_pre.cpp index db02549cf7..41036e7273 100644 --- a/src/mapleall/maple_me/src/ssa_pre.cpp +++ b/src/mapleall/maple_me/src/ssa_pre.cpp @@ -1322,7 +1322,7 @@ MeRealOcc *SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bo MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fldPair.first); bool isFinal = fldPair.second.GetAttr(FLDATTR_final); wkCand->SetNeedLocalRefVar(ty->GetPrimType() == PTY_ref && !isFinal); - } else if (strengthReduction && meExpr.StrengthReducible()) { + } else if (strengthReduction && meExpr.StrengthReducible() && meStmt.GetBB()->GetAttributes(kBBAttrIsInLoop)) { wkCand->isSRCand = true; } workList.push_back(wkCand); -- Gitee