From 93139a3c32660bc29ac91dea616aa2501f37c8cc Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 22 Oct 2021 10:38:53 -0700 Subject: [PATCH] [LegalizeTypes] Only expand CTLZ/CTTZ/CTPOP during type promotion if the new type is legal. We might be promoting a large non-power of 2 type and the new type may need to be split. Once we split it we may have a ctlz/cttz/ctpop instruction for the split type. I'm also concerned that we may create large shifts with shift amounts that are too small. --- llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 61ea98fd85e1..ae59e2c98e9c 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -586,7 +586,7 @@ SDValue DAGTypeLegalizer::PromoteIntRes_CTLZ(SDNode *N) { // If the larger CTLZ 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. - if (!OVT.isVector() && + if (!OVT.isVector() && TLI.isTypeLegal(NVT) && !TLI.isOperationLegalOrCustomOrPromote(ISD::CTLZ, NVT) && !TLI.isOperationLegalOrCustomOrPromote(ISD::CTLZ_ZERO_UNDEF, NVT)) { if (SDValue Result = TLI.expandCTLZ(N, DAG)) { @@ -614,7 +614,7 @@ SDValue DAGTypeLegalizer::PromoteIntRes_CTPOP_PARITY(SDNode *N) { // original type. // TODO: Expand ISD::PARITY. Need to move ExpandPARITY from LegalizeDAG to // TargetLowering. - if (N->getOpcode() == ISD::CTPOP && !OVT.isVector() && + if (N->getOpcode() == ISD::CTPOP && !OVT.isVector() && TLI.isTypeLegal(NVT) && !TLI.isOperationLegalOrCustomOrPromote(ISD::CTPOP, NVT)) { if (SDValue Result = TLI.expandCTPOP(N, DAG)) { Result = DAG.getNode(ISD::ANY_EXTEND, SDLoc(N), NVT, Result); @@ -636,7 +636,7 @@ 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. - if (!OVT.isVector() && + if (!OVT.isVector() && TLI.isTypeLegal(NVT) && !TLI.isOperationLegalOrCustomOrPromote(ISD::CTTZ, NVT) && !TLI.isOperationLegalOrCustomOrPromote(ISD::CTTZ_ZERO_UNDEF, NVT)) { if (SDValue Result = TLI.expandCTTZ(N, DAG)) {