From: Rob Suderman Date: Thu, 11 Jun 2020 00:18:33 +0000 (-0700) Subject: [mlir][StandardOps] Updated IndexCastOp to support tensor cast X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d56f166bd3c00e1b05931d57d385ef2b41c092d;p=platform%2Fupstream%2Fllvm.git [mlir][StandardOps] Updated IndexCastOp to support tensor cast Summary: We now support index casting for tensor to tensor. This better supports compatibility with the Shape dialect. Differential Revision: https://reviews.llvm.org/D81611 --- diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp index 0177dfc..47532c5 100644 --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -1765,6 +1765,15 @@ bool FPTruncOp::areCastCompatible(Type a, Type b) { // Index cast is applicable from index to integer and backwards. bool IndexCastOp::areCastCompatible(Type a, Type b) { + if (a.isa() && b.isa()) { + auto aShaped = a.cast(); + auto bShaped = b.cast(); + + return (aShaped.getShape() == bShaped.getShape()) && + areCastCompatible(aShaped.getElementType(), + bShaped.getElementType()); + } + return (a.isIndex() && b.isSignlessInteger()) || (a.isSignlessInteger() && b.isIndex()); } diff --git a/mlir/test/Dialect/Standard/invalid.mlir b/mlir/test/Dialect/Standard/invalid.mlir new file mode 100644 index 0000000..471ffeb --- /dev/null +++ b/mlir/test/Dialect/Standard/invalid.mlir @@ -0,0 +1,17 @@ +// RUN: mlir-opt -split-input-file %s -verify-diagnostics + +// CHECK-LABEL: test_index_cast_shape_error +func @test_index_cast_shape_error(%arg0 : tensor) -> tensor<2xi64> { + // expected-error @+1 {{operand type 'tensor' and result type 'tensor<2xi64>' are cast incompatible}} + %0 = index_cast %arg0 : tensor to tensor<2xi64> + return %0 : tensor<2xi64> +} + +// ----- + +// CHECK-LABEL: test_index_cast_tensor_error +func @test_index_cast_tensor_error(%arg0 : tensor) -> i64 { + // expected-error @+1 {{operand type 'tensor' and result type 'i64' are cast incompatible}} + %0 = index_cast %arg0 : tensor to i64 + return %0 : i64 +} diff --git a/mlir/test/Dialect/Standard/ops.mlir b/mlir/test/Dialect/Standard/ops.mlir new file mode 100644 index 0000000..3b098eb --- /dev/null +++ b/mlir/test/Dialect/Standard/ops.mlir @@ -0,0 +1,20 @@ +// RUN: mlir-opt -split-input-file %s | FileCheck %s + +// CHECK-LABEL: test_index_cast +func @test_index_cast(%arg0 : index) -> i64 { + %0 = index_cast %arg0 : index to i64 + return %0 : i64 +} + +// CHECK-LABEL: test_index_cast_tensor +func @test_index_cast_tensor(%arg0 : tensor) -> tensor { + %0 = index_cast %arg0 : tensor to tensor + return %0 : tensor +} + +// CHECK-LABEL: test_index_cast_tensor_reverse +func @test_index_cast_tensor_reverse(%arg0 : tensor) -> tensor { + %0 = index_cast %arg0 : tensor to tensor + return %0 : tensor +} +