[mlir] add canonicalization patterns for trivial SCF 'for' and 'if'
authorAlex Zinenko <zinenko@google.com>
Fri, 20 Nov 2020 17:50:52 +0000 (18:50 +0100)
committerAlex Zinenko <zinenko@google.com>
Fri, 20 Nov 2020 18:04:39 +0000 (19:04 +0100)
commit18d0f7d5c3b0f8fae2cb6cd5db3977df26e3533f
tree08cbe19c94627e4e48ad4aaf4ca4afded9bd1ae4
parentdbcc69217a3f6b41cbf6e5b30c9a0ee9d3dfe0b4
[mlir] add canonicalization patterns for trivial SCF 'for' and 'if'

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.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D91865
mlir/lib/Dialect/SCF/SCF.cpp
mlir/test/Dialect/SCF/canonicalize.mlir