[Mlir-commits] [mlir] [mlir][MemRef] Add position-based matching heuristics for rank-reduction with dynamic strides (PR #184334)

Abhishek Varma llvmlistbot at llvm.org
Wed Mar 4 22:50:03 PST 2026


================
@@ -977,47 +1064,27 @@ computeMemRefRankReductionMask(MemRefType originalType, MemRefType reducedType,
           reducedType.getStridesAndOffset(candidateStrides, candidateOffset)))
     return failure();
 
-  // For memrefs, a dimension is truly dropped if its corresponding stride is
-  // also dropped. This is particularly important when more than one of the dims
-  // is 1. Track the number of occurences of the strides in the original type
-  // and the candidate type. For each unused dim that stride should not be
-  // present in the candidate type. Note that there could be multiple dimensions
-  // that have the same size. We dont need to exactly figure out which dim
-  // corresponds to which stride, we just need to verify that the number of
-  // reptitions of a stride in the original + number of unused dims with that
-  // stride == number of repititions of a stride in the candidate.
-  std::map<int64_t, unsigned> currUnaccountedStrides =
-      getNumOccurences(originalStrides);
-  std::map<int64_t, unsigned> candidateStridesNumOccurences =
-      getNumOccurences(candidateStrides);
-  for (size_t dim = 0, e = unusedDims.size(); dim != e; ++dim) {
-    if (!unusedDims.test(dim))
-      continue;
-    int64_t originalStride = originalStrides[dim];
-    if (currUnaccountedStrides[originalStride] >
-        candidateStridesNumOccurences[originalStride]) {
-      // This dim can be treated as dropped.
-      currUnaccountedStrides[originalStride]--;
-      continue;
-    }
-    if (currUnaccountedStrides[originalStride] ==
-        candidateStridesNumOccurences[originalStride]) {
-      // The stride for this is not dropped. Keep as is.
-      unusedDims.reset(dim);
-      continue;
-    }
-    if (currUnaccountedStrides[originalStride] <
-        candidateStridesNumOccurences[originalStride]) {
-      // This should never happen. Cant have a stride in the reduced rank type
-      // that wasnt in the original one.
----------------
Abhishek-Varma wrote:

Done.

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


More information about the Mlir-commits mailing list