[Mlir-commits] [mlir] [MLIR] Incorrect result for RuntimeVerifiableOpInterface on MemRef::R… (PR #96580)

Matthias Springer llvmlistbot at llvm.org
Tue Jun 25 00:08:53 PDT 2024


================
@@ -305,6 +305,40 @@ mlir::computeLinearIndex(OpFoldResult sourceOffset,
   return {expr, values};
 }
 
+std::pair<AffineExpr, SmallVector<OpFoldResult>>
+mlir::computeInclusiveLinearIndex(OpFoldResult sourceOffset,
+                                  ArrayRef<OpFoldResult> strides,
+                                  ArrayRef<OpFoldResult> indices) {
+  assert(strides.size() == indices.size());
+  auto sourceRank = static_cast<unsigned>(strides.size());
+
+  // Hold the affine symbols and values for the computation of the offset.
+  SmallVector<OpFoldResult> values(2 * sourceRank + 1);
+  SmallVector<AffineExpr> symbols(2 * sourceRank + 1);
+
+  bindSymbolsList(getContext(sourceOffset), MutableArrayRef{symbols});
+  AffineExpr expr = symbols.front();
+  AffineExpr constOneExpr = getAffineConstantExpr(1, getContext(sourceOffset));
+  values[0] = sourceOffset;
+
+  for (unsigned i = 0; i < sourceRank; ++i) {
+    // Compute the stride.
+    OpFoldResult origStride = strides[i];
+
+    // Build up the computation of the offset.
+    unsigned baseIdxForDim = 1 + 2 * i;
+    unsigned subOffsetForDim = baseIdxForDim;
+    unsigned origStrideForDim = baseIdxForDim + 1;
+    // Subtract 1 from the index to get the inclusive bound
+    expr = expr + (symbols[subOffsetForDim] - constOneExpr) *
----------------
matthias-springer wrote:

Can you also put all the AffineExprs into separate variables so that we have a more readable computation here? Something along the lines of `expr = expr + (index - 1) * stride`.

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


More information about the Mlir-commits mailing list