Skip to content

Conversation

@newling
Copy link
Contributor

@newling newling commented Jun 3, 2025

This is the end point of a few changes I have made to vector linearization. I plan to split this into multiple PRs, but posting here as a reference.

Changes/improvements:

  • Make all patterns optional
  • Option to lower to 1D strided ops (although 1D shuffle remains default)
  • Support for scalar insert/extract

@github-actions
Copy link

github-actions bot commented Jun 3, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- mlir/include/mlir/Dialect/Vector/Transforms/VectorLinearize.h mlir/test/lib/Dialect/Vector/TestVectorLinearize.cpp mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h mlir/lib/Dialect/Vector/IR/VectorOps.cpp mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp mlir/tools/mlir-opt/mlir-opt.cpp
View the diff from clang-format here.
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 359b2ba09..014ca67d6 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -5726,20 +5726,20 @@ OpFoldResult ShapeCastOp::fold(FoldAdaptor adaptor) {
 
   VectorType resultType = getType();
 
-
-  // y = shape_cast(shape_cast(shape_cast(x))) 
+  // y = shape_cast(shape_cast(shape_cast(x)))
   //    -> shape_cast(x) # if x and y different types
   //    -> x             # if x and y same type
   // Value newSource  = getSource();
   ShapeCastOp parent = *this;
-  while (auto precedingShapeCast = parent.getSource().getDefiningOp<ShapeCastOp>()) {
+  while (auto precedingShapeCast =
+             parent.getSource().getDefiningOp<ShapeCastOp>()) {
     parent = precedingShapeCast;
   }
 
   if (parent.getSource().getType() == resultType)
     return parent.getSource();
 
-  if (parent != *this){
+  if (parent != *this) {
     setOperand(parent.getSource());
     return getResult();
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant