diff --git a/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp b/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp --- a/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp +++ b/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp @@ -37,12 +37,26 @@ while (true) { if (v.isa()) return v; + Operation *defOp = v.getDefiningOp(); - if (auto alloc = dyn_cast_or_null(defOp)) { - if (isStrided(alloc.getType())) - return alloc.getResult(); + if (!defOp) + return v; + + if (auto memEffect = dyn_cast(defOp)) { + // Collect all memory effects on `v`. + SmallVector effects; + memEffect.getEffectsOnValue(v, effects); + + // If we have the 'Allocate' memory effect on `v`, then `v` should be the + // original buffer. + if (llvm::any_of( + effects, [](const MemoryEffects::EffectInstance &instance) { + return isa(instance.getEffect()); + })) + return v; } - if (auto viewLikeOp = dyn_cast_or_null(defOp)) { + + if (auto viewLikeOp = dyn_cast(defOp)) { auto it = aliases.insert(std::make_pair(v, find(viewLikeOp.getViewSource()))); return it.first->second;