{
rtx target;
rtx_insn *seq;
- int reversep;
+ bool reversep;
HOST_WIDE_INT itrue, ifalse, diff, tmp;
- int normalize, can_reverse;
+ int normalize;
+ bool can_reverse;
machine_mode mode;
if (CONST_INT_P (if_info->a)
mode = GET_MODE (if_info->x);
ifalse = INTVAL (if_info->a);
itrue = INTVAL (if_info->b);
+ bool subtract_flag_p = false;
diff = (unsigned HOST_WIDE_INT) itrue - ifalse;
/* Make sure we can represent the difference between the two values. */
can_reverse = (reversed_comparison_code (if_info->cond, if_info->jump)
!= UNKNOWN);
- reversep = 0;
+ reversep = false;
if (diff == STORE_FLAG_VALUE || diff == -STORE_FLAG_VALUE)
- normalize = 0;
+ {
+ normalize = 0;
+ /* We could collapse these cases but it is easier to follow the
+ diff/STORE_FLAG_VALUE combinations when they are listed
+ explicitly. */
+
+ /* test ? 3 : 4
+ => 4 + (test != 0). */
+ if (diff < 0 && STORE_FLAG_VALUE < 0)
+ reversep = false;
+ /* test ? 4 : 3
+ => can_reverse | 4 + (test == 0)
+ !can_reverse | 3 - (test != 0). */
+ else if (diff > 0 && STORE_FLAG_VALUE < 0)
+ {
+ reversep = can_reverse;
+ subtract_flag_p = !can_reverse;
+ }
+ /* test ? 3 : 4
+ => can_reverse | 3 + (test == 0)
+ !can_reverse | 4 - (test != 0). */
+ else if (diff < 0 && STORE_FLAG_VALUE > 0)
+ {
+ reversep = can_reverse;
+ subtract_flag_p = !can_reverse;
+ }
+ /* test ? 4 : 3
+ => 4 + (test != 0). */
+ else if (diff > 0 && STORE_FLAG_VALUE > 0)
+ reversep = false;
+ else
+ gcc_unreachable ();
+ }
else if (ifalse == 0 && exact_log2 (itrue) >= 0
&& (STORE_FLAG_VALUE == 1
|| if_info->branch_cost >= 2))
normalize = 1;
else if (itrue == 0 && exact_log2 (ifalse) >= 0 && can_reverse
&& (STORE_FLAG_VALUE == 1 || if_info->branch_cost >= 2))
- normalize = 1, reversep = 1;
+ {
+ normalize = 1;
+ reversep = true;
+ }
else if (itrue == -1
&& (STORE_FLAG_VALUE == -1
|| if_info->branch_cost >= 2))
normalize = -1;
else if (ifalse == -1 && can_reverse
&& (STORE_FLAG_VALUE == -1 || if_info->branch_cost >= 2))
- normalize = -1, reversep = 1;
+ {
+ normalize = -1;
+ reversep = true;
+ }
else if ((if_info->branch_cost >= 2 && STORE_FLAG_VALUE == -1)
|| if_info->branch_cost >= 3)
normalize = -1;
=> x = 3 + (test == 0); */
if (diff == STORE_FLAG_VALUE || diff == -STORE_FLAG_VALUE)
{
- target = expand_simple_binop (mode,
- (diff == STORE_FLAG_VALUE
- ? PLUS : MINUS),
+ /* Always use ifalse here. It should have been swapped with itrue
+ when appropriate when reversep is true. */
+ target = expand_simple_binop (mode, subtract_flag_p ? MINUS : PLUS,
gen_int_mode (ifalse, mode), target,
if_info->x, 0, OPTAB_WIDEN);
}
goto success;
if (noce_try_abs (if_info))
goto success;
+ if (!targetm.have_conditional_execution ()
+ && noce_try_store_flag_constants (if_info))
+ goto success;
if (HAVE_conditional_move
&& noce_try_cmove (if_info))
goto success;
if (! targetm.have_conditional_execution ())
{
- if (noce_try_store_flag_constants (if_info))
- goto success;
if (noce_try_addcc (if_info))
goto success;
if (noce_try_store_flag_mask (if_info))