[Mlir-commits] [mlir] [mlir][ArmSVE] Add convert_to/from_svbool ops (PR #68586)

Benjamin Maxwell llvmlistbot at llvm.org
Wed Oct 11 10:02:19 PDT 2023


================
@@ -481,10 +500,39 @@ class IsScalableVectorOfLengthPred<list<int> allowedLengths> :
                            == }]
                          # allowedlength>)>]>;
 
+// Normalizes an index so it can be bounds checked.
+// Negative values are mapped to their absolute value.
+//  - These are used to index in reverse (i.e. index -1 would be the last element)
+// Positive values are mapped to their value + 1.
+//  - This results the same range of values as the negative indices
+// This allows bounds checking to be: len(list) >= NormalizeIndex<idx>.ret.
+class NormalizeIndex<int value> {
+  int ret = !if(!lt(value, 0), !sub(0, value), !add(value, 1));
+}
+
+// Whether the n-th dim of the shape matches the given `size`.
+// Negative values index in reverse.
----------------
MacDue wrote:

I meant: 
```
// Whether the n-th dim of the shape is contained within `allowedSizes`.
// Negative values for `n` index in reverse.
```

**Examples:**
`IsNthDimSizeIsOneOfPred<0, {2, 3, 4}`
 - Accepts any shape where the first dim is 2, 3, or 4.
   * This means shapes like: `2x8x9x5`, `4`, `3x1`, `4x?`, etc
`IsNthDimSizeIsOneOfPred<-1, {16}`
 - Accepts any shape where the last dim is 16.
   * This means shapes like `2x16`, `16`, `1x2x3x4x16`, etc
`IsNthDimSizeIsOneOfPred<-2, {10, 5}>`
 - Accepts any shape where the second to last dim is 10 or 5.
   * This means shapes like: `1x10x2`, `2x1x4x5x6`, `8x10x?`, etc



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


More information about the Mlir-commits mailing list