[Mlir-commits] [mlir] [mlir][vector] Move extract_strided_slice canonicalization to folding (PR #135676)
James Newling
llvmlistbot at llvm.org
Tue Apr 15 16:30:29 PDT 2025
================
@@ -3717,6 +3717,58 @@ OpFoldResult ExtractStridedSliceOp::fold(FoldAdaptor adaptor) {
return getVector();
if (succeeded(foldExtractStridedOpFromInsertChain(*this)))
return getResult();
+
+ // All subsequent successful folds require a constant input.
+ Attribute foldInput = adaptor.getVector();
+ if (!foldInput)
+ return {};
+
+ // ExtractStridedSliceOp(splat ConstantOp) -> ConstantOp.
+ if (auto splat = llvm::dyn_cast<SplatElementsAttr>(foldInput))
+ DenseElementsAttr::get(getType(), splat.getSplatValue<Attribute>());
+
+ // ExtractStridedSliceOp(non-splat ConstantOp) -> ConstantOp.
+ if (auto dense = llvm::dyn_cast<DenseElementsAttr>(foldInput)) {
+ // TODO: Handle non-unit strides when they become available.
----------------
newling wrote:
Will do.
https://github.com/llvm/llvm-project/pull/135676
More information about the Mlir-commits
mailing list