[Mlir-commits] [mlir] 8c07d5e - [mlir][vector] don't emit non-rank 1 masked load and store (#67656)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 28 05:06:54 PDT 2023
Author: Cullen Rhodes
Date: 2023-09-28T13:06:50+01:00
New Revision: 8c07d5ec6d4b7c3fe66d2c45630d0a0741b5854d
URL: https://github.com/llvm/llvm-project/commit/8c07d5ec6d4b7c3fe66d2c45630d0a0741b5854d
DIFF: https://github.com/llvm/llvm-project/commit/8c07d5ec6d4b7c3fe66d2c45630d0a0741b5854d.diff
LOG: [mlir][vector] don't emit non-rank 1 masked load and store (#67656)
The following patterns
- TransferReadToVectorLoadLowering
- TransferWriteToVectorStoreLowering
attempt to generate invalid vector.maskedload and vector.maskedstore ops
for non rank-1 vector types. These ops operate on 1-D vectors. This
patch adds a check to prevent this.
Added:
Modified:
mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp
mlir/test/Dialect/Vector/vector-transfer-to-vector-load-store.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp
index bc3e47a71b43097..6df85978a7e8601 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp
@@ -455,6 +455,12 @@ struct TransferReadToVectorLoadLowering
// Create vector load op.
Operation *loadOp;
if (read.getMask()) {
+ if (read.getVectorType().getRank() != 1)
+ // vector.maskedload operates on 1-D vectors.
+ return rewriter.notifyMatchFailure(
+ read, "vector type is not rank 1, can't create masked load, needs "
+ "VectorToSCF");
+
Value fill = rewriter.create<vector::SplatOp>(
read.getLoc(), unbroadcastedVectorType, read.getPadding());
loadOp = rewriter.create<vector::MaskedLoadOp>(
@@ -598,6 +604,15 @@ struct TransferWriteToVectorStoreLowering
diag << "out of bounds dim: " << write;
});
if (write.getMask()) {
+ if (write.getVectorType().getRank() != 1)
+ // vector.maskedstore operates on 1-D vectors.
+ return rewriter.notifyMatchFailure(
+ write.getLoc(), [=](Diagnostic &diag) {
+ diag << "vector type is not rank 1, can't create masked store, "
+ "needs VectorToSCF: "
+ << write;
+ });
+
rewriter.replaceOpWithNewOp<vector::MaskedStoreOp>(
write, write.getSource(), write.getIndices(), write.getMask(),
write.getVector());
diff --git a/mlir/test/Dialect/Vector/vector-transfer-to-vector-load-store.mlir b/mlir/test/Dialect/Vector/vector-transfer-to-vector-load-store.mlir
index a6ecc6d6e860641..e0df01b6735445e 100644
--- a/mlir/test/Dialect/Vector/vector-transfer-to-vector-load-store.mlir
+++ b/mlir/test/Dialect/Vector/vector-transfer-to-vector-load-store.mlir
@@ -367,3 +367,28 @@ transform.sequence failures(propagate) {
transform.apply_patterns.vector.transfer_permutation_patterns
} : !transform.op<"func.func">
}
+
+// -----
+
+/// Verify vector.maskedload and vector.maskedstore ops that operate on 1-D
+/// vectors aren't generated for rank > 1 transfer ops.
+
+// CHECK-LABEL: @transfer_2D_masked
+// CHECK-NOT: vector.maskedload
+// CHECK-NOT: vector.maskedstore
+// CHECK: vector.transfer_read
+// CHECK: vector.transfer_write
+func.func @transfer_2D_masked(%mem : memref<?x?xf32>, %mask : vector<2x4xi1>) -> vector<2x4xf32> {
+ %c0 = arith.constant 0 : index
+ %pad = arith.constant 0.0 : f32
+ %res = vector.transfer_read %mem[%c0, %c0], %pad, %mask {in_bounds = [true, true]} : memref<?x?xf32>, vector<2x4xf32>
+ vector.transfer_write %res, %mem[%c0, %c0], %mask {in_bounds = [true, true]} : vector<2x4xf32>, memref<?x?xf32>
+ return %res : vector<2x4xf32>
+}
+
+transform.sequence failures(propagate) {
+^bb1(%func_op: !transform.op<"func.func">):
+ transform.apply_patterns to %func_op {
+ transform.apply_patterns.vector.lower_transfer max_transfer_rank = 2
+ } : !transform.op<"func.func">
+}
More information about the Mlir-commits
mailing list