Skip to content

[mlir][vector] Update ApplyVectorReductionToContractPatternsOp #136699

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

Conversation

banach-space
Copy link
Contributor

This PR removes the use of populateSinkVectorOpsPatterns from the
definition of:

  • transform.apply_patterns.vector.reduction_to_contract

As of #131462, there is now a dedicated transform op for this pattern:

  • transform.apply_patterns.vector.sink_op

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:

  • transform.apply_patterns.vector.sink_op

See the updated test for an example.

This PR removes the use of `populateSinkVectorOpsPatterns` from the
definition of:
  * `transform.apply_patterns.vector.reduction_to_contract`

As of llvm#131462, there is now a dedicated transform op for this pattern:
  * `transform.apply_patterns.vector.sink_op`

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:
  * `transform.apply_patterns.vector.sink_op`

See the updated test for an example.
@llvmbot
Copy link
Member

llvmbot commented Apr 22, 2025

@llvm/pr-subscribers-mlir-sme
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-vector

Author: Andrzej Warzyński (banach-space)

Changes

This PR removes the use of populateSinkVectorOpsPatterns from the
definition of:

  • transform.apply_patterns.vector.reduction_to_contract

As of #131462, there is now a dedicated transform op for this pattern:

  • transform.apply_patterns.vector.sink_op

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:

  • transform.apply_patterns.vector.sink_op

See the updated test for an example.


Full diff: https://github.com/llvm/llvm-project/pull/136699.diff

3 Files Affected:

  • (modified) mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp (-4)
  • (modified) mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir (+1)
  • (modified) mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir (+1)
diff --git a/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp b/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
index 12dcf768dd928..adc1dd437326f 100644
--- a/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
+++ b/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
@@ -67,10 +67,6 @@ void transform::ApplyFoldElementwiseToVectorPatternsOp::populatePatterns(
 void transform::ApplyVectorReductionToContractPatternsOp::populatePatterns(
     RewritePatternSet &patterns) {
   vector::populateVectorReductionToContractPatterns(patterns);
-
-  // TODO: As we now have a dedicated transform for
-  // `populateSinkVectorOpsPatterns` we can remove it from here.
-  vector::populateSinkVectorOpsPatterns(patterns);
 }
 
 void transform::ApplyLowerCreateMaskPatternsOp::populatePatterns(
diff --git a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir
index 29b0bc0c19606..ad7dbb9f7e126 100644
--- a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir
+++ b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir
@@ -79,6 +79,7 @@ module attributes {transform.with_named_sequence} {
       transform.apply_patterns.vector.lower_masked_transfers
       transform.apply_patterns.vector.transfer_permutation_patterns
       transform.apply_patterns.vector.reduction_to_contract
+      transform.apply_patterns.vector.sink_ops
     } : !transform.any_op
 
     // Step 5: Lower vector.contract to vector.outerproduct. Also drop unit
diff --git a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir
index 78815a38612e9..71798a6affbbc 100644
--- a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir
+++ b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir
@@ -94,6 +94,7 @@ module attributes {transform.with_named_sequence} {
       transform.apply_patterns.vector.lower_masked_transfers
       transform.apply_patterns.vector.transfer_permutation_patterns
       transform.apply_patterns.vector.reduction_to_contract
+      transform.apply_patterns.vector.sink_ops
     } : !transform.any_op
 
     // Step 5: Lower vector.contract to vector.outerproduct. Also drop unit

@llvmbot
Copy link
Member

llvmbot commented Apr 22, 2025

@llvm/pr-subscribers-mlir-linalg

Author: Andrzej Warzyński (banach-space)

Changes

This PR removes the use of populateSinkVectorOpsPatterns from the
definition of:

  • transform.apply_patterns.vector.reduction_to_contract

As of #131462, there is now a dedicated transform op for this pattern:

  • transform.apply_patterns.vector.sink_op

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:

  • transform.apply_patterns.vector.sink_op

See the updated test for an example.


Full diff: https://github.com/llvm/llvm-project/pull/136699.diff

3 Files Affected:

  • (modified) mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp (-4)
  • (modified) mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir (+1)
  • (modified) mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir (+1)
diff --git a/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp b/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
index 12dcf768dd928..adc1dd437326f 100644
--- a/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
+++ b/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
@@ -67,10 +67,6 @@ void transform::ApplyFoldElementwiseToVectorPatternsOp::populatePatterns(
 void transform::ApplyVectorReductionToContractPatternsOp::populatePatterns(
     RewritePatternSet &patterns) {
   vector::populateVectorReductionToContractPatterns(patterns);
-
-  // TODO: As we now have a dedicated transform for
-  // `populateSinkVectorOpsPatterns` we can remove it from here.
-  vector::populateSinkVectorOpsPatterns(patterns);
 }
 
 void transform::ApplyLowerCreateMaskPatternsOp::populatePatterns(
diff --git a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir
index 29b0bc0c19606..ad7dbb9f7e126 100644
--- a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir
+++ b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir
@@ -79,6 +79,7 @@ module attributes {transform.with_named_sequence} {
       transform.apply_patterns.vector.lower_masked_transfers
       transform.apply_patterns.vector.transfer_permutation_patterns
       transform.apply_patterns.vector.reduction_to_contract
+      transform.apply_patterns.vector.sink_ops
     } : !transform.any_op
 
     // Step 5: Lower vector.contract to vector.outerproduct. Also drop unit
diff --git a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir
index 78815a38612e9..71798a6affbbc 100644
--- a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir
+++ b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/multi-tile-matmul-mixed-types.mlir
@@ -94,6 +94,7 @@ module attributes {transform.with_named_sequence} {
       transform.apply_patterns.vector.lower_masked_transfers
       transform.apply_patterns.vector.transfer_permutation_patterns
       transform.apply_patterns.vector.reduction_to_contract
+      transform.apply_patterns.vector.sink_ops
     } : !transform.any_op
 
     // Step 5: Lower vector.contract to vector.outerproduct. Also drop unit

@banach-space banach-space merged commit e512833 into llvm:main Apr 22, 2025
17 checks passed
@banach-space banach-space deleted the andrzej/vector/update_vec_reduction_to_contract branch April 22, 2025 19:24
banach-space added a commit to banach-space/llvm-project that referenced this pull request Apr 23, 2025
banach-space added a commit that referenced this pull request Apr 23, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…136699)

This PR removes the use of `populateSinkVectorOpsPatterns` from the
definition of:
  * `transform.apply_patterns.vector.reduction_to_contract`

As of llvm#131462, there is now a dedicated transform op for this pattern:
  * `transform.apply_patterns.vector.sink_op`

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:
  * `transform.apply_patterns.vector.sink_op`

See the updated test for an example.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…136699)

This PR removes the use of `populateSinkVectorOpsPatterns` from the
definition of:
  * `transform.apply_patterns.vector.reduction_to_contract`

As of llvm#131462, there is now a dedicated transform op for this pattern:
  * `transform.apply_patterns.vector.sink_op`

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:
  * `transform.apply_patterns.vector.sink_op`

See the updated test for an example.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…136699)

This PR removes the use of `populateSinkVectorOpsPatterns` from the
definition of:
  * `transform.apply_patterns.vector.reduction_to_contract`

As of llvm#131462, there is now a dedicated transform op for this pattern:
  * `transform.apply_patterns.vector.sink_op`

Given that, we should now use the new TD op directly instead of relying
on unrelated TD ops to include it.

NOTE TO DOWNSTREAM USERS:
Please add the following to your TD scripts:
  * `transform.apply_patterns.vector.sink_op`

See the updated test for an example.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants