[llvm] 93139a3 - [LegalizeTypes] Only expand CTLZ/CTTZ/CTPOP during type promotion if the new type is legal.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 22 11:02:42 PDT 2021


Author: Craig Topper
Date: 2021-10-22T11:02:35-07:00
New Revision: 93139a3c32660bc29ac91dea616aa2501f37c8cc

URL: https://github.com/llvm/llvm-project/commit/93139a3c32660bc29ac91dea616aa2501f37c8cc
DIFF: https://github.com/llvm/llvm-project/commit/93139a3c32660bc29ac91dea616aa2501f37c8cc.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Removed: 
    


################################################################################
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)) {


        


More information about the llvm-commits mailing list