diff --git a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.h b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.h --- a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.h +++ b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.h @@ -62,13 +62,20 @@ /// Return true if `v1` and `v2` bufferize to equivalent buffers. bool areEquivalentBufferizedValues(Value v1, Value v2) const { - // Return `false` if we have no information about `v1` or `v2`. - if (equivalentInfo.findValue(v1) == equivalentInfo.end() || - equivalentInfo.findValue(v2) == equivalentInfo.end()) - return false; + return equivalentInfo.isEquivalent(v1, v2); + } + + /// Return true if `v1` and `v2` bufferize to aliasing buffers. + bool areAliasingBufferizedValues(Value v1, Value v2) const { + return aliasInfo.isEquivalent(v1, v2); + } + + /// Union the alias sets of `v1` and `v2`. + void unionAliasSets(Value v1, Value v2) { aliasInfo.unionSets(v1, v2); } - return equivalentInfo.getLeaderValue(v1) == - equivalentInfo.getLeaderValue(v2); + /// Union the equivalence classes of `v1` and `v2`. + void unionEquivalenceClasses(Value v1, Value v2) { + equivalentInfo.unionSets(v1, v2); } /// Apply `fun` to all the members of the equivalence class of `v`. diff --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp --- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp +++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp @@ -2049,6 +2049,8 @@ // InitTensorOps without uses are ignored by the bufferization. initTensor.replaceAllUsesWith(replacement); aliasInfo.createAliasInfoEntry(replacement); + aliasInfo.unionAliasSets(initTensor, replacement); + aliasInfo.unionEquivalenceClasses(initTensor, replacement); // Run analysis on the newly created op. if (auto opResult = replacement.dyn_cast()) { diff --git a/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir b/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir --- a/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir +++ b/mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir @@ -860,7 +860,6 @@ %f = linalg.fill(%f0, %a) : f32, tensor -> tensor // Self-copy canonicalizes away later. - // CHECK: linalg.copy(%[[T_SUBVIEW]], %[[T_SUBVIEW]]) %r1 = tensor.insert_slice %f into %t[42][%sz][1]: tensor into tensor return %r1: tensor