[llvm] [LoopInterchange] Make the entries of the Dependency Matrix unique (PR #116195)
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 02:21:01 PST 2024
https://github.com/sjoerdmeijer updated https://github.com/llvm/llvm-project/pull/116195
>From 99062425aa65e2bcb381e5d1875dfed8a1d8a7ff Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Thu, 14 Nov 2024 01:53:44 -0800
Subject: [PATCH] [LoopInterchange] Make the entries of the Dependency Matrix
unique
The entries in the dependency matrix can contain a lot of duplicates,
which is unnecessary and results in more checks that we can avoid, and
this patch does that.
I haven't added tests because the printing of the dependency matrix is
guarded by and #ifdef DUMP_DEP_MATRICES so cannot be printed in normal
builds. But all existing regression tests are passing, so is tested in
that way.
---
llvm/lib/Transforms/Scalar/LoopInterchange.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index db63bda1e6b926..8e1d07792cacdc 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -43,6 +43,7 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include <cassert>
+#include <unordered_set>
#include <utility>
#include <vector>
@@ -110,6 +111,7 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
<< " Loads and Stores to analyze\n");
ValueVector::iterator I, IE, J, JE;
+ std::unordered_set<std::string> UniqueDepEntries;
for (I = MemInstr.begin(), IE = MemInstr.end(); I != IE; ++I) {
for (J = I, JE = MemInstr.end(); J != JE; ++J) {
@@ -156,7 +158,13 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
Dep.push_back('I');
}
- DepMatrix.push_back(Dep);
+ // Make sure we only add unique entries to the dependency matrix.
+ std::string Hash = std::string(Dep.begin(), Dep.end());
+ if (UniqueDepEntries.find(Hash) == UniqueDepEntries.end()) {
+ UniqueDepEntries.insert(Hash);
+ DepMatrix.push_back(Dep);
+ }
+
if (DepMatrix.size() > MaxMemInstrCount) {
LLVM_DEBUG(dbgs() << "Cannot handle more than " << MaxMemInstrCount
<< " dependencies inside loop\n");
More information about the llvm-commits
mailing list