Change LLVM exception check to check all thread flags.

The logic now first checks if flags is non-zero, then if an exception is
pending it handles that, otherwise it calls the suspend helper.

Change-Id: I94a4869b30649b205a5a6142d998920f9f463182
diff --git a/src/compiler_llvm/method_compiler.cc b/src/compiler_llvm/method_compiler.cc
index ccec7e9..7ab11f5 100644
--- a/src/compiler_llvm/method_compiler.cc
+++ b/src/compiler_llvm/method_compiler.cc
@@ -3540,16 +3540,34 @@
     return;
   }
 
-  llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending();
-
   llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
+  llvm::BasicBlock* block_flags = CreateBasicBlockWithDexPC(dex_pc, "flags");
+  llvm::BasicBlock* block_suspend = CreateBasicBlockWithDexPC(dex_pc, "suspend");
+
+  llvm::Value* flags =
+      irb_.Runtime().EmitLoadFromThreadOffset(art::Thread::ThreadFlagsOffset().Int32Value(),
+                                              irb_.getInt16Ty(),
+                                              kTBAARuntimeInfo);
+  llvm::Value* flags_set = irb_.CreateICmpNE(flags, irb_.getInt16(0));
+  irb_.CreateCondBr(flags_set, block_flags, block_cont, kUnlikely);
+
+  irb_.SetInsertPoint(block_flags);
+  llvm::Value* exception_pending = irb_.CreateAnd(flags, irb_.getInt16(art::kExceptionPending));
+  llvm::Value* exception_set = irb_.CreateICmpNE(exception_pending, irb_.getInt16(0));
 
   if (lpad) {
-    irb_.CreateCondBr(exception_pending, lpad, block_cont, kUnlikely);
+    irb_.CreateCondBr(exception_set, lpad, block_suspend, kLikely);
   } else {
-    irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont, kUnlikely);
+    irb_.CreateCondBr(exception_set, GetUnwindBasicBlock(), block_suspend, kLikely);
   }
 
+  irb_.SetInsertPoint(block_suspend);
+  if (dex_pc != art::DexFile::kDexNoIndex) {
+    EmitUpdateDexPC(dex_pc);
+  }
+  irb_.Runtime().EmitTestSuspend();
+  irb_.CreateBr(block_cont);
+
   irb_.SetInsertPoint(block_cont);
 }