[llvm] [AArch64] Fold sext-in-reg for predicate -> fixed-length conversions. (PR #176883)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 20 03:57:06 PST 2026


================
@@ -24690,6 +24690,19 @@ static SDValue performGLD1Combine(SDNode *N, SelectionDAG &DAG) {
   return SDValue();
 }
 
+// Returns true when V is the following pattern:
+//    v16i8 extract_subvector(
+//      nxv16i8 sign_extend (nxv16i1 v))
+static bool isPredicateToFixedLengthVectorConversion(SDValue V) {
+  if (V.getOpcode() != ISD::EXTRACT_SUBVECTOR)
+    return false;
+
+  SDValue Src = V.getOperand(0);
+  return V.getValueType() == MVT::v16i8 && Src.getValueType() == MVT::nxv16i8 &&
+         Src.getOpcode() == ISD::SIGN_EXTEND &&
+         Src.getOperand(0).getValueType() == MVT::nxv16i1;
+}
----------------
MacDue wrote:

I don't think we need this workaround. If you look at `ComputeNumSignBits`, you see we just bailout for scalable vectors: https://github.com/llvm/llvm-project/blob/aa57ee958d4d7080109a7ce0ff11e809773709b5/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L3037-L3039

However, I think it's valid to do:
```
  case ISD::EXTRACT_SUBVECTOR: {
    SDValue Src = Op.getOperand(0);
    APInt DemandedSrcElts;
    if (Src.getValueType().isScalableVector()) {
      // For scalable vectors, just demand all elements.
      DemandedSrcElts = APInt(1, 1);
    } else {
      // Offset the demanded elts by the subvector index.
      uint64_t Idx = Op.getConstantOperandVal(1);
      unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
      DemandedSrcElts = DemandedElts.zext(NumSrcElts).shl(Idx);
    }
    return ComputeNumSignBits(Src, DemandedSrcElts, Depth + 1);
```
With fixes `ComputeNumSignBits` more generally. 

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


More information about the llvm-commits mailing list