This is an archive of the discontinued LLVM Phabricator instance.

[mlir] OperationFolder: fix crash in creation of single-result-ops with in-place folds
ClosedPublic

Authored by ftynse on May 6 2020, 8:40 AM.

Details

Summary

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.

Diff Detail

Event Timeline

ftynse created this revision.May 6 2020, 8:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 6 2020, 8:40 AM
rriddle accepted this revision.May 6 2020, 11:09 AM
This revision is now accepted and ready to land.May 6 2020, 11:09 AM
bondhugula accepted this revision.May 6 2020, 11:38 AM
bondhugula added a subscriber: bondhugula.

Great catch and fix! Appreciate the thorough test case.

mlir/test/lib/Dialect/Test/TestDialect.cpp
327

Nit: && "single operand op").

mlir/test/lib/Dialect/Test/TestPatterns.cpp
52

Nit: Exercise, pas exercice comme on dirait en francais ;-)

This revision was automatically updated to reflect the committed changes.