Eliminate empty shapes from the operands, partially fold all constant shape
operands, and fix normal folding.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Nice. Some comments to further generalize.
mlir/lib/Dialect/Shape/IR/Shape.cpp | ||
---|---|---|
490 | This could be generalized to broadcasting all constant arguments. It would simplify the IR a little. Not sure it is worth it. | |
492 | An alternative would be to filter all empty shapes, which simplifies the broadcast, as well. |
mlir/lib/Dialect/Shape/IR/Shape.cpp | ||
---|---|---|
492 | I mostly agree with this. I think it would also make the above code easier to read by not requiring this stateful onlyPotentiallyNonEmptyShape. My only concern with doing this in fold though is that I could imagine being confused if I create an op, and operands are missing due to folding upon Op creation. |
Address comments
mlir/lib/Dialect/Shape/IR/Shape.cpp | ||
---|---|---|
492 | I'm not sure if folding can/should create new operations anyways. If we were to replace a shape.broadcast op with a simplified version that sounds more like a canonicalization. |
Arc diff doesn't update the description, so FYI in case you didn't, update to mention the additional features you added.
A few places you checked that *.isa<ShapeType>() == *.isa<ShapeType>(). Out of curiosity, why not just compare the types?
mlir/lib/Dialect/Shape/IR/Shape.cpp | ||
---|---|---|
473 | Is this supposed to be ShapedType and ShapeType? | |
539–542 | nit: I think you can also replace this with something like nonEmptyShapeOperands = llvm::make_filter_range(op->getOperands(), isNonEmptyShape) | |
561–563 | Is this change actually necessary for a reason that you know, or are you just being extra cautious? | |
572 | nit: maybe a different name like foldedConstantShape? I was confused at first thinking this should be a Vector of Values based on the name. | |
575–576 | nit: if (auto constShape = shape.getDefiningOp<ConstShapeOp>()) { | |
590 | Alternatively you could just check to see if foldedConstantOperands is empty. |
Is this supposed to be ShapedType and ShapeType?