[llvm] [AArch64] Add @llvm.experimental.vector.match (PR #101974)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 15 05:08:08 PDT 2024


================
@@ -4041,6 +4041,30 @@ bool AArch64TTIImpl::isLegalToVectorizeReduction(
   }
 }
 
+bool AArch64TTIImpl::hasVectorMatch(VectorType *VT, unsigned SearchSize) const {
+  // Check that (i) the target has SVE2 and SVE is available, (ii) `VT' is a
+  // legal type for MATCH, and (iii) the search vector can be broadcast
+  // efficently to a legal type.
+  //
+  // Currently, we require the length of the search vector to match the minimum
+  // number of elements of `VT'. In practice this means we only support the
+  // cases (nxv16i8, 16), (v16i8, 16), (nxv8i16, 8), and (v8i16, 8), where the
+  // first element of the tuples corresponds to the type of the first argument
+  // and the second the length of the search vector.
+  //
+  // In the future we can support more cases. For example, (nxv16i8, 4) could
+  // be efficiently supported by using a DUP.S to broadcast the search
+  // elements, and more exotic cases like (nxv16i8, 5) could be supported by a
+  // sequence of SEL(DUP).
+  if (ST->hasSVE2() && ST->isSVEAvailable() &&
----------------
david-arm wrote:

If you follow my suggestion of moving this to AArch64ISelLowering and passing the EVT type you could write it like this:

```
  if (!ST->hasSVE2() || !ST->isSVEAvailable())
    return false;

  if (VT == MVT::nxv8i16 || VT == MVT::v8i16)
    return SearchSize == 8;
  else if (VT == MVT::nxv16i8 || VT == MVT::v16i8)
    return SearchSize == 16;
  return false;
```

which might make it easier to extend in future rather than growing the if statement. I can see us wanting to support cases in future where SearchSize <= number of elements. What do you think?

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


More information about the llvm-commits mailing list