Don't allow MatchAddress recurse too much. This trims exponential
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 28 Mar 2007 18:36:33 +0000 (18:36 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 28 Mar 2007 18:36:33 +0000 (18:36 +0000)
behaviour in some cases.

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

lib/Target/X86/X86ISelDAGToDAG.cpp

index 9c1dcf93b256f04e3d344ecf6973138f85a17272..e48c165d383f4e0f86c9b67fcf15f655f79e383e 100644 (file)
@@ -140,7 +140,8 @@ namespace {
   private:
     SDNode *Select(SDOperand N);
 
-    bool MatchAddress(SDOperand N, X86ISelAddressMode &AM, bool isRoot = true);
+    bool MatchAddress(SDOperand N, X86ISelAddressMode &AM,
+                      bool isRoot = true,unsigned Depth = 0);
     bool SelectAddr(SDOperand Op, SDOperand N, SDOperand &Base,
                     SDOperand &Scale, SDOperand &Index, SDOperand &Disp);
     bool SelectLEAAddr(SDOperand Op, SDOperand N, SDOperand &Base,
@@ -561,7 +562,14 @@ void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
 /// returning true if it cannot be done.  This just pattern matches for the
 /// addressing mode
 bool X86DAGToDAGISel::MatchAddress(SDOperand N, X86ISelAddressMode &AM,
-                                   bool isRoot) {
+                                   bool isRoot, unsigned Depth) {
+  if (Depth > 5) {
+    // Default, generate it as a register.
+    AM.BaseType = X86ISelAddressMode::RegBase;
+    AM.Base.Reg = N;
+    return false;
+  }
+  
   // RIP relative addressing: %rip + 32-bit displacement!
   if (AM.isRIPRel) {
     if (!AM.ES && AM.JT != -1 && N.getOpcode() == ISD::Constant) {
@@ -711,12 +719,12 @@ bool X86DAGToDAGISel::MatchAddress(SDOperand N, X86ISelAddressMode &AM,
   case ISD::ADD:
     if (!Available) {
       X86ISelAddressMode Backup = AM;
-      if (!MatchAddress(N.Val->getOperand(0), AM, false) &&
-          !MatchAddress(N.Val->getOperand(1), AM, false))
+      if (!MatchAddress(N.Val->getOperand(0), AM, false, Depth+1) &&
+          !MatchAddress(N.Val->getOperand(1), AM, false, Depth+1))
         return false;
       AM = Backup;
-      if (!MatchAddress(N.Val->getOperand(1), AM, false) &&
-          !MatchAddress(N.Val->getOperand(0), AM, false))
+      if (!MatchAddress(N.Val->getOperand(1), AM, false, Depth+1) &&
+          !MatchAddress(N.Val->getOperand(0), AM, false, Depth+1))
         return false;
       AM = Backup;
     }