Skip to content

[Matrix] Optimize shuffle extracts with ShapeInfo #142276

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

Closed
wants to merge 1 commit into from

Conversation

jroelofs
Copy link
Contributor

When a shuffle extracts a vector that we have as part of the ShapeInfo for a Matrix (i.e. one column of a column-major matrix, or one row of a row-major matrix), replace the shuffle with that vector during lowering.

When a shuffle extracts a vector that we have as part of the ShapeInfo for a
Matrix (i.e. one column of a column-major matrix, or one row of a row-major
matrix), replace the shuffle with that vector during lowering.
%inv = call <9 x double> @llvm.matrix.column.major.load(ptr %in, i64 3, i1 1, i32 3, i32 3)
%row = shufflevector <9 x double> %inv, <9 x double> poison, <3 x i32> <i32 0, i32 3, i32 6>
ret <3 x double> %row
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: needs quite a few more tests.

@jroelofs
Copy link
Contributor Author

Leaving this as a draft for now. It doesn't seem to help much, I think possibly because instcombine can already do this.

Copy link

⚠️ 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 -- llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index 93d56a9a7..8ecbb88a3 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -1354,7 +1354,7 @@ public:
     for (int I = 1, E = Mask.size(); I != E; ++I) {
       if (Mask[I] == PoisonMaskElem)
         return false;
-      if (Mask[I-1] + 1 != Mask[I])
+      if (Mask[I - 1] + 1 != Mask[I])
         return false;
     }
 

@jroelofs jroelofs closed this Jun 2, 2025
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