From 6f881c8a01b91c5b834ce0a7ca89699b4dd7a818 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Thu, 10 Feb 2022 09:18:58 -0800 Subject: [PATCH] For temporaries introduced to store IV's initial value, limit its copy propagation to avoid creating big expr trees which could prevent raising while to doloop --- src/mapleall/maple_ir/src/mir_type.cpp | 2 +- src/mapleall/maple_me/include/orig_symbol.h | 1 + src/mapleall/maple_me/src/lfo_iv_canon.cpp | 1 + src/mapleall/maple_me/src/prop.cpp | 6 +++++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_ir/src/mir_type.cpp b/src/mapleall/maple_ir/src/mir_type.cpp index 10e20ecabb..0de4963d21 100644 --- a/src/mapleall/maple_ir/src/mir_type.cpp +++ b/src/mapleall/maple_ir/src/mir_type.cpp @@ -1569,7 +1569,7 @@ int64 MIRArrayType::GetBitOffsetFromArrayAddress(std::vector &indexArray) } elemsize = RoundUp(elemsize, typeAttrs.GetAlign()); constexpr int64 bitsPerByte = 8; - int64 offset = sum * static_cast(elemsize) * bitsPerByte; + int64 offset = static_cast(sum) * elemsize * static_cast(bitsPerByte); if (GetElemType()->GetKind() == kTypeArray && indexArray.size() > dim) { std::vector subIndexArray(indexArray.begin() + dim, indexArray.end()); offset += static_cast(GetElemType())->GetBitOffsetFromArrayAddress(subIndexArray); diff --git a/src/mapleall/maple_me/include/orig_symbol.h b/src/mapleall/maple_me/include/orig_symbol.h index d79af85c19..1bc285a04a 100644 --- a/src/mapleall/maple_me/include/orig_symbol.h +++ b/src/mapleall/maple_me/include/orig_symbol.h @@ -323,6 +323,7 @@ class OriginalSt { bool epreLocalRefVar = false; // is a localrefvar temp created by epre phase public: bool isPtrWithIncDec = false; // is a pointer with self-increment/decrement + bool storesIVInitValue = false; // temp created to store IV's initial value private: SymOrPreg symOrPreg; PUIdx puIdx; diff --git a/src/mapleall/maple_me/src/lfo_iv_canon.cpp b/src/mapleall/maple_me/src/lfo_iv_canon.cpp index 8a19db1990..37f4f80320 100644 --- a/src/mapleall/maple_me/src/lfo_iv_canon.cpp +++ b/src/mapleall/maple_me/src/lfo_iv_canon.cpp @@ -375,6 +375,7 @@ void IVCanon::CanonEntryValues() { initName.append(".init"); GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(initName); ScalarMeExpr *scalarMeExpr = func->GetIRMap()->CreateNewVar(strIdx, ivdesc->primType, false); + scalarMeExpr->GetOst()->storesIVInitValue = true; #else // create preg ScalarMeExpr *scalarmeexpr = func->irMap->CreateRegMeExpr(ivdesc->primType); #endif diff --git a/src/mapleall/maple_me/src/prop.cpp b/src/mapleall/maple_me/src/prop.cpp index 85bff5ced6..2a4bb199d9 100644 --- a/src/mapleall/maple_me/src/prop.cpp +++ b/src/mapleall/maple_me/src/prop.cpp @@ -645,7 +645,11 @@ MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) { DassignMeStmt *defStmt = static_cast(varMeExpr.GetDefStmt()); ASSERT(defStmt != nullptr, "dynamic cast result is nullptr"); MeExpr *rhs = defStmt->GetRHS(); - if (rhs->GetDepth() > kPropTreeLevel) { + uint32 treeLevelLimitUsed = kPropTreeLevel; + if (varMeExpr.GetOst()->storesIVInitValue) { + treeLevelLimitUsed = treeLevelLimitUsed >> 2; + } + if (rhs->GetDepth() > treeLevelLimitUsed) { return varMeExpr; } if (rhs->GetOp() == OP_select) { -- Gitee