diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -3899,7 +3899,11 @@ OpFoldResult TensorLoadOp::fold(ArrayRef) { if (auto tensorToMemref = memref().getDefiningOp()) - return tensorToMemref.tensor(); + // Approximate alias analysis by conservatively folding only when no there + // is no interleaved operation. + if (tensorToMemref->getBlock() == this->getOperation()->getBlock() && + tensorToMemref->getNextNode() == this->getOperation()) + return tensorToMemref.tensor(); return {}; }