Implement min and max using the newly introduced std operations instead of relying on compare and select.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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. |
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. |
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | ||
---|---|---|
283 |
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.
Yes, it sounds good! Any of them would work for me. |
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | ||
---|---|---|
283 |
Yes OpDSL uses signed everywhere. Inspired by Python :) |
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...