@@ -441,6 +448,7 @@ cond_exec_process_if_block (ce_if_block_t * ce_info,
rtx else_first_tail = NULL_RTX; /* First match at the tail of ELSE */
int then_n_insns, else_n_insns, n_insns;
enum rtx_code false_code;
+ rtx uncombined_compare = NULL_RTX;
/* If test is comprised of && or || elements, and we've failed at handling
all of them together, just use the last test if it is the special case of
@@ -462,6 +470,26 @@ cond_exec_process_if_block (ce_if_block_t * ce_info,
if (! test_expr)
return FALSE;
+ /* Extract predicate for compare from combined if-then-else. */
+
+ if (then_bb && else_bb
+ && REGNO (XEXP (test_expr,0)) != CC_REGNUM)
+ {
+ /* Test_expr with non CC reg, so we need to emit compare and make
+ new test_expr with CC reg. */
+ rtx tmp_test_expr;
+ rtx tmp_cc_reg = gen_rtx_REG(CCmode, CC_REGNUM);
+
+ tmp_test_expr = gen_rtx_fmt_ee (GET_CODE (test_expr),
+ GET_MODE (test_expr),
+ tmp_cc_reg, const0_rtx);
+ uncombined_compare = gen_rtx_SET (GET_MODE (test_expr), tmp_cc_reg,
+ gen_rtx_COMPARE (CCmode,
+ XEXP (test_expr,0),
+ XEXP (test_expr,1)));
+ test_expr = tmp_test_expr;
+ }
+
/* If the conditional jump is more than just a conditional jump,
then we can not do conditional execution conversion on this block. */
if (! onlyjump_p (BB_END (test_bb)))
@@ -683,6 +711,19 @@ cond_exec_process_if_block (ce_if_block_t * ce_info,
IFCVT_MODIFY_FINAL (ce_info);
#endif
+ /* Second part of compare extraction. We should emit compare insn here. */
+ if (uncombined_compare != NULL_RTX)
+ {
+ rtx test_bb_end = last_active_insn (test_bb, TRUE);
+ if (test_bb_end)
+ emit_insn_after (uncombined_compare, test_bb_end);
+ else if (then_start)
+ emit_insn_before (uncombined_compare, then_start);
+ else if (else_start)
+ emit_insn_before (uncombined_compare, else_start);
+
+ }
+
/* Conversion succeeded. */
if (dump_file)
fprintf (dump_file, "%d insn%s converted to conditional execution.\n",