Fixed a problem in IRForTarget where we would not
delete a constant after we replaced it with a
dynamically-computed value.  Also ensured that we
replace all users of the constant if there are
multiple ones.  Added a testcase.

<rdar://problem/14379043>

llvm-svn: 186363
diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp
index 7119434..dc27b65 100644
--- a/lldb/source/Expression/IRForTarget.cpp
+++ b/lldb/source/Expression/IRForTarget.cpp
@@ -2210,7 +2210,8 @@
                                                    llvm::cast<Instruction>(entry_instruction_finder.GetValue(function)));
                         });
                         
-                        return UnfoldConstant(constant_expr, bit_cast_maker, entry_instruction_finder);
+                        if (!UnfoldConstant(constant_expr, bit_cast_maker, entry_instruction_finder))
+                            return false;
                     }
                     break;
                 case Instruction::GetElementPtr:
@@ -2247,7 +2248,8 @@
                             return GetElementPtrInst::Create(ptr, indices, "", llvm::cast<Instruction>(entry_instruction_finder.GetValue(function)));
                         });
                         
-                        return UnfoldConstant(constant_expr, get_element_pointer_maker, entry_instruction_finder);
+                        if (!UnfoldConstant(constant_expr, get_element_pointer_maker, entry_instruction_finder))
+                            return false;
                     }
                     break;
                 }
@@ -2274,6 +2276,11 @@
         }
     }
     
+    if (!isa<GlobalValue>(old_constant))
+    {
+        old_constant->destroyConstant();
+    }
+    
     return true;
 }