[Mlir-commits] [mlir] [mlir] Canonicalization pattern for 'shape.shape_of' (PR #98531)
Spenser Bauman
llvmlistbot at llvm.org
Mon Jul 15 06:50:28 PDT 2024
================
@@ -1585,13 +1585,25 @@ OpFoldResult ReshapeOp::fold(FoldAdaptor adaptor) {
getResult().getType()))
return reshapedSource;
+ // If the producer of operand 'source' is another 'tensor.reshape' op, use the
+ // producer's input instead as the original tensor to reshape. This could
+ // render such producer dead code.
+ if (auto reshapeOpProducer = getSource().getDefiningOp<ReshapeOp>()) {
+ setOperand(0, reshapeOpProducer.getSource());
----------------
sabauma wrote:
This might be clearer/safer using the named accessor, rather than `setOperand`:
```cpp
getSourceMutable().assign(reshapeOpProducer.getSource());
```
https://github.com/llvm/llvm-project/pull/98531
More information about the Mlir-commits
mailing list