Make the InsertBefore argument to FindInsertedValue optional, so you can find an inserted value without modifying the code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52319 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index 64cdc24..9251857 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -805,6 +805,7 @@
 // Any inserted instructions are inserted before InsertBefore
 Value *BuildSubAggregate(Value *From, const unsigned *idx_begin,
                          const unsigned *idx_end, Instruction *InsertBefore) {
+  assert(InsertBefore && "Must have someplace to insert!");
   const Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(),
                                                              idx_begin,
                                                              idx_end);
@@ -851,9 +852,13 @@
     for (const unsigned *i = I->idx_begin(), *e = I->idx_end();
          i != e; ++i, ++req_idx) {
       if (req_idx == idx_end)
-        // The requested index is a part of a nested aggregate. Handle this
-        // specially.
-        return BuildSubAggregate(V, idx_begin, req_idx, InsertBefore);
+        if (InsertBefore)
+          // The requested index is a part of a nested aggregate. Handle this
+          // specially.
+          return BuildSubAggregate(V, idx_begin, req_idx, InsertBefore);
+        else
+          // We can't handle this without inserting insertvalues
+          return 0;
       
       // This insert value inserts something else than what we are looking for.
       // See if the (aggregrate) value inserted into has the value we are