[Mlir-commits] [mlir] [mlir][vector] Teach `TransferOptimization` to look through trivial aliases (PR #87805)

Benjamin Maxwell llvmlistbot at llvm.org
Tue Apr 16 08:53:20 PDT 2024


================
@@ -88,6 +88,46 @@ bool TransferOptimization::isReachable(Operation *start, Operation *dest) {
   return false;
 }
 
+/// Walk up the source chain until an operation that changes/defines the view of
+/// memory is found (i.e. skip operations that alias the entire view).
+Value skipFullyAliasingOperations(Value source) {
+  while (auto op = source.getDefiningOp()) {
+    if (auto subViewOp = dyn_cast<memref::SubViewOp>(op);
+        subViewOp && subViewOp.hasZeroOffset() && subViewOp.hasUnitStride()) {
+      // A `memref.subview` with an all zero offset, and all unit strides, still
+      // points to the same memory.
+      source = subViewOp.getSource();
+    } else if (auto castOp = dyn_cast<memref::CastOp>(op)) {
+      // A `memref.cast` still points to the same memory.
+      source = castOp.getSource();
+    } else {
+      return source;
+    }
+  }
+  return source;
+}
----------------
MacDue wrote:

Any suggestion for a good home? :)

https://github.com/llvm/llvm-project/pull/87805


More information about the Mlir-commits mailing list