Index: combine.c
===================================================================
--- combine.c	(revision 183953)
+++ combine.c	(working copy)
@@ -10687,6 +10687,30 @@ recog_for_combine (rtx *pnewpat, rtx insn, rtx *pn
       print_rtl_single (dump_file, pat);
     }
 
+  /* If PAT is a PARALLEL with two SETs, swap the SETs and try again.  */
+  if (insn_code_number < 0
+      && GET_CODE (pat) == PARALLEL
+      && XVECLEN (pat, 0) == 2
+      && GET_CODE (XVECEXP (pat, 0, 0)) == SET
+      && GET_CODE (XVECEXP (pat, 0, 1)) == SET)
+    {
+      rtx set0 = XVECEXP (pat, 0, 0);
+      rtx set1 = XVECEXP (pat, 0, 1);
+
+      SUBST (XVECEXP (pat, 0, 0), set1);
+      SUBST (XVECEXP (pat, 0, 1), set0);
+
+      insn_code_number = recog (pat, insn, &num_clobbers_to_add);
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	{
+	  if (insn_code_number < 0)
+	    fputs ("Failed to match this instruction:\n", dump_file);
+	  else
+	    fputs ("Successfully matched this instruction:\n", dump_file);
+	  print_rtl_single (dump_file, pat);
+	}
+    }
+
   /* If it isn't, there is the possibility that we previously had an insn
      that clobbered some register as a side effect, but the combined
      insn doesn't need to do that.  So try once more without the clobbers
Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 183953)
+++ config/i386/i386.md	(working copy)
@@ -5808,14 +5808,14 @@
 	(zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))])
 
 (define_insn "*add<mode>_2"
-  [(set (reg FLAGS_REG)
+  [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
+	(plus:SWI
+	  (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
+	  (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>")))
+   (set (reg FLAGS_REG)
 	(compare
-	  (plus:SWI
-	    (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
-	    (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>"))
-	  (const_int 0)))
-   (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
-	(plus:SWI (match_dup 1) (match_dup 2)))]
+	  (plus:SWI (match_dup 1) (match_dup 2))
+	  (const_int 0)))]
   "ix86_match_ccmode (insn, CCGOCmode)
    && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
 {
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 183953)
+++ config/i386/i386.c	(working copy)
@@ -17611,7 +17611,7 @@ ix86_match_ccmode (rtx insn, enum machine_mode req
 
   set = PATTERN (insn);
   if (GET_CODE (set) == PARALLEL)
-    set = XVECEXP (set, 0, 0);
+    set = XVECEXP (set, 0, 1);
   gcc_assert (GET_CODE (set) == SET);
   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
 
@@ -38685,6 +38685,9 @@ ix86_autovectorize_vector_sizes (void)
 #undef TARGET_EXPAND_TO_RTL_HOOK
 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
 
+#undef TARGET_FLAGS_REGNUM
+#define TARGET_FLAGS_REGNUM FLAGS_REG
+
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
 
