Eliminate the subsequent applications of `size_to_index` and `index_to_size`.
Differential Revision: https://reviews.llvm.org/D82083
let assemblyFormat = "$arg attr-dict";
let hasFolder = 1;
+ let hasCanonicalizer = 1;
}
def Shape_JoinOp : Shape_Op<"join", []> {
return {};
}
+void IndexToSizeOp::getCanonicalizationPatterns(
+ OwningRewritePatternList &patterns, MLIRContext *context) {
+ patterns.insert<SizeToIndexToSizeCanonicalization>(context);
+}
+
//===----------------------------------------------------------------------===//
// FromExtentsOp
//===----------------------------------------------------------------------===//
(Shape_SizeToIndexOp (Shape_IndexToSizeOp $arg)),
(replaceWithValue $arg)>;
+def SizeToIndexToSizeCanonicalization : Pat<
+ (Shape_IndexToSizeOp (Shape_SizeToIndexOp $arg)),
+ (replaceWithValue $arg)>;
+
return %result : index
}
+// -----
+
+// Canonicalize redundant conversion from `size` to `index` and back.
+// CHECK-LABEL: @size_to_index_to_size
+// CHECK-SAME: (%[[SIZE:.*]]: !shape.size) -> !shape.size
+func @size_to_index_to_size(%size : !shape.size) -> !shape.size {
+ // CHECK: return %[[SIZE]] : !shape.size
+ %idx = shape.size_to_index %size
+ %result = shape.index_to_size %idx
+ return %result : !shape.size
+}
+