Change LLVM check for pending exception to use thread flags.

This is the first step towards having a single check for
suspension/exceptions.

Change-Id: I4008f43d6ba1ee2441f2656fc3ae8bc4fcb7da23
diff --git a/src/compiler_llvm/runtime_support_builder.cc b/src/compiler_llvm/runtime_support_builder.cc
index 169f8e8..9513d4a 100644
--- a/src/compiler_llvm/runtime_support_builder.cc
+++ b/src/compiler_llvm/runtime_support_builder.cc
@@ -147,11 +147,12 @@
 }
 
 llvm::Value* RuntimeSupportBuilder::EmitIsExceptionPending() {
-  Value* exception = EmitLoadFromThreadOffset(Thread::ExceptionOffset().Int32Value(),
-                                              irb_.getJObjectTy(),
-                                              kTBAARuntimeInfo);
-  // If exception not null
-  return irb_.CreateIsNotNull(exception);
+  Value* state_and_flags = EmitLoadFromThreadOffset(Thread::ThreadFlagsOffset().Int32Value(),
+                                                    irb_.getInt16Ty(),
+                                                    kTBAARuntimeInfo);
+  // Mask exception pending status and return true if non-zero.
+  Value* exception_pending = irb_.CreateAnd(state_and_flags, irb_.getInt16(kExceptionPending));
+  return irb_.CreateICmpNE(exception_pending, irb_.getInt16(0));
 }