@@ -305,28 +305,27 @@ struct MergeAssumingOpsPattern : public OpRewritePattern<shape::AssumingOp> {
305305 }
306306};
307307
308- // Eliminate extent tensor casts . Instead, produce the concrete extent tensor
308+ // Eliminate casted extent tensors . Instead, produce the concrete extent tensor
309309// type where possible.
310- template <typename OpTy>
311- struct CanonicalizeCastedExtentTensorOpPattern
310+ struct CanonicalizeCastedShapeOfOpPattern
312311 : public OpRewritePattern<tensor::CastOp> {
313312 using OpRewritePattern<tensor::CastOp>::OpRewritePattern;
314313
315314 LogicalResult matchAndRewrite (tensor::CastOp op,
316315 PatternRewriter &rewriter) const override {
317- // Only merge tensor cast into a producer op if we know it supports it .
318- auto producer_op = op.source ().getDefiningOp <OpTy >();
319- if (!producer_op ) return failure ();
316+ // Only merge tensor cast into `shape_of` ops .
317+ auto shape_of_op = op.source ().getDefiningOp <shape::ShapeOfOp >();
318+ if (!shape_of_op ) return failure ();
320319
321320 // Desired type must be an extent tensor type.
322321 auto result_ty = op.getType ().dyn_cast <RankedTensorType>();
323322 if (!result_ty || result_ty.getRank () != 1 ||
324323 !result_ty.getElementType ().isIndex ())
325324 return failure ();
326325
327- rewriter.replaceOpWithNewOp <OpTy >(op, result_ty, producer_op-> getOperands () ,
328- producer_op-> getAttrs ());
329- if (producer_op ->getUses ().empty ()) rewriter.eraseOp (producer_op );
326+ rewriter.replaceOpWithNewOp <shape::ShapeOfOp >(op, result_ty,
327+ shape_of_op. arg ());
328+ if (shape_of_op ->getUses ().empty ()) rewriter.eraseOp (shape_of_op );
330329 return success ();
331330 }
332331};
@@ -402,8 +401,7 @@ void PopulateMoveUpDynamicBroadcastsForFusionPatterns(
402401 MLIRContext *context, OwningRewritePatternList *patterns) {
403402 // clang-format off
404403 patterns->insert <
405- CanonicalizeCastedExtentTensorOpPattern<shape::ShapeOfOp>,
406- CanonicalizeCastedExtentTensorOpPattern<shape::BroadcastOp>,
404+ CanonicalizeCastedShapeOfOpPattern,
407405 InlineBroadcastedShapeOperandsPattern<shape::CstrBroadcastableOp>,
408406 MergeAssumingOpsPattern,
409407 MoveIntoAssumingOpPattern<shape::ShapeOfOp>,
0 commit comments