-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][memref] Add a folder for chained AssumeAlignmentOp ops. #142425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The chained ops can be folded away when they have the same alignment. Signed-off-by: hanhanW <hanhan0912@gmail.com>
@llvm/pr-subscribers-mlir-memref @llvm/pr-subscribers-mlir Author: Han-Chung Wang (hanhanW) ChangesThe chained ops can be folded away when they have the same alignment. Full diff: https://github.com/llvm/llvm-project/pull/142425.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index f33ecb28d27cd..77e3074661abf 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -174,6 +174,7 @@ def AssumeAlignmentOp : MemRef_Op<"assume_alignment", [
}];
let hasVerifier = 1;
+ let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
index aa9587510670c..d56b32193765e 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
@@ -533,6 +533,15 @@ void AssumeAlignmentOp::getAsmResultNames(
setNameFn(getResult(), "assume_align");
}
+OpFoldResult AssumeAlignmentOp::fold(FoldAdaptor adaptor) {
+ auto source = getMemref().getDefiningOp<AssumeAlignmentOp>();
+ if (!source)
+ return {};
+ if (source.getAlignment() != getAlignment())
+ return {};
+ return getMemref();
+}
+
//===----------------------------------------------------------------------===//
// CastOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/MemRef/canonicalize.mlir b/mlir/test/Dialect/MemRef/canonicalize.mlir
index da6faf490653d..7a267ae8a2c95 100644
--- a/mlir/test/Dialect/MemRef/canonicalize.mlir
+++ b/mlir/test/Dialect/MemRef/canonicalize.mlir
@@ -1177,3 +1177,16 @@ func.func @cannot_fold_transpose_cast(%arg0: memref<?x4xf32>) -> memref<?x?xf32,
// CHECK: return %[[TRANSPOSE]]
return %transpose : memref<?x?xf32, #transpose_map>
}
+
+// -----
+
+// CHECK-LABEL: func @fold_assume_alignment_chain
+// CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]
+func.func @fold_assume_alignment_chain(%0: memref<128xf32>) -> memref<128xf32> {
+ // CHECK: %[[ALIGN:.+]] = memref.assume_alignment %[[ARG0]], 16
+ %1 = memref.assume_alignment %0, 16 : memref<128xf32>
+ // CHECK-NOT: memref.assume_alignment
+ %2 = memref.assume_alignment %1, 16 : memref<128xf32>
+ // CHECK: return %[[ALIGN]]
+ return %2 : memref<128xf32>
+}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/13650 Here is the relevant piece of the build log for the reference
|
…142425) The chained ops can be folded away when they have the same alignment. Signed-off-by: hanhanW <hanhan0912@gmail.com>
The chained ops can be folded away when they have the same alignment.