[polly] [polly] Add profitability check for expanded region. (PR #96548)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 01:44:01 PDT 2024


================
@@ -1749,6 +1760,56 @@ bool ScopDetection::isProfitableRegion(DetectionContext &Context) const {
   return invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
 }
 
+bool ScopDetection::isRegionExpansionProfitable(const Region &ExpandedRegion,
+                                                LoopInfo &LI) const {
+  if (!RegionExpansionProfitabilityCheck)
+    return true;
+
+  POLLY_DEBUG(dbgs() << "\nChecking expanded region: "
+                     << ExpandedRegion.getNameStr() << "\n");
+
+  // Collect outermost loops from expanded region.
+  SmallPtrSet<const Loop *, 2> Loops;
+  for (auto BB : ExpandedRegion.blocks()) {
+    Loop *L = ExpandedRegion.outermostLoopInRegion(&LI, BB);
+    if (L)
+      Loops.insert(L);
+  }
+
+  if (Loops.size() == 0) {
+    POLLY_DEBUG(dbgs() << "Unprofitable expanded region: no loops found.\n");
+    return false;
+  }
+
+  // Return region expansion as unprofitable, if it contains basic blocks with
+  // memory accesses not used in outermost loops of the expanded region.
+  for (auto BB : ExpandedRegion.blocks()) {
----------------
Meinersbur wrote:

```suggestion
  for (BasicBlock *BB : ExpandedRegion.blocks()) {
```

https://github.com/llvm/llvm-project/pull/96548


More information about the llvm-commits mailing list