[llvm] [IR] Add llvm.vector.shuffle intrinsic for vector shuffles with runtime masks Part 1. (PR #219259)

Oscar Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 22:26:11 PDT 2026


================
@@ -2580,6 +2575,38 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
       return thisT()->getShuffleCost(TTI::SK_Reverse, cast<VectorType>(RetTy),
                                      cast<VectorType>(ICA.getArgTypes()[0]),
                                      CostKind, {}, 0, cast<VectorType>(RetTy));
+    case Intrinsic::vector_shuffle: {
+      auto *VecTy = cast<VectorType>(RetTy);
+      auto *MaskTy = cast<VectorType>(ICA.getArgTypes()[1]);
+      std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VecTy);
+
+      // On a target that lowers the run-time-mask shuffle natively, each legal
+      // part of the result is one permute of every legal part of the source,
+      // with a select to merge each extra source part in, plus the fixup that
+      // turns the indices into whatever form the permute wants.
+      if (getTLI()->isOperationLegalOrCustom(ISD::VECTOR_SHUFFLE_VAR,
+                                             LT.second)) {
+        InstructionCost Parts = LT.first;
+        return Parts * Parts + Parts * (Parts - 1) +
+               getTypeLegalizationCost(MaskTy).first;
----------------
oscardssmith wrote:

cost calculation dropped until we actually have backends that do things.

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


More information about the llvm-commits mailing list