[PATCH] D80305: [mlir] Add folding for shape.any
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 02:10:16 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4a255bbd2969: [mlir] Add folding for shape.any (authored by Tres Popp <tpopp at google.com>).
Herald added a subscriber: msifontes.
Changed prior to commit:
https://reviews.llvm.org/D80305?vs=268477&id=268711#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80305/new/
https://reviews.llvm.org/D80305
Files:
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/Dialect/Shape/canonicalize.mlir
Index: mlir/test/Dialect/Shape/canonicalize.mlir
===================================================================
--- mlir/test/Dialect/Shape/canonicalize.mlir
+++ mlir/test/Dialect/Shape/canonicalize.mlir
@@ -245,3 +245,25 @@
"consume.witness"(%2) : (!shape.witness) -> ()
return
}
+
+// -----
+// any can be replaced with a constant input if it has one.
+// CHECK-LABEL: func @f
+func @f(%arg0 : !shape.shape) -> !shape.shape {
+ // CHECK-NEXT: %[[CS:.*]] = shape.const_shape
+ // CHECK-NEXT: return %[[CS]]
+ %0 = shape.const_shape [2, 3, 4]
+ %1 = shape.any %0, %arg0
+ return %1 : !shape.shape
+}
+
+
+// -----
+// Folding of any with partially constant operands is not yet implemented.
+// CHECK-LABEL: func @f
+func @f(%arg0 : !shape.shape, %arg1 : !shape.shape) -> !shape.shape {
+ // CHECK-NEXT: shape.any
+ // CHECK-NEXT: return %[[CS]]
+ %1 = shape.any %arg0, %arg1
+ return %1 : !shape.shape
+}
Index: mlir/lib/Dialect/Shape/IR/Shape.cpp
===================================================================
--- mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -101,6 +101,16 @@
// AnyOp
//===----------------------------------------------------------------------===//
+// TODO: Canonicalization should be implemented for shapes that can be
+// determined through mixtures of the known dimensions of the inputs.
+OpFoldResult AnyOp::fold(ArrayRef<Attribute> operands) {
+ // Only the last operand is checked because AnyOp is commutative.
+ if (operands.back())
+ return operands.back();
+
+ return nullptr;
+}
+
//===----------------------------------------------------------------------===//
// AssumingOp
//===----------------------------------------------------------------------===//
Index: mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
===================================================================
--- mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -438,7 +438,7 @@
//===----------------------------------------------------------------------===//
//TODO(tpopp): Move the code below and witnesses to a different file.
-def Shape_AnyOp : Shape_Op<"any", [NoSideEffect]> {
+def Shape_AnyOp : Shape_Op<"any", [Commutative, NoSideEffect]> {
let summary = "Return any combination of the input shapes";
let description = [{
This operation takes multiple input shapes and returns some combination of
@@ -458,6 +458,8 @@
let results = (outs Shape_ShapeType:$result);
let assemblyFormat = "$inputs attr-dict";
+
+ let hasFolder = 1;
}
def Shape_AssumingAllOp : Shape_Op<"assuming_all", [Commutative, NoSideEffect]> {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80305.268711.patch
Type: text/x-patch
Size: 2673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200605/43bb2a39/attachment.bin>
More information about the llvm-commits
mailing list