[Mlir-commits] [mlir] [mlir] ViewLikeInterface - verify ranks in verifyOffsetSizeAndStrideOp (PR #147926)

Matthias Springer llvmlistbot at llvm.org
Thu Jul 10 05:15:12 PDT 2025


================
@@ -94,6 +94,32 @@ SliceBoundsVerificationResult mlir::verifyInBoundsSlice(
 
 LogicalResult
 mlir::detail::verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op) {
+  // A dynamic size is represented as ShapedType::kDynamic in `static_sizes`.
+  // Its corresponding Value appears in `sizes`. Thus, the number of dynamic
+  // dimensions in `static_sizes` must equal the rank of `sizes`.
+  // The same applies to strides and offsets.
+  unsigned int numDynamicDims =
+      llvm::count_if(op.getStaticSizes(), ShapedType::isDynamic);
+  if (op.getSizes().size() != numDynamicDims) {
+    return op->emitError("expected sizes rank to match the number of dynamic "
+                         "dimensions (")
+           << op.getSizes().size() << " vs " << numDynamicDims << ")";
+  }
+  unsigned int numDynamicStrides =
+      llvm::count_if(op.getStaticStrides(), ShapedType::isDynamic);
+  if (op.getStrides().size() != numDynamicStrides) {
+    return op->emitError("expected strides rank to match the number of dynamic "
+                         "strides (")
+           << op.getStrides().size() << " vs " << numDynamicStrides << ")";
+  }
+  unsigned int numDynamicOffsets =
+      llvm::count_if(op.getStaticOffsets(), ShapedType::isDynamic);
+  if (op.getOffsets().size() != numDynamicOffsets) {
+    return op->emitError("expected offsets rank to match the number of dynamic "
----------------
matthias-springer wrote:

same as above

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


More information about the Mlir-commits mailing list