This is an archive of the discontinued LLVM Phabricator instance.

[mlir] add canonicalization patterns for trivial SCF 'for' and 'if'
ClosedPublic

Authored by ftynse on Nov 20 2020, 5:43 AM.

Details

Summary

Add canoncalization patterns to remove zero-iteration 'for' loops, replace
single-iteration 'for' loops with their bodies; remove known-false conditionals
with no 'else' branch and replace conditionals with known value by the
respective region. Although similar transformations are performed at the CFG
level, not all flows reach that level, e.g., the GPU flow may want to remove
single-iteration loops before deciding on loop mapping to thread dimensions.

Diff Detail

Event Timeline

ftynse created this revision.Nov 20 2020, 5:43 AM
ftynse requested review of this revision.Nov 20 2020, 5:43 AM
herhut accepted this revision.Nov 20 2020, 6:49 AM

Nice, thanks!

mlir/lib/Dialect/SCF/SCF.cpp
526

It would be nice to also handle the case where op.lowerBound() == op.upperBound(). Not in this patch, though.

mlir/test/Dialect/SCF/canonicalize.mlir
254

Could you test with a step other than 1?

This revision is now accepted and ready to land.Nov 20 2020, 6:49 AM
ftynse updated this revision to Diff 306720.Nov 20 2020, 9:51 AM
ftynse marked an inline comment as done.

Address review.

mlir/lib/Dialect/SCF/SCF.cpp
526

Will do.

This revision was landed with ongoing or failed builds.Nov 20 2020, 10:04 AM
This revision was automatically updated to reflect the committed changes.