SDValue ExpandFSUB(SDValue Op);
SDValue ExpandBITREVERSE(SDValue Op);
SDValue ExpandCTLZ(SDValue Op);
- SDValue ExpandCTTZ_ZERO_UNDEF(SDValue Op);
+ SDValue ExpandCTTZ(SDValue Op);
SDValue ExpandStrictFPOp(SDValue Op);
/// Implements vector promotion.
case ISD::CTLZ:
case ISD::CTLZ_ZERO_UNDEF:
return ExpandCTLZ(Op);
+ case ISD::CTTZ:
case ISD::CTTZ_ZERO_UNDEF:
- return ExpandCTTZ_ZERO_UNDEF(Op);
+ return ExpandCTTZ(Op);
case ISD::STRICT_FADD:
case ISD::STRICT_FSUB:
case ISD::STRICT_FMUL:
return DAG.UnrollVectorOp(Op.getNode());
}
-SDValue VectorLegalizer::ExpandCTTZ_ZERO_UNDEF(SDValue Op) {
+SDValue VectorLegalizer::ExpandCTTZ(SDValue Op) {
EVT VT = Op.getValueType();
+ unsigned NumBitsPerElt = VT.getScalarSizeInBits();
// If the non-ZERO_UNDEF version is supported we can use that instead.
if (TLI.isOperationLegalOrCustom(ISD::CTTZ, VT)) {
return DAG.getNode(ISD::CTTZ, DL, VT, Op.getOperand(0));
}
+ // If we have the appropriate vector bit operations, it is better to use them
+ // than unrolling and expanding each component.
+ if (isPowerOf2_32(NumBitsPerElt) &&
+ (TLI.isOperationLegalOrCustom(ISD::CTPOP, VT) ||
+ TLI.isOperationLegalOrCustom(ISD::CTLZ, VT)) &&
+ TLI.isOperationLegalOrCustom(ISD::SUB, VT) &&
+ TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) &&
+ TLI.isOperationLegalOrCustomOrPromote(ISD::XOR, VT))
+ return Op;
+
// Otherwise go ahead and unroll.
return DAG.UnrollVectorOp(Op.getNode());
}
if (VT.is256BitVector() && !Subtarget.hasInt256())
return Lower256IntUnary(Op, DAG);
- // Tmp = ~x & (x - 1)
- SDValue One = DAG.getConstant(1, dl, VT);
- SDValue Tmp = DAG.getNode(ISD::AND, dl, VT, DAG.getNOT(dl, N0, VT),
- DAG.getNode(ISD::SUB, dl, VT, N0, One));
-
// cttz(x) = width - ctlz(~x & (x - 1))
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
if (TLI.isOperationLegal(ISD::CTLZ, VT) &&
!TLI.isOperationLegal(ISD::CTPOP, VT)) {
+ SDValue One = DAG.getConstant(1, dl, VT);
SDValue Width = DAG.getConstant(NumBits, dl, VT);
- return DAG.getNode(ISD::SUB, dl, VT, Width,
- DAG.getNode(ISD::CTLZ, dl, VT, Tmp));
+ return DAG.getNode(
+ ISD::SUB, dl, VT, Width,
+ DAG.getNode(ISD::CTLZ, dl, VT,
+ DAG.getNode(ISD::AND, dl, VT, DAG.getNOT(dl, N0, VT),
+ DAG.getNode(ISD::SUB, dl, VT, N0, One))));
}
- // cttz(x) = ctpop(~x & (x - 1))
- return DAG.getNode(ISD::CTPOP, dl, VT, Tmp);
+ // Else leave it to the legalizer.
+ return SDValue();
}
assert(Op.getOpcode() == ISD::CTTZ &&