This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add multi-level AffineMinSCF canonicalization support
AbandonedPublic

Authored by nicolasvasilache on Jun 17 2020, 8:56 AM.

Details

Summary

[mlir] Add multi-level AffineMinSCF floding support

This revision allows chains of AffineMinOp that depend on SCF induction variables to fold. This allows the foldings of IR such as:

#map1 = affine_map<(d0) -> (128, -d0 + 192)>
#map2 = affine_map<(d0, d1) -> (16, d0 - d1)>

scf.parallel (%i) = (%c0) to (%c192) step (%c128) {
  %1 = affine.min #map1(%i)
  scf.for %j = %c0 to %1 step %c16 {
    %2 = affine.min #map2(%1, %j)
    %3 = index_cast %2: index to i64
    store %3, %A[]: memref<i64>

into:

#map1 = affine_map<(d0) -> (128, -d0 + 192)>

scf.parallel (%arg1) = (%c0) to (%c192) step (%c128) {
  %0 = affine.min #map1(%arg1)
  scf.for %arg2 = %c0 to %0 step %c16 {
    store %c16_i64, %arg0[] : memref<i64>

Note that handling chains is required because 192 % 128 != 0 but 192 % 16 == 0.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald Transcript

This revision allows chains of AffineMinOp that depend on SCF induction variables to canonicalize.

to canonicalize -> to fold.

What's map1 and map3 in the commit summary example?

nicolasvasilache edited the summary of this revision. (Show Details)Jun 18 2020, 4:58 AM
nicolasvasilache edited the summary of this revision. (Show Details)
ftynse accepted this revision.Jun 18 2020, 5:15 AM
ftynse added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
310

Nit: can we invert the condition and remove one indentaion level?

311

Nit: llvm::to_vector

339

Nit: consider adding a debug print here, we may want to know when we hit pathological cases

This revision is now accepted and ready to land.Jun 18 2020, 5:15 AM
nicolasvasilache marked 3 inline comments as done.

Address comments.

bondhugula requested changes to this revision.Jun 18 2020, 8:17 AM
bondhugula added inline comments.
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
509

outerloops -> outer loops

Again, canonicalize -> fold?

519

It's not %1 that canonicalizes, but it's the affine.min that folds.

mlir/include/mlir/IR/AffineExpr.h
137

Should this just be shiftSymbols or replaceByShiftedSymbols?

mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
328

Comment please here.

mlir/lib/IR/AffineExpr.cpp
129

Missing assertion on valid numDims values.

mlir/test/Dialect/Linalg/fold-affine-min-scf.mlir
120

Please add a one line comment on what it's testing.

124

Missing CHECK-LABEL.

133

Nit: indent by two for readability.

145

fold

This revision now requires changes to proceed.Jun 18 2020, 8:17 AM
limo1996 requested changes to this revision.Jun 30 2020, 5:34 AM
limo1996 added a subscriber: limo1996.
limo1996 added inline comments.
mlir/lib/IR/AffineExpr.cpp
143

This should be getAffineSymbolExpr

nicolasvasilache abandoned this revision.Sep 27 2021, 3:12 AM