Fix a crash when threading a block that includes a MRV call result.
DemoteRegToStack doesn't work with MRVs yet, because it relies on the
ability to load/store things.

This fixes PR2285.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50667 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index be94025..1a2ec99 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -433,12 +433,27 @@
   // Jump Threading can not update SSA properties correctly if the values
   // defined in the duplicated block are used outside of the block itself.  For
   // this reason, we spill all values that are used outside of BB to the stack.
-  for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
-    if (I->isUsedOutsideOfBlock(BB)) {
-      // We found a use of I outside of BB.  Create a new stack slot to
-      // break this inter-block usage pattern.
+  for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
+    if (!I->isUsedOutsideOfBlock(BB))
+      continue;
+    
+    // We found a use of I outside of BB.  Create a new stack slot to
+    // break this inter-block usage pattern.
+    if (!isa<StructType>(I->getType())) {
       DemoteRegToStack(*I);
+      continue;
     }
+    
+    // Alternatively, I must be a call or invoke that returns multiple retvals.
+    // We can't use 'DemoteRegToStack' because the at will create loads and
+    // stores of aggregates which is not valid yet.  If I is a call, we can just
+    // pull all the getresult instructions up to this block.  If I is an invoke,
+    // we are out of luck.
+    BasicBlock::iterator IP = I; ++IP;
+    for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
+         UI != E; ++UI)
+      cast<GetResultInst>(UI)->moveBefore(IP);
+  }
  
   // We are going to have to map operands from the original BB block to the new
   // copy of the block 'NewBB'.  If there are PHI nodes in BB, evaluate them to