[Mlir-commits] [mlir] [mlir][vector] Folder: shape_cast(extract) -> extract (PR #146368)

James Newling llvmlistbot at llvm.org
Mon Jun 30 10:57:05 PDT 2025


================
@@ -1696,59 +1696,68 @@ static bool hasZeroDimVectors(Operation *op) {
          llvm::any_of(op->getResultTypes(), hasZeroDimVectorType);
 }
 
+/// All BroadcastOps and SplatOps, and ShapeCastOps that only prepends 1s, are
+/// considered 'broadcastlike'.
+static bool isBroadcastLike(Operation *op) {
+  if (isa<BroadcastOp, SplatOp>(op))
+    return true;
+
+  auto shapeCast = dyn_cast<ShapeCastOp>(op);
+  if (!shapeCast)
+    return false;
+
+  VectorType srcType = shapeCast.getSourceVectorType();
+  ArrayRef<int64_t> srcShape = srcType.getShape();
+  uint64_t srcRank = srcType.getRank();
+  ArrayRef<int64_t> dstShape = shapeCast.getType().getShape();
+  return dstShape.size() <= srcRank && dstShape.take_back(srcRank) == srcShape;
----------------
newling wrote:

> Since this is looking for shape_cast that prepends 1s, shouldn't the destination rank be larger than the source rank? 

Good spot! I introduced this error in an intermediate commit (apologies for squashing commits, I didn't expect any eyes on this until it passed CI). Fixed. 

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


More information about the Mlir-commits mailing list