[Mlir-commits] [mlir] [mlir][ArmSVE] Add convert_to/from_svbool ops (PR #68586)
Cullen Rhodes
llvmlistbot at llvm.org
Wed Oct 11 02:38:42 PDT 2023
================
@@ -236,6 +243,81 @@ def UmmlaOp : ArmSVE_Op<"ummla",
"$acc `,` $src1 `,` $src2 attr-dict `:` type($src1) `to` type($dst)";
}
+class SvboolTypeConstraint<string lhsArg, string rhsArg> : TypesMatchWith<
+ "expected corresponding svbool type widened to [16]xi1",
+ lhsArg, rhsArg,
+ "VectorType(VectorType::Builder(::llvm::cast<VectorType>($_self)).setDim(::llvm::cast<VectorType>($_self).getRank() - 1, 16))">;
+
+def ConvertFromSvboolOp : ArmSVE_Op<"convert_from_svbool",
+ [Pure, SvboolTypeConstraint<"result", "source">]>
+{
+ let summary = "Convert a svbool type to a SVE predicate type";
+ let description = [{
+ Converts svbool types (`vector<[16]xi1>` or vectors of that type, e.g.
+ `vector<2x3x[16]xi1>`) to SVE predicate types. Note: Only the trailing
+ dimension can be scalable.
+
+ Example 1: Convert a 1-D svbool mask to a SVE predicate.
+ ```mlir
+ %source = vector.load %memref[%c0] : memref<?xi1>, vector<[16]xi1>
+ %result = arm_sve.convert_from_svbool %source : vector<[4]xi1>
+ ```
+
+ Example 2: Convert a 2-D svbool mask to a mask of SVE predicates.
+ ```mlir
+ %source = vector.load %memref[%c0, %c0] : memref<2x?xi1>, vector<2x[16]xi1>
+ %result = arm_sve.convert_from_svbool %source : vector<2x[8]xi1>
+ ```
+
+ ---
+
+ A `svbool` is the smallest SVE predicate type that has a in-memory
+ representation (and maps to a full predicate register). In MLIR `svbool` is
+ represented as `vector<[16]xi1>`. Smaller SVE predicate types
+ (`vector<[1|2|4|8]xi1>`) must be stored as `svbool` then converted back to
+ a predicate after loading.
----------------
c-rhodes wrote:
```suggestion
(`vector<[1|2|4|8]xi1>`) must be stored as `svbool` then converted back to
the original predicate type after loading.
```
https://github.com/llvm/llvm-project/pull/68586
More information about the Mlir-commits
mailing list