[llvm] [LoopInterchange] Make the entries of the Dependency Matrix unique (PR #116195)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 13:55:15 PST 2024


================
@@ -156,7 +157,14 @@ 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.
+        size_t Hash =
+            std::hash<std::string>{}(std::string(Dep.begin(), Dep.end()));
+        if (!Seen.count(Hash)) {
+          Seen.insert(Hash);
----------------
mshockwave wrote:

```suggestion
        if (Seen.insert(Hash).second) {
```
The second element of the returned std::pair from insert indicate if an insertion actually happens (i.e. it's first time you see it)

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


More information about the llvm-commits mailing list