[Mlir-commits] [mlir] [mlir][presburger] Implement moveColumns using std::rotate (PR #168243)

Arjun P llvmlistbot at llvm.org
Fri Nov 21 11:43:37 PST 2025


================
@@ -276,23 +270,25 @@ void Matrix<T>::moveColumns(unsigned srcPos, unsigned num, unsigned dstPos) {
   assert(dstPos + num <= getNumColumns() &&
          "move destination range exceeds matrix columns");
 
-  unsigned insertCount = offset > 0 ? offset : -offset;
-  unsigned finalAdjStart = offset > 0 ? srcPos : srcPos + num;
-  unsigned curAdjStart = offset > 0 ? srcPos + num : dstPos;
-  // TODO: This can be done using std::rotate.
-  // Insert new zero columns in the positions where the adjacent columns are to
-  // be moved.
-  insertColumns(finalAdjStart, insertCount);
-  // Update curAdjStart if insertion of new columns invalidates it.
-  if (finalAdjStart < curAdjStart)
-    curAdjStart += insertCount;
-
-  // Swap the adjacent columns with inserted zero columns.
-  for (unsigned i = 0; i < insertCount; ++i)
-    swapColumns(finalAdjStart + i, curAdjStart + i);
-
-  // Delete the now redundant zero columns.
-  removeColumns(curAdjStart, insertCount);
+  unsigned numRows = getNumRows();
+  unsigned numCols = getNumReservedColumns();
+
+  if (offset > 0) {
+    // shift the matrix left, see
+    // https://en.cppreference.com/w/cpp/algorithm/rotate.html.
+    for (unsigned i = 0; i < numRows; ++i) {
+      auto begin = data.begin() + i * numCols + srcPos;
+      auto end = data.begin() + i * numCols + dstPos + num;
----------------
Superty wrote:

Can we use `&at(i, srcPos)`? That will avoid duplicating the linearization logic. (here and below)

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


More information about the Mlir-commits mailing list