[llvm] [LoopFusion] Improve collectFusionCandidates() (PR #182571)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 20 11:07:02 PST 2026
https://github.com/amehsan created https://github.com/llvm/llvm-project/pull/182571
The order of visiting loops in collectFusionCandidates() guarantees that a new member can only possibly be added to the end of a set.
Also currently `NumFusionCandidates` counts any loop that is added to a candidate set. Usually large majority of candidate sets have a single members so they are not really candidates for fusion. Only the second member of a candidate set and the ones that come after that could be counted as fusion candidates.
>From 966ecec6609a515aebcb272dd9b243c5d044c45c Mon Sep 17 00:00:00 2001
From: Ehsan Amiri <ehsan.amiri at huawei.com>
Date: Thu, 19 Feb 2026 13:12:38 -0500
Subject: [PATCH] [LoopFusion] Improve collectFusionCandidates()
The order of visiting loops in collectFusionCandidates() guarantees that a new
member can only possibly be added to the end of a set.
Also currently `NumFusionCandidates` counts any loop that is added to a
candidate set. Usually large majority of candidate sets have a single
members so they are not really candidates for fusion. Only the second member
of a candidate set and the ones that come after that could be counted as fusion
candidates.
---
llvm/lib/Transforms/Scalar/LoopFuse.cpp | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
index eefd602659660..48a19839529b0 100644
--- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -591,18 +591,10 @@ struct LoopFuser {
// FusionCandidates.
bool FoundAdjacent = false;
for (auto &CurrCandList : FusionCandidates) {
- if (isStrictlyAdjacent(CurrCand, CurrCandList.front())) {
- CurrCandList.push_front(CurrCand);
- FoundAdjacent = true;
-#ifndef NDEBUG
- if (VerboseFusionDebugging)
- LLVM_DEBUG(dbgs() << "Adding " << CurrCand
- << " to existing candidate list\n");
-#endif
- break;
- } else if (isStrictlyAdjacent(CurrCandList.back(), CurrCand)) {
+ if (isStrictlyAdjacent(CurrCandList.back(), CurrCand)) {
CurrCandList.push_back(CurrCand);
FoundAdjacent = true;
+ NumFusionCandidates++;
#ifndef NDEBUG
if (VerboseFusionDebugging)
LLVM_DEBUG(dbgs() << "Adding " << CurrCand
@@ -621,7 +613,6 @@ struct LoopFuser {
NewCandList.push_back(CurrCand);
FusionCandidates.push_back(NewCandList);
}
- NumFusionCandidates++;
}
}
More information about the llvm-commits
mailing list