[Mlir-commits] [mlir] 82b692e - [mlir][Shape] Mark BroadcastOp as not having side effects

Benjamin Kramer llvmlistbot at llvm.org
Wed Feb 17 01:26:39 PST 2021


Author: Benjamin Kramer
Date: 2021-02-17T10:26:14+01:00
New Revision: 82b692e54698a3b2b874ea4f6e97c5337e8045d1

URL: https://github.com/llvm/llvm-project/commit/82b692e54698a3b2b874ea4f6e97c5337e8045d1
DIFF: https://github.com/llvm/llvm-project/commit/82b692e54698a3b2b874ea4f6e97c5337e8045d1.diff

LOG: [mlir][Shape] Mark BroadcastOp as not having side effects

This allows it to be dead code eliminated when unused.

Differential Revision: https://reviews.llvm.org/D96797

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/test/Dialect/Shape/canonicalize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index b50a6f99e04c..30e8ca10150d 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -49,7 +49,7 @@ def Shape_AddOp : Shape_Op<"add", [Commutative, NoSideEffect]> {
   let verifier = [{ return verifySizeOrIndexOp(*this); }];
 }
 
-def Shape_BroadcastOp : Shape_Op<"broadcast", [Commutative]> {
+def Shape_BroadcastOp : Shape_Op<"broadcast", [Commutative, NoSideEffect]> {
   let summary = "Returns the broadcasted output shape of two or more inputs";
   let description = [{
     Returns the broadcasted shape for input shapes or extent tensors. The rest

diff  --git a/mlir/test/Dialect/Shape/canonicalize.mlir b/mlir/test/Dialect/Shape/canonicalize.mlir
index f7e3c66a6014..ba7e479eb347 100644
--- a/mlir/test/Dialect/Shape/canonicalize.mlir
+++ b/mlir/test/Dialect/Shape/canonicalize.mlir
@@ -132,6 +132,17 @@ func @f() -> !shape.shape {
 
 // -----
 
+// Dead code
+// CHECK-LABEL: @broadcast
+func @broadcast(%arg0 : !shape.shape, %arg1 : !shape.shape) {
+  // CHECK-NEXT: return
+  %0 = shape.broadcast %arg0, %arg1
+      : !shape.shape, !shape.shape -> !shape.shape
+  return
+}
+
+// -----
+
 // Basic case.
 // CHECK-LABEL: func @f
 func @f() -> !shape.shape {


        


More information about the Mlir-commits mailing list