Skip to content

Commit

Permalink
[MLIR] Fix dialect conversion cancelRootUpdate
Browse files Browse the repository at this point in the history
Fix dialect conversion ConversionPatternRewriter::cancelRootUpdate: the
erasure of operations here from the list of root update was off by one.
Should have been:
```
rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it - 1));
```
instead of
```
rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it));
```

or more directly:
```
rootUpdates.erase(it.base() - 1)
```

While on this, add an assertion to improve dev experience when a cancel is
called on an op on which a root update hasn't been started.

Differential Revision: https://reviews.llvm.org/D105397
  • Loading branch information
bondhugula committed Jul 6, 2021
1 parent 17b701c commit 0c29f45
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mlir/lib/Transforms/Utils/DialectConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,9 @@ void ConversionPatternRewriter::cancelRootUpdate(Operation *op) {
auto stateHasOp = [op](const auto &it) { return it.getOperation() == op; };
auto &rootUpdates = impl->rootUpdates;
auto it = llvm::find_if(llvm::reverse(rootUpdates), stateHasOp);
rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it));
assert(it != rootUpdates.rend() && "no root update started on op");
int updateIdx = std::prev(rootUpdates.rend()) - it;
rootUpdates.erase(rootUpdates.begin() + updateIdx);
}

/// PatternRewriter hook for notifying match failure reasons.
Expand Down Expand Up @@ -2049,7 +2051,7 @@ void OperationLegalizer::computeLegalizationGraphBenefit(
orderedPatternList = anyOpLegalizerPatterns;

// If the pattern is not found, then it was removed and cannot be matched.
auto it = llvm::find(orderedPatternList, &pattern);
auto *it = llvm::find(orderedPatternList, &pattern);
if (it == orderedPatternList.end())
return PatternBenefit::impossibleToMatch();

Expand Down

0 comments on commit 0c29f45

Please sign in to comment.