predict.c (estimate_probability): Examine both sides of a branch for no exits.

* predict.c (estimate_probability): Examine both sides of
        a branch for no exits.  Use 90% not 50% for predict taken.
        Reorg for one copy of note generation code.

From-SVN: r33343
This commit is contained in:
Richard Henderson 2000-04-22 12:16:03 -07:00 committed by Richard Henderson
parent b2433fcde0
commit 9bcbfc524a
2 changed files with 48 additions and 32 deletions

View File

@ -1,3 +1,9 @@
2000-04-22 Richard Henderson <rth@cygnus.com>
* predict.c (estimate_probability): Examine both sides of
a branch for no exits. Use 90% not 50% for predict taken.
Reorg for one copy of note generation code.
2000-04-22 Richard Henderson <rth@cygnus.com> 2000-04-22 Richard Henderson <rth@cygnus.com>
* flow.c (mark_used_reg): Hack around rs6000 eliminable pic reg. * flow.c (mark_used_reg): Hack around rs6000 eliminable pic reg.

View File

@ -103,34 +103,32 @@ estimate_probability (loops_info)
{ {
rtx last_insn = BLOCK_END (i); rtx last_insn = BLOCK_END (i);
rtx cond, earliest; rtx cond, earliest;
int prob = 0; int prob;
edge e; edge e;
if (GET_CODE (last_insn) != JUMP_INSN if (GET_CODE (last_insn) != JUMP_INSN
|| ! condjump_p (last_insn) || simplejump_p (last_insn)) || ! condjump_p (last_insn) || simplejump_p (last_insn))
continue; continue;
if (find_reg_note (last_insn, REG_BR_PROB, 0)) if (find_reg_note (last_insn, REG_BR_PROB, 0))
continue; continue;
cond = get_condition (last_insn, &earliest); cond = get_condition (last_insn, &earliest);
if (! cond) if (! cond)
continue; continue;
/* If the jump branches around a block with no successors, /* If one of the successor blocks has no successors, predict
predict it to be taken. */ that side not taken. */
prob = 0; /* ??? Ought to do the same for any subgraph with no exit. */
for (e = BASIC_BLOCK (i)->succ; e; e = e->succ_next) for (e = BASIC_BLOCK (i)->succ; e; e = e->succ_next)
if ((e->flags & EDGE_FALLTHRU) && e->dest->succ == NULL) if (e->dest->succ == NULL)
{ {
prob = REG_BR_PROB_BASE; if (e->flags & EDGE_FALLTHRU)
break; prob = REG_BR_PROB_BASE;
else
prob = 0;
goto emitnote;
} }
if (prob)
{
REG_NOTES (last_insn)
= gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (prob),
REG_NOTES (last_insn));
continue;
}
/* Try "pointer heuristic." /* Try "pointer heuristic."
A comparison ptr == 0 is predicted as false. A comparison ptr == 0 is predicted as false.
@ -143,7 +141,10 @@ estimate_probability (loops_info)
&& (XEXP (cond, 1) == const0_rtx && (XEXP (cond, 1) == const0_rtx
|| (GET_CODE (XEXP (cond, 1)) == REG || (GET_CODE (XEXP (cond, 1)) == REG
&& REGNO_POINTER_FLAG (REGNO (XEXP (cond, 1)))))) && REGNO_POINTER_FLAG (REGNO (XEXP (cond, 1))))))
prob = REG_BR_PROB_BASE / 10; {
prob = REG_BR_PROB_BASE / 10;
goto emitnote;
}
break; break;
case NE: case NE:
if (GET_CODE (XEXP (cond, 0)) == REG if (GET_CODE (XEXP (cond, 0)) == REG
@ -151,17 +152,14 @@ estimate_probability (loops_info)
&& (XEXP (cond, 1) == const0_rtx && (XEXP (cond, 1) == const0_rtx
|| (GET_CODE (XEXP (cond, 1)) == REG || (GET_CODE (XEXP (cond, 1)) == REG
&& REGNO_POINTER_FLAG (REGNO (XEXP (cond, 1)))))) && REGNO_POINTER_FLAG (REGNO (XEXP (cond, 1))))))
prob = REG_BR_PROB_BASE / 2; {
prob = REG_BR_PROB_BASE - (REG_BR_PROB_BASE / 10);
goto emitnote;
}
break; break;
default: default:
prob = 0; break;
}
if (prob)
{
REG_NOTES (last_insn)
= gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (prob),
REG_NOTES (last_insn));
continue;
} }
/* Try "opcode heuristic." /* Try "opcode heuristic."
@ -172,30 +170,42 @@ estimate_probability (loops_info)
{ {
case CONST_INT: case CONST_INT:
/* Unconditional branch. */ /* Unconditional branch. */
prob = REG_BR_PROB_BASE / 2; prob = (cond == const0_rtx ? 0 : REG_BR_PROB_BASE);
break; goto emitnote;
case EQ: case EQ:
prob = REG_BR_PROB_BASE / 10; prob = REG_BR_PROB_BASE / 10;
break; goto emitnote;
case NE: case NE:
prob = REG_BR_PROB_BASE / 2; prob = REG_BR_PROB_BASE - (REG_BR_PROB_BASE / 10);
break; goto emitnote;
case LE: case LE:
case LT: case LT:
if (XEXP (cond, 1) == const0_rtx) if (XEXP (cond, 1) == const0_rtx)
prob = REG_BR_PROB_BASE / 10; {
prob = REG_BR_PROB_BASE / 10;
goto emitnote;
}
break; break;
case GE: case GE:
case GT: case GT:
if (XEXP (cond, 1) == const0_rtx if (XEXP (cond, 1) == const0_rtx
|| (GET_CODE (XEXP (cond, 1)) == CONST_INT || (GET_CODE (XEXP (cond, 1)) == CONST_INT
&& INTVAL (XEXP (cond, 1)) == -1)) && INTVAL (XEXP (cond, 1)) == -1))
prob = REG_BR_PROB_BASE / 2; {
prob = REG_BR_PROB_BASE - (REG_BR_PROB_BASE / 10);
goto emitnote;
}
break; break;
default: default:
prob = 0; break;
} }
/* If we havn't chosen something by now, predict 50-50. */
prob = REG_BR_PROB_BASE / 2;
emitnote:
REG_NOTES (last_insn) REG_NOTES (last_insn)
= gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (prob), = gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (prob),
REG_NOTES (last_insn)); REG_NOTES (last_insn));