[mlir] OperationFolder: fix crash in creation of single-result-ops with in-place...
authorAlex Zinenko <zinenko@google.com>
Wed, 6 May 2020 15:39:23 +0000 (17:39 +0200)
committerAlex Zinenko <zinenko@google.com>
Wed, 6 May 2020 18:40:32 +0000 (20:40 +0200)
commit26f93d9f373a1e638b621391ef7ba9bdf7b79044
tree3300e4c6d87b99ad7c060382ea98d40c658ec0bc
parent1b678ee8a6cc7510801b7c5be2bcde08ff8bbd6e
[mlir] OperationFolder: fix crash in creation of single-result-ops with in-place folds

When the folding is performed in place, the `::fold` function does not populate
its `results` argument to indicate that. (In the folding hook for single-result
operations, the result of the original operation is expected to be returned,
but it is then ignored by the wrapper.) `OperationFolder::create` would
erronously rely on the _operation_ having zero results instead of on the
_folding_ producing zero new results to populate the list of results with those
of the original operation. This would lead to a crash for single-result ops
with in-place folds where the first result is accessed uncondtionally because
the list of results was not properly populated. Use the list of values produced
by the folding instead.

Differential Revision: https://reviews.llvm.org/D79497
mlir/include/mlir/Transforms/FoldUtils.h
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/lib/Dialect/Test/TestPatterns.cpp