[LegalizeTypes] Further limit expansion of CTTZ during type promotion.

Don't expand CTTZ if CTPOP or CTLZ is supported on the promoted type.
We have special handling for CTTZ expansion to use those ops with a
small conversion. The setup for that doesn't generate extra code or
large constants so we don't gain anything from expanding early and we
make CTTZ_ZERO_UNDEF codegen worse.

Follow up from post commit feedback on D112268. We don't seem to have
any in tree tests that care about this.
This commit is contained in:
Craig Topper 2021-11-17 15:21:00 -08:00
parent 951b107eed
commit d78fdf111d
1 changed files with 5 additions and 2 deletions

View File

@ -622,10 +622,13 @@ SDValue DAGTypeLegalizer::PromoteIntRes_CTTZ(SDNode *N) {
// 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;