[Mlir-commits] [mlir] 7b59121 - [mlir][shape] Remove overzealous Dim verifier

Jacques Pienaar llvmlistbot at llvm.org
Wed Jul 5 20:01:41 PDT 2023


Author: Jacques Pienaar
Date: 2023-07-05T20:01:32-07:00
New Revision: 7b59121be5ae0f8393d17ad54d7a23b70097104a

URL: https://github.com/llvm/llvm-project/commit/7b59121be5ae0f8393d17ad54d7a23b70097104a
DIFF: https://github.com/llvm/llvm-project/commit/7b59121be5ae0f8393d17ad54d7a23b70097104a.diff

LOG: [mlir][shape] Remove overzealous Dim verifier

Follow up of D143999 and follow
https://mlir.llvm.org/getting_started/DeveloperGuide/#ir-verifier.

Fixes #60808.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index 47918b46dddc98..dce5be8207c82b 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -361,7 +361,6 @@ def Shape_DimOp : Shape_Op<"dim",
   }];
 
   let hasFolder = 1;
-  let hasVerifier = 1;
 }
 
 def Shape_GetExtentOp : Shape_Op<"get_extent",

diff  --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index b1dffbf98920d9..c5c69dc98b82a0 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -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
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list