[mlir][shape] Remove overzealous Dim verifier
authorJacques Pienaar <jpienaar@google.com>
Thu, 6 Jul 2023 03:01:32 +0000 (20:01 -0700)
committerJacques Pienaar <jpienaar@google.com>
Thu, 6 Jul 2023 03:01:32 +0000 (20:01 -0700)
Follow up of D143999 and follow
https://mlir.llvm.org/getting_started/DeveloperGuide/#ir-verifier.

Fixes #60808.

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/lib/Dialect/Shape/IR/Shape.cpp

index 47918b4..dce5be8 100644 (file)
@@ -361,7 +361,6 @@ def Shape_DimOp : Shape_Op<"dim",
   }];
 
   let hasFolder = 1;
-  let hasVerifier = 1;
 }
 
 def Shape_GetExtentOp : Shape_Op<"get_extent",
index b1dffbf..c5c69dc 100644 (file)
@@ -1095,7 +1095,7 @@ OpFoldResult DimOp::fold(FoldAdaptor adaptor) {
   std::optional<int64_t> index = getConstantIndex();
   if (!index.has_value())
     return nullptr;
-  if (index.value() >= valShapedType.getRank())
+  if (index.value() < 0 || index.value() >= valShapedType.getRank())
     return nullptr;
   auto extent = valShapedType.getDimSize(*index);
   if (ShapedType::isDynamic(extent))
@@ -1116,17 +1116,6 @@ bool mlir::shape::DimOp::isCompatibleReturnTypes(TypeRange l, TypeRange r) {
   return eachHasOnlyOneOfTypes<SizeType, IndexType>(l, r);
 }
 
-LogicalResult mlir::shape::DimOp::verify() {
-  auto st = llvm::cast<ShapedType>(getValue().getType());
-  if (!st.hasRank())
-    return success();
-  if (auto index = getConstantIndex()) {
-    if (*index < 0 || *index >= st.getRank())
-      return emitOpError("index is out of range");
-  }
-  return success();
-}
-
 //===----------------------------------------------------------------------===//
 // DivOp
 //===----------------------------------------------------------------------===//