add an assertion, avoid creating copyfromreg/copytoreg pairs that are the
authorChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 22:03:46 +0000 (22:03 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 22:03:46 +0000 (22:03 +0000)
same for PHI nodes.

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

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 916943f30b1735cd7ba041084a2ed3ed9c628134..9ccf87cfd845e0a3dc250412d65be038dc00e6b4 100644 (file)
@@ -762,7 +762,10 @@ bool SelectionDAGISel::runOnFunction(Function &Fn) {
 void SelectionDAGISel::CopyValueToVirtualRegister(SelectionDAGLowering &SDL,
                                                   Value *V, unsigned Reg) {
   SelectionDAG &DAG = SDL.DAG;
-  DAG.setRoot(DAG.getCopyToReg(DAG.getRoot(), SDL.getValue(V), Reg));
+  SDOperand Op = SDL.getValue(V);
+  if (CopyRegSDNode *CR = dyn_cast<CopyRegSDNode>(Op))
+    assert(CR->getReg() != Reg && "Copy from a reg to the same reg!");
+  DAG.setRoot(DAG.getCopyToReg(DAG.getRoot(), Op, Reg));
 }
 
 void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
@@ -798,7 +801,7 @@ void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
   // Ensure that all instructions which are used outside of their defining
   // blocks are available as virtual registers.
   for (BasicBlock::iterator I = LLVMBB->begin(), E = LLVMBB->end(); I != E;++I)
-    if (!I->use_empty()) {
+    if (!I->use_empty() && !isa<PHINode>(I)) {
       std::map<const Value*, unsigned>::iterator VMI =FuncInfo.ValueMap.find(I);
       if (VMI != FuncInfo.ValueMap.end())
         CopyValueToVirtualRegister(SDL, I, VMI->second);