]> granicus.if.org Git - llvm/commitdiff
[DAG] Add SelectionDAG::MaxRecursionDepth constant
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 19 Sep 2019 12:58:43 +0000 (12:58 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 19 Sep 2019 12:58:43 +0000 (12:58 +0000)
As commented on D67557 we have a lot of uses of depth checks all using magic numbers.

This patch adds the SelectionDAG::MaxRecursionDepth constant and moves over some general cases to use this explicitly.

Differential Revision: https://reviews.llvm.org/D67711

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372315 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAG.h
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/TargetLowering.cpp
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

index 8b8436f9eaab61c8860c4adef36f151ec91bba45..1c35c9f65a00b8ddc8da50c127506d02cc4fbff5 100644 (file)
@@ -388,7 +388,11 @@ private:
     Node->OperandList = nullptr;
   }
   void CreateTopologicalOrder(std::vector<SDNode*>& Order);
+
 public:
+  // Maximum depth for recursive analysis such as computeKnownBits, etc.
+  static constexpr unsigned MaxRecursionDepth = 6;
+
   explicit SelectionDAG(const TargetMachine &TM, CodeGenOpt::Level);
   SelectionDAG(const SelectionDAG &) = delete;
   SelectionDAG &operator=(const SelectionDAG &) = delete;
index edb5ecb4d3df18c4057ba12a898e95e5f7763701..9de16e58e8c51ad33f7699dca5b923409ce0c8c8 100644 (file)
@@ -806,7 +806,7 @@ static char isNegatibleForFree(SDValue Op, bool LegalOperations,
     return 0;
 
   // Don't recurse exponentially.
-  if (Depth > 6)
+  if (Depth > SelectionDAG::MaxRecursionDepth)
     return 0;
 
   switch (Op.getOpcode()) {
@@ -913,7 +913,8 @@ static SDValue GetNegatedExpression(SDValue Op, SelectionDAG &DAG,
   if (Op.getOpcode() == ISD::FNEG)
     return Op.getOperand(0);
 
-  assert(Depth <= 6 && "GetNegatedExpression doesn't match isNegatibleForFree");
+  assert(Depth <= SelectionDAG::MaxRecursionDepth &&
+         "GetNegatedExpression doesn't match isNegatibleForFree");
   const TargetOptions &Options = DAG.getTarget().Options;
   const SDNodeFlags Flags = Op->getFlags();
 
index 96884bad54a9e0f6f0de12a7a3392d241ea6db16..95b7fe2e1c6d3f4e8c699a02f6e1d06d3e095bd7 100644 (file)
@@ -2422,7 +2422,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     return Known;
   }
 
-  if (Depth >= 6)
+  if (Depth >= MaxRecursionDepth)
     return Known;  // Limit search depth.
 
   KnownBits Known2;
@@ -3412,7 +3412,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     return Val.getNumSignBits();
   }
 
-  if (Depth >= 6)
+  if (Depth >= MaxRecursionDepth)
     return 1;  // Limit search depth.
 
   if (!DemandedElts)
@@ -3973,7 +3973,7 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, bool SNaN, unsigned Depth) const
   if (getTarget().Options.NoNaNsFPMath || Op->getFlags().hasNoNaNs())
     return true;
 
-  if (Depth >= 6)
+  if (Depth >= MaxRecursionDepth)
     return false; // Limit search depth.
 
   // TODO: Handle vectors.
index cd7f64efa750c9007570f29c4dc2608d2db89baa..fbe4e8cca8eac5aa08634866704a5a775e4f0601 100644 (file)
@@ -585,7 +585,7 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
     SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
     SelectionDAG &DAG, unsigned Depth) const {
   // Limit search depth.
-  if (Depth >= 6)
+  if (Depth >= SelectionDAG::MaxRecursionDepth)
     return SDValue();
 
   // Ignore UNDEFs.
@@ -798,7 +798,8 @@ bool TargetLowering::SimplifyDemandedBits(
   } else if (OriginalDemandedBits == 0 || OriginalDemandedElts == 0) {
     // Not demanding any bits/elts from Op.
     return TLO.CombineTo(Op, TLO.DAG.getUNDEF(VT));
-  } else if (Depth >= 6) { // Limit search depth.
+  } else if (Depth >= SelectionDAG::MaxRecursionDepth) {
+    // Limit search depth.
     return false;
   }
 
@@ -2107,7 +2108,7 @@ bool TargetLowering::SimplifyDemandedVectorElts(
   }
 
   // Limit search depth.
-  if (Depth >= 6)
+  if (Depth >= SelectionDAG::MaxRecursionDepth)
     return false;
 
   SDLoc DL(Op);
index dba34a96304b4d6a90b06d1811528fbb031fa98c..1f08505f37e797354f731c6561661324fc763714 100644 (file)
@@ -2053,7 +2053,7 @@ static void getUsefulBitsForUse(SDNode *UserNode, APInt &UsefulBits,
 }
 
 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth) {
-  if (Depth >= 6)
+  if (Depth >= SelectionDAG::MaxRecursionDepth)
     return;
   // Initialize UsefulBits
   if (!Depth) {