This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Update OpDSL to use the newly introduced min and max ops.
ClosedPublic

Authored by gysit on Oct 5 2021, 11:10 AM.

Details

Summary

Implement min and max using the newly introduced std operations instead of relying on compare and select.

Diff Detail

Event Timeline

gysit created this revision.Oct 5 2021, 11:10 AM
gysit requested review of this revision.Oct 5 2021, 11:10 AM
gysit updated this revision to Diff 377319.Oct 5 2021, 11:36 AM

Fix one more test.

Hey Tobias! Thanks for addressing this. Just one comment.

Thanks,
Diego

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
283

I think we can't assume that max/min ops will always be signed for integers (or maybe I'm missing something?). I fixed similar bugs here: https://reviews.llvm.org/D110854. Given that Linalg signedness is signless, we can't retrieve the sign information from the integer type so we would have to pass a flag for it...

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
283

There is a can of worms here. Like the rest of the things at this level, Linalg is signless, and any signed/unsigned semantics needs to come from the op (name and/or attribute of some kind).

There is actually already a bias towards signed that we should address somewhere: on extension/truncation between types, the cast is done signed. We could actually extend that tradition and make the default form of all of these ops be signed, providing unsigned variants as well as needed (i.e. max_unsigned, cast_unsigned). This would tie the signedness precisely to the definition of the op. The consequence of this decision would be that full support for unsigned will result in duplicate ops (or some other as yet to be invented mechanism to switch). I'm not convinced that would be such a bad outcome, personally -- and it is consistent with the rest of the system.

gysit added inline comments.Oct 5 2021, 1:55 PM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
283

Yes so for everything is signed. I think we can either add unsigned signatures or we use a boolean attribute to control signedness. The later sounds a bit more involved...

I would suggest this is a problem we can solve in a follow up revision? Let me know if you have preferences regarding unsigned signature / attribute parameter.

dcaballe accepted this revision.Oct 5 2021, 2:20 PM
dcaballe added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
283

We could actually extend that tradition and make the default form of all of these ops be signed, providing unsigned variants as well as needed

Are you referring to the OpDSL? Note that internally (MLIR core dialects) we already follow that approach for those integer ops where the sign matters. For example, we have MaxSIOp for signed max and MaxUIOp for unsigned max. Same for min. We have similar versions for division, remainder, zero extension, signed extension, etc.

I would suggest this is a problem we can solve in a follow up revision? Let me know if you have preferences regarding unsigned signature / attribute parameter.

Yes, it sounds good! Any of them would work for me.

This revision is now accepted and ready to land.Oct 5 2021, 2:20 PM
gysit added inline comments.Oct 5 2021, 11:41 PM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
283

Are you referring to the OpDSL?

Yes OpDSL uses signed everywhere. Inspired by Python :)