Remove restriction on static dimensions in Shape method
authorTres Popp <tpopp@google.com>
Tue, 8 Feb 2022 10:15:04 +0000 (11:15 +0100)
committerTres Popp <tpopp@google.com>
Tue, 8 Feb 2022 10:20:01 +0000 (11:20 +0100)
mlir::shape::ToExtentTensorOp::areCastCompatible didn't allow the input
to have a static dimension, but that is allowed.

mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/Dialect/Shape/ops.mlir

index 1ae9e68..89a9766 100644 (file)
@@ -1767,7 +1767,7 @@ bool ToExtentTensorOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
     return false;
   if (auto inputTensor = inputs[0].dyn_cast<RankedTensorType>()) {
     if (!inputTensor.getElementType().isa<IndexType>() ||
-        inputTensor.getRank() != 1 || !inputTensor.isDynamicDim(0))
+        inputTensor.getRank() != 1)
       return false;
   } else if (!inputs[0].isa<ShapeType>()) {
     return false;
index e4f22a2..8c21878 100644 (file)
@@ -168,6 +168,11 @@ func @test_to_extent_tensor(%arg: !shape.shape) -> tensor<3xindex> {
   return %0 : tensor<3xindex>
 }
 
+func @test_identity_to_extent_tensor(%arg: tensor<3xindex>) -> tensor<3xindex> {
+  %0 = shape.to_extent_tensor %arg : tensor<3xindex> -> tensor<3xindex>
+  return %0 : tensor<3xindex>
+}
+
 func @test_from_extent_tensor(%arg: tensor<?xindex>) -> !shape.shape {
   %0 = shape.from_extent_tensor %arg : tensor<?xindex>
   return %0 : !shape.shape