diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index 0793a28f5f5f99bc813314399d6b966540221c9a..b490c2bb20f84741f67d4973b0c7e879f10f3270 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -728,6 +728,7 @@ class AddroflabelMeExpr : public MeExpr { return true; } BaseNode &EmitExpr(SSATab&) override; + MeExpr *GetIdenticalExpr(MeExpr &expr, bool) const override; uint32 GetHashIndex() const override { constexpr uint32 shiftNum = 4; diff --git a/src/mapleall/maple_me/include/orig_symbol.h b/src/mapleall/maple_me/include/orig_symbol.h index bc8e44be3564c076db23757fb5c7e8fc3582e468..5bd56dcabbdc8e0ac9abd5737d38f30ec2226d9a 100644 --- a/src/mapleall/maple_me/include/orig_symbol.h +++ b/src/mapleall/maple_me/include/orig_symbol.h @@ -407,6 +407,7 @@ class OriginalStTable { // mir symbol to original table, this only exists for no-original variables. public: MapleUnorderedMap mirSt2Ost; + MapleUnorderedMap addrofSt2Ost; private: MapleUnorderedMap preg2Ost; // mir type to virtual variables in original table. this only exists for no-original variables. diff --git a/src/mapleall/maple_me/src/me_ir.cpp b/src/mapleall/maple_me/src/me_ir.cpp index 9c7209b8a03dab3ab8f7c0da3d7c0785e1a98fde..8a1c3d7094a9c19f1ce47b96f9b66cf5b0f5be6a 100644 --- a/src/mapleall/maple_me/src/me_ir.cpp +++ b/src/mapleall/maple_me/src/me_ir.cpp @@ -754,6 +754,20 @@ MeExpr *AddroffuncMeExpr::GetIdenticalExpr(MeExpr &expr, bool isConstructor) con return nullptr; } +MeExpr *AddroflabelMeExpr::GetIdenticalExpr(MeExpr &expr, bool isConstructor) const { + (void)isConstructor; + auto *addroflabelExpr = static_cast(&expr); + + while (addroflabelExpr != nullptr) { + if (addroflabelExpr->GetMeOp() == kMeOpAddroflabel && addroflabelExpr->labelIdx == labelIdx) { + return addroflabelExpr; + } + addroflabelExpr = static_cast(addroflabelExpr->GetNext()); + } + + return nullptr; +} + void MePhiNode::Dump(const IRMap *irMap) const { const OriginalSt *ost = lhs->GetOst(); bool isSym = ost->IsSymbolOst(); diff --git a/src/mapleall/maple_me/src/orig_symbol.cpp b/src/mapleall/maple_me/src/orig_symbol.cpp index 19ddeaaf7451f5162f23020bfc114d42739989d6..b46deb45c249d9171a61c35babbe8546e751eb54 100644 --- a/src/mapleall/maple_me/src/orig_symbol.cpp +++ b/src/mapleall/maple_me/src/orig_symbol.cpp @@ -55,6 +55,7 @@ OriginalStTable::OriginalStTable(MemPool &memPool, MIRModule &mod) mirModule(mod), originalStVector({ nullptr }, alloc.Adapter()), mirSt2Ost(alloc.Adapter()), + addrofSt2Ost(alloc.Adapter()), preg2Ost(alloc.Adapter()), pType2Ost(std::less(), alloc.Adapter()), malloc2Ost(alloc.Adapter()), @@ -155,15 +156,22 @@ OriginalSt *OriginalStTable::FindOrCreateAddrofSymbolOriginalSt(OriginalSt *ost) if (ost->GetPrevLevelOst() != nullptr) { return ost->GetPrevLevelOst(); } - // create a new node - OriginalSt *prevLevelOst = alloc.GetMemPool()->New( - originalStVector.size(), *ost->GetMIRSymbol(), ost->GetPuIdx(), 0, alloc); - originalStVector.push_back(prevLevelOst); - prevLevelOst->SetIndirectLev(-1); - MIRPtrType pointType(ost->GetMIRSymbol()->GetTyIdx(), PTY_ptr); - TyIdx newTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&pointType); - prevLevelOst->SetTyIdx(newTyIdx); - prevLevelOst->SetFieldID(0); + OriginalSt *prevLevelOst = nullptr; + auto it = addrofSt2Ost.find(ost->GetMIRSymbol()->GetStIndex()); + if (it != addrofSt2Ost.end()) { + prevLevelOst = originalStVector[it->second]; + } else { + // create a new node + prevLevelOst = alloc.GetMemPool()->New( + originalStVector.size(), *ost->GetMIRSymbol(), ost->GetPuIdx(), 0, alloc); + originalStVector.push_back(prevLevelOst); + prevLevelOst->SetIndirectLev(-1); + MIRPtrType pointType(ost->GetMIRSymbol()->GetTyIdx(), PTY_ptr); + TyIdx newTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&pointType); + prevLevelOst->SetTyIdx(newTyIdx); + prevLevelOst->SetFieldID(0); + addrofSt2Ost[ost->GetMIRSymbol()->GetStIndex()] = prevLevelOst->GetIndex(); + } ost->SetPrevLevelOst(prevLevelOst); prevLevelOst->AddNextLevelOst(ost); return prevLevelOst; diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 0a0267c6f8c8417352c53949c736ac10fd9419c1..d7cc671c721162e40aff31284d1486294910f101 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -463,7 +463,7 @@ MIRConst *ConstantFold::FoldIntConstBinaryMIRConst(Opcode opcode, PrimType resul } case OP_mul: { if (useResult64) { - result64 = static_cast(intValueOfConst0 * intValueOfConst1); + result64 = static_cast(intValueOfConst0) * static_cast(intValueOfConst1); } else { result32 = static_cast(intValueOfConst0) * static_cast(intValueOfConst1); }