Avoid creating virtual registers for unused values.
authorDan Gohman <gohman@apple.com>
Fri, 16 Apr 2010 17:15:02 +0000 (17:15 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 16 Apr 2010 17:15:02 +0000 (17:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101480 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 412de1c89bb00bd8299bc555f9ee1a8f667f10e5..71da0ab3e560548b13cfcaf52e5adea2fab6d9c9 100644 (file)
@@ -918,10 +918,10 @@ void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
 /// created for it, emit nodes to copy the value into the virtual
 /// registers.
 void SelectionDAGBuilder::CopyToExportRegsIfNeeded(const Value *V) {
-  if (!V->use_empty()) {
-    DenseMap<const Value *, unsigned>::iterator VMI = FuncInfo.ValueMap.find(V);
-    if (VMI != FuncInfo.ValueMap.end())
-      CopyValueToVirtualRegister(V, VMI->second);
+  DenseMap<const Value *, unsigned>::iterator VMI = FuncInfo.ValueMap.find(V);
+  if (VMI != FuncInfo.ValueMap.end()) {
+    assert(!V->use_empty() && "Unused value assigned virtual registers!");
+    CopyValueToVirtualRegister(V, VMI->second);
   }
 }
 
index 7436bbea723c3deae1f613555bfb227c7b25e698..9082fb6fbe92905261e178b3ad253bd2e66c9210 100644 (file)
@@ -834,7 +834,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
             BI->dump();
           }
 
-          if (!BI->getType()->isVoidTy()) {
+          if (!BI->getType()->isVoidTy() && !BI->use_empty()) {
             unsigned &R = FuncInfo->ValueMap[BI];
             if (!R)
               R = FuncInfo->CreateRegForValue(BI);