Skip to content

Commit ed84d82

Browse files
update code and rebase main.
1 parent b13e220 commit ed84d82

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

mlir/lib/Analysis/Presburger/Matrix.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,21 @@ void Matrix<T>::moveColumns(unsigned srcPos, unsigned num, unsigned dstPos) {
271271
"move destination range exceeds matrix columns");
272272

273273
unsigned numRows = getNumRows();
274-
unsigned numCols = getNumReservedColumns();
275274

276275
if (offset > 0) {
277-
// shift the matrix left, see
278-
// https://en.cppreference.com/w/cpp/algorithm/rotate.html.
276+
// Shift the matrix left, because start < end, that std::rotate(start,
277+
// middle, end) turns the range [start, end] to [middle, end) + [start,
278+
// middle).
279279
for (unsigned i = 0; i < numRows; ++i) {
280-
auto begin = data.begin() + i * numCols + srcPos;
281-
auto end = data.begin() + i * numCols + dstPos + num;
282-
std::rotate(begin, begin + num, end);
283-
}
284-
} else {
285-
// shift the matrix right.
286-
for (unsigned i = 0; i < numRows; ++i) {
287-
auto begin = data.begin() + i * numCols + srcPos + num;
288-
auto end = data.begin() + i * numCols + dstPos;
289-
std::rotate(end, begin - num, begin);
280+
std::rotate(&at(i, srcPos), &at(i, srcPos) + num, &at(i, dstPos) + num);
290281
}
282+
return;
283+
}
284+
// Shift the matrix right. because end < start, that std::rotate(start,
285+
// middle, end) turns the range [start, end] to [middle, start) + [end,
286+
// middle).
287+
for (unsigned i = 0; i < numRows; ++i) {
288+
std::rotate(&at(i, dstPos), &at(i, srcPos), &at(i, srcPos) + num);
291289
}
292290
}
293291

0 commit comments

Comments
 (0)