This is an archive of the discontinued LLVM Phabricator instance.

[mlir][SCF] Remove empty else blocks of `scf.if` operations.
ClosedPublic

Authored by mravishankar on Jun 14 2021, 3:30 PM.

Diff Detail

Event Timeline

mravishankar created this revision.Jun 14 2021, 3:30 PM
mravishankar requested review of this revision.Jun 14 2021, 3:30 PM
hanchung added inline comments.Jun 14 2021, 3:43 PM
mlir/lib/Dialect/SCF/SCF.cpp
1384–1385

Does !llvm::hasSingleElement(*elseBlock) work? I thought it should be something like elseBlock->begin() != elseBlock->end()? It could have two or more operations in the else branch right?

1389

They are probably no difference in this case, but I would prefer to use replaceOp here.

mlir/test/Dialect/SCF/canonicalize.mlir
492–494

Revert this part?

mravishankar added inline comments.Jun 14 2021, 10:09 PM
mlir/lib/Dialect/SCF/SCF.cpp
1384–1385

The pattern is trying to remove and empty else block. So basically the case where the else block has a single scf.yield operation (it will always have an scf.yield op). If that is not the case, then the else block is kept as is.

ftynse accepted this revision.Jun 15 2021, 1:19 AM

LGTM with comments addressed.

This revision is now accepted and ready to land.Jun 15 2021, 1:19 AM
hanchung added inline comments.Jun 15 2021, 12:16 PM
mlir/lib/Dialect/SCF/SCF.cpp
1384–1385

I see, thanks for the explanation.

mravishankar marked 3 inline comments as done.

Rebase and address comments

This revision was landed with ongoing or failed builds.Jun 15 2021, 3:07 PM
This revision was automatically updated to reflect the committed changes.