[Mlir-commits] [mlir] [MLIR][Vector] Implement transferXXPermutationLowering as MaskableOpRewritePattern (PR #91987)

Hugo Trachino llvmlistbot at llvm.org
Fri May 17 02:33:47 PDT 2024


================
@@ -46,6 +46,52 @@ func.func @permutation_with_mask_xfer_write_scalable(%arg0: vector<4x[8]xi16>, %
     return
 }
 
+// transfer_write in MaskOp case not supported.
+// CHECK-LABEL: func @masked_permutation_xfer_write_fixed_width
+//  CHECK-SAME:        %[[ARG_0:.*]]: tensor<?x?xf32>,
+//  CHECK-SAME:        %[[ARG_1:.*]]: vector<16xf32>,
+//  CHECK-SAME:        %[[IDX:.*]]: index,
+//  CHECK-SAME:        %[[MASK:.*]]: vector<16xi1>
+//       CHECK:   %[[RES:.*]] = vector.mask %[[MASK]] { vector.transfer_write %[[ARG_1]], %[[ARG_0]][%[[IDX]], %[[IDX]]] {{.*}} vector<16xf32>, tensor<?x?xf32> } : vector<16xi1> -> tensor<?x?xf32>
+//       CHECK:   return %[[RES]]
----------------
nujaa wrote:

`permutation_with_mask_xfer_write_fixed_width` indeed does not have `PureTensorSemantics` hence this check.
The `MaskableOpRewritePattern` interface replaces uses of the original op with a value with `RewriterBase::replaceOp(oldOp, newValue)`. Which requires the same amount of newValues than return values in oldOp. `newValue` is normally the return value of the newly generated op.
 In this case, both `oldOp` and the new Op do not have a return value. Hence, there is no `newValue` to replace the oldOp with.
In the case the op does not have a result, the solution might be to have `matchAndRewriteMaskableOp` return `Value()` to differentiate it from `failure()` and update MaskableOpRewritePattern::matchAndRewrite so it handles ops with no result.

e.g. : 
`mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h:155`
```
FailureOr<Value> newOp =
    matchAndRewriteMaskableOp(sourceOp, maskOp, rewriter);
if (failed(newOp))
  return failure();
////////// To add
// We could also check newOp == Value() but not sure it is necessary.
if(rootOp->getNumResults() == 0)
  eraseOp(rootOp)
else
///////////////////////
rewriter.replaceOp(rootOp, *newOp);
return success();
```

I can create such MR if you think it is a good addition to your feature. 😉 



https://github.com/llvm/llvm-project/pull/91987


More information about the Mlir-commits mailing list