[llvm] [LoopInterchange] Improve profitability check for vectorization (PR #133672)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 14 07:57:40 PDT 2025


================
@@ -221,13 +250,28 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
           Dep.push_back('I');
         }
 
+        auto [Ite, Inserted] = Seen.try_emplace(
+            StringRef(Dep.data(), Dep.size()), DepMatrix.size());
+
         // Make sure we only add unique entries to the dependency matrix.
-        if (Seen.insert(StringRef(Dep.data(), Dep.size())).second)
+        if (Inserted) {
           DepMatrix.push_back(Dep);
+          IsForwardFlags.push_back(true);
+        }
+        if (!IsForward)
+          IsForwardFlags.reset(Ite->second);
----------------
Meinersbur wrote:

Took me a while to understand why adding the last element is delayed until later instead of adding it directly to `Dep`. Can you add a comment about it? Including that `IsForwardFlags.push_back(true);` will be overwritten by this.

On the other side, why not adding `*` or `<` directly to Dep here, and overwriting the Dep entry with `*` if `!IsForward`. The `StringRef` for the `StringMap` can exclude the last element. 

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


More information about the llvm-commits mailing list