// If the larger CTTZ isn't supported by the target, try to expand now.
// If we expand later we'll end up with more operations since we lost the
- // original type.
+ // original type. Don't expand if we can use CTPOP or CTLZ expansion on the
+ // larger type.
if (!OVT.isVector() && TLI.isTypeLegal(NVT) &&
!TLI.isOperationLegalOrCustomOrPromote(ISD::CTTZ, NVT) &&
- !TLI.isOperationLegalOrCustomOrPromote(ISD::CTTZ_ZERO_UNDEF, NVT)) {
+ !TLI.isOperationLegalOrCustomOrPromote(ISD::CTTZ_ZERO_UNDEF, NVT) &&
+ !TLI.isOperationLegal(ISD::CTPOP, NVT) &&
+ !TLI.isOperationLegal(ISD::CTLZ, NVT)) {
if (SDValue Result = TLI.expandCTTZ(N, DAG)) {
Result = DAG.getNode(ISD::ANY_EXTEND, dl, NVT, Result);
return Result;