Fix PR2488, a case where we deleted stack restores too aggressively.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52702 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 37637bb..d45eb99 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -8697,13 +8697,18 @@
         CannotRemove = true;
         break;
       }
-      if (isa<CallInst>(BI)) {
-        if (!isa<IntrinsicInst>(BI)) {
+      if (CallInst *BCI = dyn_cast<CallInst>(BI)) {
+        if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(BCI)) {
+          // If there is a stackrestore below this one, remove this one.
+          if (II->getIntrinsicID() == Intrinsic::stackrestore)
+            return EraseInstFromFunction(CI);
+          // Otherwise, ignore the intrinsic.
+        } else {
+          // If we found a non-intrinsic call, we can't remove the stack
+          // restore.
           CannotRemove = true;
           break;
         }
-        // If there is a stackrestore below this one, remove this one.
-        return EraseInstFromFunction(CI);
       }
     }