[llvm] [LoopInterchange] Make the entries of the Dependency Matrix unique (PR #116195)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 02:05:20 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Sjoerd Meijer (sjoerdmeijer)
<details>
<summary>Changes</summary>
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 adds that.
I haven't added tests because the printing of the dependency matrix is guarded by an #ifdef DUMP_DEP_MATRICES so cannot be printed in normal builds. But all existing regression tests are passing, so this is tested in that way.
---
Full diff: https://github.com/llvm/llvm-project/pull/116195.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/LoopInterchange.cpp (+9-1)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index db63bda1e6b926..703be2fb7ad39b 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");
``````````
</details>
https://github.com/llvm/llvm-project/pull/116195
More information about the llvm-commits
mailing list