From d78fdf111dda26307e88d16f5f5d1411f3bd7e61 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 17 Nov 2021 15:21:00 -0800 Subject: [PATCH] [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. --- llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 6ce7822..1fa4d88 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -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; -- 2.7.4