[Mlir-commits] [mlir] [mlir][vector] Add LinearizeVectorToElements	(PR #157740)
    Erick Ochoa Lopez 
    llvmlistbot at llvm.org
       
    Tue Sep  9 13:20:53 PDT 2025
    
    
  
================
@@ -798,6 +798,49 @@ struct LinearizeVectorFromElements final
   }
 };
 
+/// This pattern linearizes the operand in `vector.to_elements` operations
+/// by converting the result type to a 1-D vector while preserving all element
+/// values. The transformation creates a linearized `vector.shape_cast`
+/// followed by a `vector.to_elements`.
+///
+/// Example:
+///
+///     %0:4 = vector.to_elements %v : vector<2x2xf32>
+///
+/// is converted to:
+///
+///     %vector_cast = vector.shape_cast %v : vector<2x2xf32> to vector<4xf32>
+///     %0:4 = vector.to_elements %vector_cast : vector<4xf32>
+///
+struct LinearizeVectorToElements final
+    : public OpConversionPattern<vector::ToElementsOp> {
+  using OpConversionPattern::OpConversionPattern;
+
+  LinearizeVectorToElements(const TypeConverter &typeConverter,
+                            MLIRContext *context, PatternBenefit benefit = 1)
+      : OpConversionPattern(typeConverter, context, benefit) {}
+
+  LogicalResult
+  matchAndRewrite(vector::ToElementsOp toElementsOp, OpAdaptor adaptor,
----------------
amd-eochoalo wrote:
Happy to use the adaptor, but I noticed that in the pattern above adaptor is not used. To continue the style of the pattern above I also did not use it here.
https://github.com/llvm/llvm-project/pull/157740
    
    
More information about the Mlir-commits
mailing list