Commit 04cc79bb by Roger Sayle Committed by Roger Sayle

builtins.c (expand_builtin_expect_jump): Simplify logic.


	* builtins.c (expand_builtin_expect_jump): Simplify logic. Handle
	conditional jumps that drop through to unconditional jumps or the
	end of the sequence.

From-SVN: r75780
parent 3416f5c2
2004-01-12 Roger Sayle <roger@eyesopen.com>
* builtins.c (expand_builtin_expect_jump): Simplify logic. Handle
conditional jumps that drop through to unconditional jumps or the
end of the sequence.
2004-01-13 Jan Hubicka <jh@suse.cz> 2004-01-13 Jan Hubicka <jh@suse.cz>
* alias.c (new_alias_set): Construct the alias_set varray. * alias.c (new_alias_set): Construct the alias_set varray.
......
...@@ -4460,10 +4460,7 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label) ...@@ -4460,10 +4460,7 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label)
if (! if_false_label) if (! if_false_label)
if_false_label = drop_through_label; if_false_label = drop_through_label;
/* Now that the __builtin_expect has been validated, go through and add /* Go through and add the expect's to each of the conditional jumps. */
the expect's to each of the conditional jumps. If we run into an
error, just give up and generate the 'safe' code of doing a SCC
operation and then doing a branch on that. */
insn = ret; insn = ret;
while (insn != NULL_RTX) while (insn != NULL_RTX)
{ {
...@@ -4472,54 +4469,65 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label) ...@@ -4472,54 +4469,65 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label)
if (GET_CODE (insn) == JUMP_INSN && any_condjump_p (insn)) if (GET_CODE (insn) == JUMP_INSN && any_condjump_p (insn))
{ {
rtx ifelse = SET_SRC (pc_set (insn)); rtx ifelse = SET_SRC (pc_set (insn));
rtx label; rtx then_dest = XEXP (ifelse, 1);
int taken; rtx else_dest = XEXP (ifelse, 2);
int taken = -1;
if (GET_CODE (XEXP (ifelse, 1)) == LABEL_REF)
{ /* First check if we recognize any of the labels. */
taken = 1; if (GET_CODE (then_dest) == LABEL_REF
label = XEXP (XEXP (ifelse, 1), 0); && XEXP (then_dest, 1) == if_true_label)
} taken = 1;
/* An inverted jump reverses the probabilities. */ else if (GET_CODE (then_dest) == LABEL_REF
else if (GET_CODE (XEXP (ifelse, 2)) == LABEL_REF) && XEXP (then_dest, 1) == if_false_label)
taken = 0;
else if (GET_CODE (else_dest) == LABEL_REF
&& XEXP (else_dest, 1) == if_false_label)
taken = 1;
else if (GET_CODE (else_dest) == LABEL_REF
&& XEXP (else_dest, 1) == if_true_label)
taken = 0;
/* Otherwise check where we drop through. */
else if (else_dest == pc_rtx)
{ {
taken = 0; if (next && GET_CODE (next) == NOTE)
label = XEXP (XEXP (ifelse, 2), 0); next = next_nonnote_insn (next);
if (next && GET_CODE (next) == JUMP_INSN
&& any_uncondjump_p (next))
next = XEXP (SET_SRC (pc_set (next)), 1);
/* NEXT is either a CODE_LABEL, NULL_RTX or something
else that can't possibly match either target label. */
if (next == if_false_label)
taken = 1;
else if (next == if_true_label)
taken = 0;
} }
/* We shouldn't have to worry about conditional returns during else if (then_dest == pc_rtx)
the expansion stage, but handle it gracefully anyway. */
else if (GET_CODE (XEXP (ifelse, 1)) == RETURN)
{ {
taken = 1; if (next && GET_CODE (next) == NOTE)
label = NULL_RTX; next = next_nonnote_insn (next);
if (next && GET_CODE (next) == JUMP_INSN
&& any_uncondjump_p (next))
next = XEXP (SET_SRC (pc_set (next)), 1);
if (next == if_false_label)
taken = 0;
else if (next == if_true_label)
taken = 1;
} }
/* An inverted return reverses the probabilities. */
else if (GET_CODE (XEXP (ifelse, 2)) == RETURN) if (taken != -1)
{ {
taken = 0; /* If the test is expected to fail, reverse the
label = NULL_RTX; probabilities. */
if (integer_zerop (arg1))
taken = 1 - taken;
predict_insn_def (insn, PRED_BUILTIN_EXPECT, taken);
} }
else
goto do_next_insn;
/* If the test is expected to fail, reverse the
probabilities. */
if (integer_zerop (arg1))
taken = 1 - taken;
/* If we are jumping to the false label, reverse the
probabilities. */
if (label == NULL_RTX)
; /* conditional return */
else if (label == if_false_label)
taken = 1 - taken;
else if (label != if_true_label)
goto do_next_insn;
predict_insn_def (insn, PRED_BUILTIN_EXPECT, taken);
} }
do_next_insn:
insn = next; insn = next;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment