[Mlir-commits] [mlir] [MLIR][Affine] Fix fusion across ops with unknown memory effects (PR #203231)

Federico Bruzzone llvmlistbot at llvm.org
Fri Jun 12 06:48:48 PDT 2026


================
@@ -83,7 +122,7 @@ unsigned Node::getLoadOpCount(Value memref) const {
     if (auto affineLoad = dyn_cast<AffineReadOpInterface>(loadOp)) {
       if (memref == affineLoad.getMemRef())
         ++loadOpCount;
-    } else if (hasEffect<MemoryEffects::Read>(loadOp, memref)) {
+    } else if (mayHaveEffect<MemoryEffects::Read>(loadOp, memref)) {
       ++loadOpCount;
     }
   }
----------------
FedericoBruzzone wrote:

Thanks for the detailed explanation, you're right on all fronts.

Looking at the diff more carefully, I see the root cause was the mismatch between `getEffectedValues` (conservative for ops without `MemoryEffectOpInterface`) and `hasEffect` (returns false for those same ops). 

Centralizing via `mayHaveEffect / getMayEffectedValues` is the correct fix from my POV: sharing one code path guarantees they can't diverge again.

The cost argument also makes sense: for non-affine ops with 1–2 memref operands, the `SmallVector` stays inline and the scan is negligible. And I agree that passing MDG into Node would be backwards coupling, not an improvement.

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


More information about the Mlir-commits mailing list