[llvm] [SDAG] Add basic type legalization for experimental.vector.match (PR #213344)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 2 20:43:36 PDT 2026


================
@@ -8526,30 +8526,14 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
     SDValue Op1 = getValue(I.getOperand(0));
     SDValue Op2 = getValue(I.getOperand(1));
     SDValue Mask = getValue(I.getOperand(2));
-    EVT Op1VT = Op1.getValueType();
-    EVT Op2VT = Op2.getValueType();
     EVT ResVT = Mask.getValueType();
-    unsigned SearchSize = Op2VT.getVectorNumElements();
-
-    // If the target has native support for this vector match operation, lower
-    // the intrinsic untouched; otherwise, expand it below.
-    if (!TLI.shouldExpandVectorMatch(Op1VT, SearchSize)) {
-      visitTargetIntrinsic(I, Intrinsic);
+    if (!TLI.shouldExpandVectorMatch()) {
+      setValue(&I, DAG.getNode(ISD::VECTOR_MATCH, sdl, ResVT, Op1, Op2, Mask));
       return;
     }
 
-    SDValue Ret = DAG.getConstant(0, sdl, ResVT);
-
-    for (unsigned i = 0; i < SearchSize; ++i) {
-      SDValue Op2Elem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl,
-                                    Op2VT.getVectorElementType(), Op2,
-                                    DAG.getVectorIdxConstant(i, sdl));
-      SDValue Splat = DAG.getNode(ISD::SPLAT_VECTOR, sdl, Op1VT, Op2Elem);
-      SDValue Cmp = DAG.getSetCC(sdl, ResVT, Op1, Splat, ISD::SETEQ);
-      Ret = DAG.getNode(ISD::OR, sdl, ResVT, Ret, Cmp);
-    }
-
-    setValue(&I, DAG.getNode(ISD::AND, sdl, ResVT, Ret, Mask));
+    SDValue Match = DAG.getNode(ISD::VECTOR_MATCH, sdl, ResVT, Op1, Op2, Mask);
+    setValue(&I, TLI.expandVectorMatch(Match.getNode(), DAG));
----------------
lukel97 wrote:

Can we remove the `TLI.shouldExpandVectorMatch()` hook and always return `ISD::VECTOR_MATCH`? That way LegalizeVectorOps could handle the expansion by just checking if ISD::VECTOR_MATCH is marked as expand by the target.

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


More information about the llvm-commits mailing list