diff --git a/src/mapleall/maple_me/src/ssa_epre_for_sr.cpp b/src/mapleall/maple_me/src/ssa_epre_for_sr.cpp index 9882180098b4e6548c18f824b16d1cec47a0e337..cbd888c937118627fc03c435b8057eec81cdc326 100644 --- a/src/mapleall/maple_me/src/ssa_epre_for_sr.cpp +++ b/src/mapleall/maple_me/src/ssa_epre_for_sr.cpp @@ -138,7 +138,6 @@ void SSAEPre::SRSetNeedRepair(MeOccur *useocc, std::set *needRepairInj RegMeExpr *regx = static_cast(curopnd); needRepairInjuringDefs->insert(regx->GetDefStmt()); } - return; // restricted injury requirement to at most 1 operand } } } @@ -332,8 +331,6 @@ MeExpr* SSAEPre::SRRepairInjuries(MeOccur *useocc, if (!OpndInDefOcc(curopnd, defocc, i)) { repairedTemp = SRRepairOpndInjuries(curopnd, defocc, i, repairedTemp, needRepairInjuringDefs, repairedInjuringDefs); - // restricted to only 1 var or reg injured - break; } } // for return repairedTemp; diff --git a/src/mapleall/maple_me/src/ssa_pre.cpp b/src/mapleall/maple_me/src/ssa_pre.cpp index 6b7130ec198fa223ec960c142ed3719dee900b41..ea5aa2e1cd568f1fec8fb59c6c697a60998f4c67 100644 --- a/src/mapleall/maple_me/src/ssa_pre.cpp +++ b/src/mapleall/maple_me/src/ssa_pre.cpp @@ -231,6 +231,8 @@ void SSAPre::CodeMotion() { temp2LocalRefVarMap.clear(); reBuiltOccIndex = static_cast(workList.size()); // so we know the elements added due to rebuilding std::set repairedInjuringDefs; // for marking injuring defs that have been repaired + MeOccur *injuriedOcc = nullptr; + MeExpr *injuriedExpr = nullptr; for (MeOccur *occ : allOccs) { switch (occ->GetOccType()) { @@ -248,6 +250,8 @@ void SSAPre::CodeMotion() { bool isreplaced = irMap->ReplaceMeExprStmt(*realOcc->GetMeStmt(), *realOcc->GetMeExpr(), *regorvar); // update worklist if (isreplaced) { + injuriedOcc = realOcc; + injuriedExpr = regorvar; BuildWorkListStmt(*realOcc->GetMeStmt(), realOcc->GetSequence(), true, regorvar); } } @@ -269,7 +273,14 @@ void SSAPre::CodeMotion() { } else { // set phiOpnd4Temp needed in the temp's phi if (workCand->isSRCand) { + auto oldSize = repairedInjuringDefs.size(); phiOpnd->phiOpnd4Temp = SRRepairInjuries(phiOpnd, &needRepairInjuringDefs, &repairedInjuringDefs); + // the expr's version may changed after (realocc) repair injuries. if is, use the new version + if (repairedInjuringDefs.size() == oldSize && injuriedExpr != nullptr) { + if (dom->Domonate(*injuriedOcc->GetBB(), *phiOpnd->GetBB())) { + phiOpnd->phiOpnd4Temp = injuriedExpr; + } + } } else { if (defOcc->GetOccType() == kOccReal) { phiOpnd->phiOpnd4Temp = static_cast(defOcc)->GetSavedExpr();