[Mlir-commits] [mlir] [mlir][affine] Block producer-consumer fusion across opaque memref effects (PR #225250)
Demetrios Chiuratto Agourakis
llvmlistbot at llvm.org
Sat Oct 31 04:27:42 PDT 2026
================
@@ -225,6 +226,58 @@ static void gatherEscapingMemrefs(unsigned id, const MemRefDependenceGraph &mdg,
}
}
+/// Returns true if the producer nest has opaque effects on any
+/// producer-consumer memref. An effect is treated as opaque when:
+/// 1) the producer contains non-affine memory effects on the memref, or
+/// 2) the memref has a non-dereferencing user in the producer nest
+/// (for example `func.call`), which can observe/reorder whole-buffer
+/// effects across consumer iterations.
+///
+/// Note: mere "escaping" via block arguments (used for private-memref
+/// decisions) is NOT sufficient to block fusion.
+static bool
+hasOpaqueEffectOnPCMemrefs(const MemRefDependenceGraph::Node &srcNode,
+ const DenseSet<Value> &producerConsumerMemrefs) {
+ if (producerConsumerMemrefs.empty())
+ return false;
+
+ // Non-affine memory ops collected on the producer node.
+ auto touchesPCMemref = [&](Operation *op) {
+ for (Value memref : producerConsumerMemrefs) {
+ if (hasEffect<MemoryEffects::Read>(op, memref) ||
+ hasEffect<MemoryEffects::Write>(op, memref) ||
+ hasEffect<MemoryEffects::Free>(op, memref))
+ return true;
+ // Ops without an effect model (e.g. func.call) were conservatively
+ // recorded because they take a memref operand.
+ if (!isa<MemoryEffectOpInterface>(op) &&
+ !op->hasTrait<OpTrait::HasRecursiveMemoryEffects>() &&
+ llvm::is_contained(op->getOperands(), memref))
+ return true;
+ }
+ return false;
+ };
----------------
agourakis82 wrote:
Addressed in 962d58c. The predicate inspects effect instances and blocks value-less Read/Write/Free effects in both candidate nests. loop-fusion-opaque-pc.mlir includes distinct producer and consumer regressions for those effects, with a value-less allocation control that still permits fusion. Current Linux and Windows checks pass.
Prepared with OpenAI Codex assistance.
https://github.com/llvm/llvm-project/pull/225250
More information about the Mlir-commits
mailing list