[Mlir-commits] [mlir] [mlir][memref]: Added OOB value bound check to ViewOp (PR #183985)

Aviad Cohen llvmlistbot at llvm.org
Sun Mar 1 10:52:18 PST 2026


================
@@ -142,6 +142,40 @@ struct SubViewOpInterface
   }
 };
 
+struct ViewOpInterface
+    : public ValueBoundsOpInterface::ExternalModel<ViewOpInterface, ViewOp> {
+  void populateBoundsForShapedValueDim(Operation *op, Value value, int64_t dim,
+                                       ValueBoundsConstraintSet &cstr) const {
+    auto viewOp = cast<ViewOp>(op);
+    assert(value == viewOp.getResult() && "invalid value");
+
+    // Each result dimension equals the corresponding mixed size (static or
+    // dynamic operand).
+    cstr.bound(value)[dim] == viewOp.getMixedSizes()[dim];
+
+    // Out-of-bounds constraint in bytes.
+    // The total number of bytes in the result should be the product of all
+    // result dimensions according to the element type size. Therefore, the
+    // out-of-bounds constraint in bytes is: (src_bytes - byte_shift) / dim_size
+    // == total_result_bytes_without_dim meaning that:
+    //  dim_size == (src_bytes - byte_shift) / total_result_bytes_without_dim
+    AffineExpr sourceBytes = cstr.getExpr(viewOp.getSource(), 0);
+    AffineExpr byteShift = cstr.getExpr(viewOp.getByteShift());
+    AffineExpr availableBytes = sourceBytes - byteShift;
+    int64_t elementSizeBytes = viewOp.getType().getElementTypeBitWidth() / 8;
----------------
AviadCo wrote:

Ack, bailed out for none int/flaot

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


More information about the Mlir-commits mailing list