[Mlir-commits] [mlir] 30c0a14 - [MLIR][Presburger] Matrix::insertColumns: add doc, fix lint issue, and early exit when possible

Arjun P llvmlistbot at llvm.org
Wed Mar 23 17:42:43 PDT 2022


Author: Arjun P
Date: 2022-03-24T00:42:55Z
New Revision: 30c0a148466913fdbe4ee1c75ad3c88375b34ce3

URL: https://github.com/llvm/llvm-project/commit/30c0a148466913fdbe4ee1c75ad3c88375b34ce3
DIFF: https://github.com/llvm/llvm-project/commit/30c0a148466913fdbe4ee1c75ad3c88375b34ce3.diff

LOG: [MLIR][Presburger] Matrix::insertColumns: add doc, fix lint issue, and early exit when possible

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122137

Added: 
    

Modified: 
    mlir/lib/Analysis/Presburger/Matrix.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 2bfa5c37637fc..219d490e7368a 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -126,14 +126,27 @@ void Matrix::insertColumns(unsigned pos, unsigned count) {
       unsigned r = ri;
       unsigned c = ci;
       int64_t &dest = data[r * nReservedColumns + c];
-      if (c >= nColumns)
+      if (c >= nColumns) { // NOLINT
+        // Out of bounds columns are zero-initialized. NOLINT because clang-tidy
+        // complains about this branch being the same as the c >= pos one.
+        //
+        // TODO: this case can be skipped if the number of reserved columns
+        // didn't change.
         dest = 0;
-      else if (c >= pos + count)
+      } else if (c >= pos + count) {
+        // Shift the data occuring after the inserted columns.
         dest = data[r * oldNReservedColumns + c - count];
-      else if (c >= pos)
+      } else if (c >= pos) {
+        // The inserted columns are also zero-initialized.
         dest = 0;
-      else
+      } else {
+        // The columns before the inserted columns stay at the same (row, col)
+        // but this corresponds to a 
diff erent location in the linearized array
+        // if the number of reserved columns changed.
+        if (nReservedColumns == oldNReservedColumns)
+          break;
         dest = data[r * oldNReservedColumns + c];
+      }
     }
   }
 }


        


More information about the Mlir-commits mailing list