diff --git unittests/ExecutionEngine/JIT/JITTest.cpp unittests/ExecutionEngine/JIT/JITTest.cpp
index 4d10ee6..1b2761c 100644
--- unittests/ExecutionEngine/JIT/JITTest.cpp
+++ unittests/ExecutionEngine/JIT/JITTest.cpp
@@ -578,11 +578,49 @@ TEST_F(JITTest, FunctionIsRecompiledAndRelinked) {
   int (*NewFPtr)() = reinterpret_cast<int(*)()>(
     (intptr_t)TheJIT->recompileAndRelinkFunction(F));
 
+  EXPECT_NE(NewFPtr, OrigFPtr)
+    << "Recompilation shouldn't happen in-place";
+  EXPECT_EQ((intptr_t)NewFPtr, (intptr_t)TheJIT->getPointerToGlobalIfAvailable(F))
+    << "Global mapping should forward to the recompiled version";
   EXPECT_EQ(2, NewFPtr())
     << "The new pointer should call the new version of the function";
   EXPECT_EQ(2, OrigFPtr())
     << "The old pointer's target should now jump to the new version";
 }
+
+TEST_F(JITTest, KeepStubs) {
+  Function *F = Function::Create(TypeBuilder<int(void), false>::get(Context),
+                                 GlobalValue::ExternalLinkage, "test", M);
+  BasicBlock *Entry = BasicBlock::Create(Context, "entry", F);
+  IRBuilder<> Builder(Entry);
+  Value *Val = ConstantInt::get(TypeBuilder<int, false>::get(Context), 1);
+  Builder.CreateRet(Val);
+
+  TheJIT->DisableLazyCompilation(true);
+  TheJIT->SetKeepStubs(true);
+
+  // Compile the function once, and make sure it works.
+  int (*OrigFPtr)() = reinterpret_cast<int(*)()>(
+    (intptr_t)TheJIT->getPointerToFunction(F));
+  EXPECT_EQ(1, OrigFPtr());
+
+  // Now change the function to return a different value.
+  Entry->eraseFromParent();
+  BasicBlock *NewEntry = BasicBlock::Create(Context, "new_entry", F);
+  Builder.SetInsertPoint(NewEntry);
+  Val = ConstantInt::get(TypeBuilder<int, false>::get(Context), 2);
+  Builder.CreateRet(Val);
+
+  // Recompile it, which should update the stub to call the new function
+  // pointer, but still return the old stub pointer.
+  int (*NewFPtr)() = reinterpret_cast<int(*)()>(
+    (intptr_t)TheJIT->recompileAndRelinkFunction(F));
+
+  EXPECT_EQ(OrigFPtr, NewFPtr)
+    << "If KeepStubs is set, an invariant stub pointer should be returned";
+  EXPECT_EQ(2, NewFPtr())
+    << "The stub should now call the new version of the function";
+}
 #endif  // !defined(__arm__)
 
 }  // anonymous namespace

