[llvm] [X86] Narrow the mask when folding (vselect mask, (v16i8 (vtrunc (v8i64 x))), 0). (PR #228270)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 23:50:51 PDT 2026


================
@@ -49145,7 +49145,11 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG,
       SDValue TruncSrc = LHS.getOperand(0);
       EVT TruncSrcVT = TruncSrc.getValueType();
       if (VT == MVT::v16i8 && TruncSrcVT == MVT::v8i64) {
-        return DAG.getNode(X86ISD::VMTRUNC, DL, VT, TruncSrc, RHS, Cond);
+        // VMTRUNC's mask operand must have the same number of elements as
+        // the truncation source (v8i64), not the (wider) v16i8 result.
+        EVT MaskVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1, 8);
+        SDValue MaskCond = DAG.getExtractSubvector(DL, MaskVT, Cond, 0);
----------------
topperc wrote:

```suggestion
        SDValue MaskCond = DAG.getExtractSubvector(DL, MVT::v8i1, Cond, 0);
```

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


More information about the llvm-commits mailing list