summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/ifcvt.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/ifcvt.c')
-rw-r--r--contrib/gcc/ifcvt.c181
1 files changed, 104 insertions, 77 deletions
diff --git a/contrib/gcc/ifcvt.c b/contrib/gcc/ifcvt.c
index a7860e3..0d65eab 100644
--- a/contrib/gcc/ifcvt.c
+++ b/contrib/gcc/ifcvt.c
@@ -27,6 +27,7 @@
#include "flags.h"
#include "insn-config.h"
#include "recog.h"
+#include "except.h"
#include "hard-reg-set.h"
#include "basic-block.h"
#include "expr.h"
@@ -104,6 +105,7 @@ static int find_if_block PARAMS ((basic_block, edge, edge));
static int find_if_case_1 PARAMS ((basic_block, edge, edge));
static int find_if_case_2 PARAMS ((basic_block, edge, edge));
static int find_cond_trap PARAMS ((basic_block, edge, edge));
+static rtx block_has_only_trap PARAMS ((basic_block));
static int find_memory PARAMS ((rtx *, void *));
static int dead_or_predicable PARAMS ((basic_block, basic_block,
basic_block, basic_block, int));
@@ -620,7 +622,7 @@ noce_try_store_flag (if_info)
seq = get_insns ();
end_sequence ();
- emit_insns_before (seq, if_info->cond_earliest);
+ emit_insns_before (seq, if_info->jump);
return TRUE;
}
@@ -755,7 +757,7 @@ noce_try_store_flag_constants (if_info)
if (seq_contains_jump (seq))
return FALSE;
- emit_insns_before (seq, if_info->cond_earliest);
+ emit_insns_before (seq, if_info->jump);
return TRUE;
}
@@ -815,7 +817,7 @@ noce_try_store_flag_inc (if_info)
if (seq_contains_jump (seq))
return FALSE;
- emit_insns_before (seq, if_info->cond_earliest);
+ emit_insns_before (seq, if_info->jump);
return TRUE;
}
@@ -867,7 +869,7 @@ noce_try_store_flag_mask (if_info)
if (seq_contains_jump (seq))
return FALSE;
- emit_insns_before (seq, if_info->cond_earliest);
+ emit_insns_before (seq, if_info->jump);
return TRUE;
}
@@ -962,7 +964,7 @@ noce_try_cmove (if_info)
seq = get_insns ();
end_sequence ();
- emit_insns_before (seq, if_info->cond_earliest);
+ emit_insns_before (seq, if_info->jump);
return TRUE;
}
else
@@ -1124,7 +1126,7 @@ noce_try_cmove_arith (if_info)
tmp = get_insns ();
end_sequence ();
- emit_insns_before (tmp, if_info->cond_earliest);
+ emit_insns_before (tmp, if_info->jump);
return TRUE;
end_seq_and_fail:
@@ -1377,7 +1379,7 @@ noce_try_minmax (if_info)
if (seq_contains_jump (seq))
return FALSE;
- emit_insns_before (seq, earliest);
+ emit_insns_before (seq, if_info->jump);
if_info->cond = cond;
if_info->cond_earliest = earliest;
@@ -1495,7 +1497,7 @@ noce_try_abs (if_info)
if (seq_contains_jump (seq))
return FALSE;
- emit_insns_before (seq, earliest);
+ emit_insns_before (seq, if_info->jump);
if_info->cond = cond;
if_info->cond_earliest = earliest;
@@ -1783,7 +1785,7 @@ noce_process_if_block (test_bb, then_bb, else_bb, join_bb)
if (insn_b && else_bb)
delete_insn (insn_b);
- /* The new insns will have been inserted before cond_earliest. We should
+ /* The new insns will have been inserted just before the jump. We should
be able to remove the jump with impunity, but the condition itself may
have been modified by gcse to be shared across basic blocks. */
delete_insn (jump);
@@ -1844,11 +1846,14 @@ merge_if_block (test_bb, then_bb, else_bb, join_bb)
/* First merge TEST block into THEN block. This is a no-brainer since
the THEN block did not have a code label to begin with. */
-
- if (life_data_ok)
- COPY_REG_SET (combo_bb->global_live_at_end, then_bb->global_live_at_end);
- merge_blocks_nomove (combo_bb, then_bb);
- num_removed_blocks++;
+ if (then_bb)
+ {
+ if (life_data_ok)
+ COPY_REG_SET (combo_bb->global_live_at_end,
+ then_bb->global_live_at_end);
+ merge_blocks_nomove (combo_bb, then_bb);
+ num_removed_blocks++;
+ }
/* The ELSE block, if it existed, had a label. That label count
will almost always be zero, but odd things can happen when labels
@@ -1864,14 +1869,34 @@ merge_if_block (test_bb, then_bb, else_bb, join_bb)
if (! join_bb)
{
+ rtx last = combo_bb->end;
+
/* The outgoing edge for the current COMBO block should already
be correct. Verify this. */
if (combo_bb->succ == NULL_EDGE)
- abort ();
+ {
+ if (find_reg_note (last, REG_NORETURN, NULL))
+ ;
+ else if (GET_CODE (last) == INSN
+ && GET_CODE (PATTERN (last)) == TRAP_IF
+ && TRAP_CONDITION (PATTERN (last)) == const_true_rtx)
+ ;
+ else
+ abort ();
+ }
- /* There should still be a branch at the end of the THEN or ELSE
+ /* There should still be something at the end of the THEN or ELSE
blocks taking us to our final destination. */
- if (GET_CODE (combo_bb->end) != JUMP_INSN)
+ else if (GET_CODE (last) == JUMP_INSN)
+ ;
+ else if (combo_bb->succ->dest == EXIT_BLOCK_PTR
+ && GET_CODE (last) == CALL_INSN
+ && SIBLING_CALL_P (last))
+ ;
+ else if ((combo_bb->succ->flags & EDGE_EH)
+ && can_throw_internal (last))
+ ;
+ else
abort ();
}
@@ -2090,68 +2115,27 @@ find_cond_trap (test_bb, then_edge, else_edge)
basic_block test_bb;
edge then_edge, else_edge;
{
- basic_block then_bb, else_bb, join_bb, trap_bb;
+ basic_block then_bb, else_bb, trap_bb, other_bb;
rtx trap, jump, cond, cond_earliest, seq;
enum rtx_code code;
then_bb = then_edge->dest;
else_bb = else_edge->dest;
- join_bb = NULL;
/* Locate the block with the trap instruction. */
/* ??? While we look for no successors, we really ought to allow
EH successors. Need to fix merge_if_block for that to work. */
- /* ??? We can't currently handle merging the blocks if they are not
- already adjacent. Prevent losage in merge_if_block by detecting
- this now. */
- if (then_bb->succ == NULL)
- {
- trap_bb = then_bb;
- if (else_bb->index != then_bb->index + 1)
- return FALSE;
- join_bb = else_bb;
- else_bb = NULL;
- }
- else if (else_bb->succ == NULL)
- {
- trap_bb = else_bb;
- if (else_bb->index != then_bb->index + 1)
- else_bb = NULL;
- else if (then_bb->succ
- && ! then_bb->succ->succ_next
- && ! (then_bb->succ->flags & EDGE_COMPLEX)
- && then_bb->succ->dest->index == else_bb->index + 1)
- join_bb = then_bb->succ->dest;
- }
+ if ((trap = block_has_only_trap (then_bb)) != NULL)
+ trap_bb = then_bb, other_bb = else_bb;
+ else if ((trap = block_has_only_trap (else_bb)) != NULL)
+ trap_bb = else_bb, other_bb = then_bb;
else
return FALSE;
- /* Don't confuse a conditional return with something we want to
- optimize here. */
- if (trap_bb == EXIT_BLOCK_PTR)
- return FALSE;
-
- /* The only instruction in the THEN block must be the trap. */
- trap = first_active_insn (trap_bb);
- if (! (trap == trap_bb->end
- && GET_CODE (PATTERN (trap)) == TRAP_IF
- && TRAP_CONDITION (PATTERN (trap)) == const_true_rtx))
- return FALSE;
-
if (rtl_dump_file)
{
- if (trap_bb == then_bb)
- fprintf (rtl_dump_file,
- "\nTRAP-IF block found, start %d, trap %d",
- test_bb->index, then_bb->index);
- else
- fprintf (rtl_dump_file,
- "\nTRAP-IF block found, start %d, then %d, trap %d",
- test_bb->index, then_bb->index, trap_bb->index);
- if (join_bb)
- fprintf (rtl_dump_file, ", join %d\n", join_bb->index);
- else
- fputc ('\n', rtl_dump_file);
+ fprintf (rtl_dump_file, "\nTRAP-IF block found, start %d, trap %d\n",
+ test_bb->index, trap_bb->index);
}
/* If this is not a standard conditional jump, we can't parse it. */
@@ -2184,26 +2168,67 @@ find_cond_trap (test_bb, then_edge, else_edge)
if (seq == NULL)
return FALSE;
- /* Emit the new insns before cond_earliest; delete the old jump
- and trap insns. */
-
+ /* Emit the new insns before cond_earliest. */
emit_insn_before (seq, cond_earliest);
- delete_insn (jump);
-
- delete_insn (trap);
-
- /* Merge the blocks! */
- if (trap_bb != then_bb && ! else_bb)
+ /* Delete the trap block if possible. */
+ remove_edge (trap_bb == then_bb ? then_edge : else_edge);
+ if (trap_bb->pred == NULL)
{
flow_delete_block (trap_bb);
num_removed_blocks++;
}
- merge_if_block (test_bb, then_bb, else_bb, join_bb);
+
+ /* If the non-trap block and the test are now adjacent, merge them.
+ Otherwise we must insert a direct branch. */
+ if (test_bb->index + 1 == other_bb->index)
+ {
+ delete_insn (jump);
+ merge_if_block (test_bb, NULL, NULL, other_bb);
+ }
+ else
+ {
+ rtx lab, newjump;
+
+ lab = JUMP_LABEL (jump);
+ newjump = emit_jump_insn_after (gen_jump (lab), jump);
+ LABEL_NUSES (lab) += 1;
+ JUMP_LABEL (newjump) = lab;
+ emit_barrier_after (newjump);
+
+ delete_insn (jump);
+ }
return TRUE;
}
+/* Subroutine of find_cond_trap: if BB contains only a trap insn,
+ return it. */
+
+static rtx
+block_has_only_trap (bb)
+ basic_block bb;
+{
+ rtx trap;
+
+ /* We're not the exit block. */
+ if (bb == EXIT_BLOCK_PTR)
+ return NULL_RTX;
+
+ /* The block must have no successors. */
+ if (bb->succ)
+ return NULL_RTX;
+
+ /* The only instruction in the THEN block must be the trap. */
+ trap = first_active_insn (bb);
+ if (! (trap == bb->end
+ && GET_CODE (PATTERN (trap)) == TRAP_IF
+ && TRAP_CONDITION (PATTERN (trap)) == const_true_rtx))
+ return NULL_RTX;
+
+ return trap;
+}
+
/* Look for IF-THEN-ELSE cases in which one of THEN or ELSE is
transformable, but not necessarily the other. There need be no
JOIN block.
@@ -2444,7 +2469,7 @@ dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
basic_block new_dest;
int reversep;
{
- rtx head, end, jump, earliest, old_dest, new_label;
+ rtx head, end, jump, earliest, old_dest, new_label = NULL_RTX;
jump = test_bb->end;
@@ -2756,6 +2781,7 @@ if_convert (x_life_data_ok)
if (UPDATE_LIFE (BASIC_BLOCK (block_num)))
SET_BIT (update_life_blocks, block_num);
+ clear_aux_for_blocks ();
count_or_remove_death_notes (update_life_blocks, 1);
/* ??? See about adding a mode that verifies that the initial
set of blocks don't let registers come live. */
@@ -2765,7 +2791,8 @@ if_convert (x_life_data_ok)
sbitmap_free (update_life_blocks);
}
- clear_aux_for_blocks ();
+ else
+ clear_aux_for_blocks ();
/* Write the final stats. */
if (rtl_dump_file && num_possible_if_blocks > 0)
OpenPOWER on IntegriCloud