@@ -77,18 +77,12 @@ static bool distinctAllocAndBlockArgument(Value v1, Value v2) {
77
77
return areDistinct (v1Base, v2Base) || areDistinct (v2Base, v1Base);
78
78
}
79
79
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.
86
83
static bool potentiallyAliasesMemref (AliasAnalysis &analysis,
87
- ValueRange otherList, Value memref,
88
- bool allowSelfAlias) {
84
+ ValueRange otherList, Value memref) {
89
85
for (auto other : otherList) {
90
- if (allowSelfAlias && other == memref)
91
- continue ;
92
86
if (distinctAllocAndBlockArgument (other, memref))
93
87
continue ;
94
88
if (!analysis.alias (other, memref).isNo ())
@@ -243,7 +237,7 @@ struct RemoveRetainedMemrefsGuaranteedToNotAlias
243
237
244
238
for (auto retainedMemref : deallocOp.getRetained ()) {
245
239
if (potentiallyAliasesMemref (aliasAnalysis, deallocOp.getMemrefs (),
246
- retainedMemref, false )) {
240
+ retainedMemref)) {
247
241
newRetainedMemrefs.push_back (retainedMemref);
248
242
replacements.push_back ({});
249
243
continue ;
@@ -314,11 +308,13 @@ struct SplitDeallocWhenNotAliasingAnyOther
314
308
315
309
SmallVector<Value> remainingMemrefs, remainingConditions;
316
310
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);
319
316
// 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)) {
322
318
// `memref` alias with other memrefs, do not split off.
323
319
remainingMemrefs.push_back (memref);
324
320
remainingConditions.push_back (cond);
0 commit comments