This is an archive of the discontinued LLVM Phabricator instance.

[mlir] add scf.if op canonicalization pattern that removes unused results
ClosedPublic

Authored by gysit on Oct 8 2020, 1:18 AM.

Details

Summary

The patch adds a canonicalization pattern that removes the unused results of scf.if operation. As a result, cse may remove unused computations in the then and else regions of the scf.if operation.

Diff Detail

Event Timeline

gysit created this revision.Oct 8 2020, 1:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 8 2020, 1:18 AM
gysit requested review of this revision.Oct 8 2020, 1:18 AM
mehdi_amini accepted this revision.Oct 8 2020, 7:16 PM
mehdi_amini added inline comments.
mlir/lib/Dialect/SCF/SCF.cpp
512

Nit: if op -> IfOp

529

Note: operation can have their operands erased in place, seems like it would be possible here.

540

Please early exit: if (usedResults.size() != op.getNumResults()) return failure()

This revision is now accepted and ready to land.Oct 8 2020, 7:16 PM
gysit updated this revision to Diff 297130.Oct 9 2020, 12:01 AM
  • exit early if the pattern does not apply
  • update terminators of then and else bodies in place using the setOperands method
gysit marked 2 inline comments as done.Oct 9 2020, 12:04 AM
gysit added inline comments.
mlir/lib/Dialect/SCF/SCF.cpp
529

Thanks for the hint! I was not aware that the pattern rewriter has this in place update functionality.

gysit updated this revision to Diff 297448.Oct 11 2020, 1:36 AM

update to latest master