This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Fix affine.for unroll for multi-result upper bound maps
ClosedPublic

Authored by bondhugula on Nov 26 2021, 7:10 PM.

Details

Summary

Fix affine.for unroll for multi-result upper bound maps: these can't be
unrolled/unroll-and-jammed in cases where the trip count isn't known to
be a multiple of the unroll factor.

Fix and clean up repeated/unnecessary checks/comments at helper callees.

Also, fix clang-tidy variable naming warnings and redundant includes.

Diff Detail

Event Timeline

bondhugula created this revision.Nov 26 2021, 7:10 PM
bondhugula requested review of this revision.Nov 26 2021, 7:10 PM

Thanks, Uday. LGTM but I'm not super familiar with the loop unrolling pass. I'll defer the approval to someone with more expertise in the pass.

Looks good, minor request to complicate the test case, thanks!

mlir/lib/Transforms/Utils/LoopUtils.cpp
1177–1178

Comment needs an update ?

mlir/test/Dialect/Affine/unroll.mlir
585

Can you please complicate the test case more ?

func @unroll_multi_upper_bound(%arg0 : index) {
  affine.for %i = 0 to min affine_map<()[s0] -> (8 * s0, 12 * s0)>()[%arg0] {
    "test.foo"(%i) : (index) -> ()
  }
  // UNROLL-BY-4: affine.for %{{.*}} = 0 to min #map{{.*}}() step 4
  // UNROLL-BY-4-NOT: affine.for
  return
}
This revision is now accepted and ready to land.Nov 29 2021, 9:35 AM

Looks great, could you add an unrolling test where the lower bound map has multiple results and the trip count is a multiple of the unroll factor? Thanks.

bondhugula marked an inline comment as done.Nov 29 2021, 3:20 PM

Looks great, could you add an unrolling test where the lower bound map has multiple results and the trip count is a multiple of the unroll factor? Thanks.

This is a good point. Although this revision enables go past that unnecessary initial check, the unrolling of loops with multi-result lower bound maps where the trip count is a multiple of unroll factor still won't happen since getTripCountMapAndOperands isn't yet extended for multi-result lower bound maps. There is this in LoopAnalysis.cpp:

53   if (lbMap.getNumResults() != 1) {
54     *tripCountMap = AffineMap();
55     return;
56   }

There isn't a reason for this restriction and this has been a TODO.

But I've added a test case and marked it TODO.

mlir/lib/Transforms/Utils/LoopUtils.cpp
1177–1178

This is already covered in the comment below and so I didn't want to duplicate the specific subset where it isn't possible.

mlir/test/Dialect/Affine/unroll.mlir
585

Good point, done.

bondhugula marked 2 inline comments as done.

Address review comments.

ayzhuang accepted this revision.Nov 29 2021, 3:40 PM

LGTM, thanks.