[Mlir-commits] [mlir] [MLIR][Tensor] Perform shape inference via in-place modification (NFC) (PR #111593)

Han-Chung Wang llvmlistbot at llvm.org
Tue Oct 8 14:58:57 PDT 2024


================
@@ -4332,21 +4332,24 @@ LogicalResult PackOp::canonicalize(PackOp packOp, PatternRewriter &rewriter) {
           rewriter.create<tensor::CastOp>(loc, newSrcType, packOp.getSource());
     }
     Value dest = packOp.getDest();
+    Type originalResultType = dest.getType();
     if (destShape != packOp.getDestType().getShape()) {
       auto newDestType = packOp.getDestType().clone(destShape);
       dest =
           rewriter.create<tensor::CastOp>(loc, newDestType, packOp.getDest());
     }
----------------
hanhanW wrote:

nit: we can use a boolean, then we save one comparison.

```suggestion
    bool needNewDest = destShape != packOp.getDestType().getShape();
    if (needNewDest) {
      auto newDestType = packOp.getDestType().clone(destShape);
      dest =
          rewriter.create<tensor::CastOp>(loc, newDestType, packOp.getDest());
    }
    // ...
    // Insert a cast if needed.
    if (needNewDest) {
      // ...
    }
```

https://github.com/llvm/llvm-project/pull/111593


More information about the Mlir-commits mailing list