Skip to content

[Will be divided up] Vector linearization via strided ops #142672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

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

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