This change extends the ReplaceUnitExtents pattern so that users can choose between of two strategies for generating rank reductions:
- CollapseShapeOp / ExpandShapeOp (was already implemented but code was cleaned up; default strategy)
- rank-reducing ExtractSliceOp / InsertSliceOp
Also add helper functions to the memref dialect that we already have on the tensor dialect: getMixedSizes, createCanonicalRankReducingSubViewOp, rankReduceIfNeeded.
Nit: you can origOutput.getType().cast<RankedTensorType>(); and drop the assert.
Also you could just move the auto with cast from below, here.