From cf793349db656a25d314ef27c6e8ddf4a0b71b81 Mon Sep 17 00:00:00 2001 From: William Chen Date: Mon, 22 Nov 2021 18:41:36 -0800 Subject: [PATCH] Fix loop merge for multi-entry when 1st header is not the same --- src/mapleall/maple_be/include/cg/loop.h | 1 + src/mapleall/maple_be/src/cg/loop.cpp | 26 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_be/include/cg/loop.h b/src/mapleall/maple_be/include/cg/loop.h index 052c7ef4cf..581b31406a 100644 --- a/src/mapleall/maple_be/include/cg/loop.h +++ b/src/mapleall/maple_be/include/cg/loop.h @@ -134,6 +134,7 @@ class LoopFinder : public AnalysisResult { void seekBackEdge(BB* bb, MapleList succs); void seekCycles(); void markExtraEntryAndEncl(); + bool HasSameHeader(LoopHierarchy *lp1, LoopHierarchy *lp2); void MergeLoops(); void SortLoops(); void UpdateOuterForInnerLoop(BB *bb, LoopHierarchy *outer); diff --git a/src/mapleall/maple_be/src/cg/loop.cpp b/src/mapleall/maple_be/src/cg/loop.cpp index e3f6ca5173..c581108110 100644 --- a/src/mapleall/maple_be/src/cg/loop.cpp +++ b/src/mapleall/maple_be/src/cg/loop.cpp @@ -352,6 +352,23 @@ void LoopFinder::markExtraEntryAndEncl() { } } +bool LoopFinder::HasSameHeader(LoopHierarchy *lp1, LoopHierarchy *lp2) { + if (lp1->GetHeader() == lp2->GetHeader()) { + return true; + } + for (auto other1 : lp1->otherLoopEntries) { + if (lp2->GetHeader() == other1) { + return true; + } + for (auto other2 : lp2->otherLoopEntries) { + if (other2 == other1) { + return true; + } + } + } + return false; +} + void LoopFinder::MergeLoops() { for (LoopHierarchy *loopHierarchy1 = loops; loopHierarchy1 != nullptr; loopHierarchy1 = loopHierarchy1->GetNext()) { for (LoopHierarchy *loopHierarchy2 = loopHierarchy1->GetNext(); loopHierarchy2 != nullptr; @@ -383,14 +400,19 @@ void LoopFinder::MergeLoops() { continue; } } - if (loopHierarchy1->GetHeader() != loopHierarchy2->GetHeader()) { + if (HasSameHeader(loopHierarchy1, loopHierarchy2) == false) { continue; } for (auto *bb : loopHierarchy2->GetLoopMembers()) { loopHierarchy1->InsertLoopMembers(*bb); } + if (loopHierarchy1->GetHeader() != loopHierarchy2->GetHeader()) { + loopHierarchy1->otherLoopEntries.insert(loopHierarchy2->GetHeader()); + } for (auto bb : loopHierarchy2->otherLoopEntries) { - loopHierarchy1->otherLoopEntries.insert(bb); + if (loopHierarchy1->GetHeader() != bb) { + loopHierarchy1->otherLoopEntries.insert(bb); + } } for (auto *bb : loopHierarchy2->GetBackedge()) { loopHierarchy1->InsertBackedge(*bb); -- Gitee