[llvm-commits] [llvm] r82214 - in /llvm/trunk: include/llvm/CodeGen/MachineBasicBlock.h lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Evan Cheng evan.cheng at apple.com
Fri Sep 18 01:16:04 PDT 2009


Author: evancheng
Date: Fri Sep 18 03:16:04 2009
New Revision: 82214

URL: http://llvm.org/viewvc/llvm-project?rev=82214&view=rev
Log:
Fix a bug in sdisel switch lowering code. When it updates the phi nodes in switch successor blocks, it can introduce multiple phi operands of the same value from different blocks (and may not be on the predecessor list).

This can be seen on CodeGen/Generic/2006-09-06-SwitchLowering.ll. But it's not known to cause any real regression (but I have added an assertion for it now).

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=82214&r1=82213&r2=82214&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Fri Sep 18 03:16:04 2009
@@ -149,6 +149,10 @@
     return (unsigned)Predecessors.size();
   }
   bool                 pred_empty() const { return Predecessors.empty(); }
+  bool                 isPred(MachineBasicBlock *MBB) const {
+    return std::find(pred_begin(), pred_end(), MBB) != pred_end();
+  }
+
   succ_iterator        succ_begin()       { return Successors.begin();   }
   const_succ_iterator  succ_begin() const { return Successors.begin();   }
   succ_iterator        succ_end()         { return Successors.end();     }
@@ -165,6 +169,9 @@
     return (unsigned)Successors.size();
   }
   bool                 succ_empty() const { return Successors.empty();   }
+  bool                 isSucc(MachineBasicBlock *MBB) const {
+    return std::find(succ_begin(), succ_end(), MBB) != succ_end();
+  }
 
   // LiveIn management methods.
 

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=82214&r1=82213&r2=82214&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Sep 18 03:16:04 2009
@@ -982,6 +982,7 @@
   
   // If we generated any switch lowering information, build and codegen any
   // additional DAGs necessary.
+  SmallSet<unsigned, 4> Processed;
   for (unsigned i = 0, e = SDL->SwitchCases.size(); i != e; ++i) {
     // Set the current basic block to the mbb we wish to insert the code into
     BB = SDL->SwitchCases[i].ThisBB;
@@ -1004,12 +1005,18 @@
         for (unsigned pn = 0; ; ++pn) {
           assert(pn != SDL->PHINodesToUpdate.size() &&
                  "Didn't find PHI entry!");
-          if (SDL->PHINodesToUpdate[pn].first == Phi) {
-            Phi->addOperand(MachineOperand::CreateReg(SDL->PHINodesToUpdate[pn].
-                                                      second, false));
-            Phi->addOperand(MachineOperand::CreateMBB(SDL->SwitchCases[i].ThisBB));
+          if (SDL->PHINodesToUpdate[pn].first != Phi)
+            continue;
+          if (!Processed.insert(pn))
+            // Already processed, done. We can't have the value from more than
+            // one edges.
             break;
-          }
+          Phi->addOperand(MachineOperand::CreateReg(SDL->PHINodesToUpdate[pn].
+                                                    second, false));
+          assert(BB->isPred(SDL->SwitchCases[i].ThisBB) &&
+                 "phi value cannot come from a bb that is not a predecessor!");
+          Phi->addOperand(MachineOperand::CreateMBB(SDL->SwitchCases[i].ThisBB));
+          break;
         }
       }
       





More information about the llvm-commits mailing list