This is an archive of the discontinued LLVM Phabricator instance.

[mlir][scf] More WhileOp canonicalizations
ClosedPublic

Authored by Hardcode84 on Mar 16 2023, 11:47 AM.

Details

Summary

Remove duplicated ConditonOp args, remove unused init/yield args

Diff Detail

Event Timeline

Hardcode84 created this revision.Mar 16 2023, 11:47 AM
Hardcode84 requested review of this revision.Mar 16 2023, 11:47 AM
ftynse accepted this revision.Apr 12 2023, 6:12 AM
ftynse added inline comments.
mlir/lib/Dialect/SCF/IR/SCF.cpp
3811

Nit: prefer notifyMatchFailure with an explanatory message.

3815

Nit: feel free to add builder overloads that don't take callbacks.

3826

auto &&, enumerate will eventually return references.

3863

Ditto for auto &&.

This revision is now accepted and ready to land.Apr 12 2023, 6:12 AM

rebase, review comments

Hardcode84 marked 3 inline comments as done.Apr 12 2023, 7:13 AM
Hardcode84 added inline comments.
mlir/lib/Dialect/SCF/IR/SCF.cpp
3815

Will do in separate review

This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Apr 12 2023, 10:39 PM
mlir/lib/Dialect/SCF/IR/SCF.cpp
3796

This isn't used before the early exit, can you move this closer to its use?

3798

There is a getConditionOp() method on WhileOp.

3801

Shall we reserve() these before the loop?

I'm also not sure if we could do better to filter out the "do nothing case" (which is the most important one to optimize for).
For example we could do a first pass with a SmallPtrSet just to check if there are duplicated argument and bail out immediately?

3841

mergeBlocks is pretty expensive: it is possible to steal the block as the new body of the region instead? Isn't the destination block empty?
Actually mergeBlocks() should be optimized for the case where the destination block is empty! (maybe it is already?)

mlir/test/Dialect/SCF/canonicalize.mlir
1249

Do we need that many checks? Seems like a CHECK-NOT: test.val1 would do the job here, potentially after a CHECK: scf.while : () -> i32. The rest seems spurious.

There is a another issue, there is an existing WhileUnusedArg pattern, but it is not added anywhere, and test which was supposed to check it passes because of unrelated pattern. I'll do another PR to clean thing up

Hardcode84 added inline comments.Apr 13 2023, 9:17 AM
mlir/test/Dialect/SCF/canonicalize.mlir
1249

I still want to check general structure of the loop is preserved.

Hardcode84 added inline comments.Apr 13 2023, 9:32 AM
mlir/lib/Dialect/SCF/IR/SCF.cpp
3841

mergeBlocks just doing replaceAllUsesWith + getOperations().splice, is it really that expensive?