[llvm] [LoopInterchange] Exit early in certain cases in legality check (NFC) (PR #139254)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 05:28:54 PDT 2025


================
@@ -231,18 +231,22 @@ static void interChangeDependencies(CharMatrix &DepMatrix, unsigned FromIndx,
     std::swap(DepMatrix[I][ToIndx], DepMatrix[I][FromIndx]);
 }
 
-// After interchanging, check if the direction vector is valid.
+// Check if a direction vector is lexicographically positive. Return true if it
+// is positive, nullopt if it is "zero", othrewise false.
 // [Theorem] A permutation of the loops in a perfect nest is legal if and only
 // if the direction matrix, after the same permutation is applied to its
 // columns, has no ">" direction as the leftmost non-"=" direction in any row.
-static bool isLexicographicallyPositive(std::vector<char> &DV) {
-  for (unsigned char Direction : DV) {
+static std::optional<bool> isLexicographicallyPositive(std::vector<char> &DV,
+                                                       unsigned Begin,
+                                                       unsigned End) {
----------------
Meinersbur wrote:

Consider default arguments
```suggestion
static std::optional<bool> isLexicographicallyPositive(std::vector<char> &DV,
                                                       unsigned Begin = 0,
                                                       unsigned End = DV.size()) {
```

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


More information about the llvm-commits mailing list