[Mlir-commits] [mlir] [mlir][tosa] Disallow inferable dim in reshape/slice validation (PR #182472)

Luke Hutton llvmlistbot at llvm.org
Mon Mar 2 02:20:51 PST 2026


================
@@ -1214,6 +1215,47 @@ LogicalResult checkErrorIfPad(Operation *op) {
   return success();
 }
 
+LogicalResult checkErrorIfReshape(Operation *op) {
+  auto reshapeOp = dyn_cast<tosa::ReshapeOp>(op);
+  if (!reshapeOp)
+    return success();
+
+  constexpr int64_t kInferableDim = -1;
+  SmallVector<int64_t> shapeValues;
+  if (!tosa::getConstShapeValues(reshapeOp.getShape().getDefiningOp(),
+                                 shapeValues))
+    return success();
+
+  if (llvm::is_contained(shapeValues, kInferableDim))
+    return op->emitOpError("shape input contains inferable dimension (-1) "
----------------
lhutton1 wrote:

It's not a recent change, it's just that the spec never supported expressing dynamic/unknown dimensions. Adding this restriction in the validation pass makes sure other tools that implement the spec don't encounter this behaviour. While the dialect is a superset (so can be used to express non-compliant behaviour), it would be nice to rely on shape expressions for this behaviour in the future, rather than relying on a "special" value to indicate dynamic handling in an op.

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


More information about the Mlir-commits mailing list