@@ -77,18 +77,12 @@ static bool distinctAllocAndBlockArgument(Value v1, Value v2) {
7777 return areDistinct (v1Base, v2Base) || areDistinct (v2Base, v1Base);
7878}
7979
80- // / Checks if `memref` may or must alias a MemRef in `otherList`. It is often a
81- // / requirement of optimization patterns that there cannot be any aliasing
82- // / memref in order to perform the desired simplification. The `allowSelfAlias`
83- // / argument indicates whether `memref` may be present in `otherList` which
84- // / makes this helper function applicable to situations where we already know
85- // / that `memref` is in the list but also when we don't want it in the list.
80+ // / Checks if `memref` may potentially alias a MemRef in `otherList`. It is
81+ // / often a requirement of optimization patterns that there cannot be any
82+ // / aliasing memref in order to perform the desired simplification.
8683static bool potentiallyAliasesMemref (AliasAnalysis &analysis,
87- ValueRange otherList, Value memref,
88- bool allowSelfAlias) {
84+ ValueRange otherList, Value memref) {
8985 for (auto other : otherList) {
90- if (allowSelfAlias && other == memref)
91- continue ;
9286 if (distinctAllocAndBlockArgument (other, memref))
9387 continue ;
9488 if (!analysis.alias (other, memref).isNo ())
@@ -243,7 +237,7 @@ struct RemoveRetainedMemrefsGuaranteedToNotAlias
243237
244238 for (auto retainedMemref : deallocOp.getRetained ()) {
245239 if (potentiallyAliasesMemref (aliasAnalysis, deallocOp.getMemrefs (),
246- retainedMemref, false )) {
240+ retainedMemref)) {
247241 newRetainedMemrefs.push_back (retainedMemref);
248242 replacements.push_back ({});
249243 continue ;
@@ -314,11 +308,13 @@ struct SplitDeallocWhenNotAliasingAnyOther
314308
315309 SmallVector<Value> remainingMemrefs, remainingConditions;
316310 SmallVector<SmallVector<Value>> updatedConditions;
317- for (auto [memref, cond] :
318- llvm::zip (deallocOp.getMemrefs (), deallocOp.getConditions ())) {
311+ for (int64_t i = 0 , e = deallocOp.getMemrefs ().size (); i < e; ++i) {
312+ Value memref = deallocOp.getMemrefs ()[i];
313+ Value cond = deallocOp.getConditions ()[i];
314+ SmallVector<Value> otherMemrefs (deallocOp.getMemrefs ());
315+ otherMemrefs.erase (otherMemrefs.begin () + i);
319316 // Check if `memref` can split off into a separate bufferization.dealloc.
320- if (potentiallyAliasesMemref (aliasAnalysis, deallocOp.getMemrefs (),
321- memref, true )) {
317+ if (potentiallyAliasesMemref (aliasAnalysis, otherMemrefs, memref)) {
322318 // `memref` alias with other memrefs, do not split off.
323319 remainingMemrefs.push_back (memref);
324320 remainingConditions.push_back (cond);
0 commit comments