summaryrefslogtreecommitdiff
path: root/gcc/dojump.c
diff options
context:
space:
mode:
authormrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-20 23:47:35 +0000
committermrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-20 23:47:35 +0000
commit6b40961666f073231ed8a76e6e33deeda063cde7 (patch)
tree8247eb4232e8be98b7f61bd68bab2fd1a9f06ca3 /gcc/dojump.c
parente6b1b76450af5f98696ecedd4bd9a0ed18cdb2a6 (diff)
parentfc1ce0cf396bf638746d546a557158d87f13849b (diff)
downloadgcc-6b40961666f073231ed8a76e6e33deeda063cde7.tar.gz
Merge in trunk.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/wide-int@203881 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/dojump.c')
-rw-r--r--gcc/dojump.c82
1 files changed, 58 insertions, 24 deletions
diff --git a/gcc/dojump.c b/gcc/dojump.c
index 700a17c9653..b7b78050217 100644
--- a/gcc/dojump.c
+++ b/gcc/dojump.c
@@ -311,32 +311,66 @@ do_jump_1 (enum tree_code code, tree op0, tree op1,
break;
case TRUTH_ANDIF_EXPR:
- if (if_false_label == NULL_RTX)
- {
- drop_through_label = gen_label_rtx ();
- do_jump (op0, drop_through_label, NULL_RTX, prob);
- do_jump (op1, NULL_RTX, if_true_label, prob);
- }
- else
- {
- do_jump (op0, if_false_label, NULL_RTX, prob);
- do_jump (op1, if_false_label, if_true_label, prob);
- }
- break;
+ {
+ /* Spread the probability that the expression is false evenly between
+ the two conditions. So the first condition is false half the total
+ probability of being false. The second condition is false the other
+ half of the total probability of being false, so its jump has a false
+ probability of half the total, relative to the probability we
+ reached it (i.e. the first condition was true). */
+ int op0_prob = -1;
+ int op1_prob = -1;
+ if (prob != -1)
+ {
+ int false_prob = inv (prob);
+ int op0_false_prob = false_prob / 2;
+ int op1_false_prob = GCOV_COMPUTE_SCALE ((false_prob / 2),
+ inv (op0_false_prob));
+ /* Get the probability that each jump below is true. */
+ op0_prob = inv (op0_false_prob);
+ op1_prob = inv (op1_false_prob);
+ }
+ if (if_false_label == NULL_RTX)
+ {
+ drop_through_label = gen_label_rtx ();
+ do_jump (op0, drop_through_label, NULL_RTX, op0_prob);
+ do_jump (op1, NULL_RTX, if_true_label, op1_prob);
+ }
+ else
+ {
+ do_jump (op0, if_false_label, NULL_RTX, op0_prob);
+ do_jump (op1, if_false_label, if_true_label, op1_prob);
+ }
+ break;
+ }
case TRUTH_ORIF_EXPR:
- if (if_true_label == NULL_RTX)
- {
- drop_through_label = gen_label_rtx ();
- do_jump (op0, NULL_RTX, drop_through_label, prob);
- do_jump (op1, if_false_label, NULL_RTX, prob);
- }
- else
- {
- do_jump (op0, NULL_RTX, if_true_label, prob);
- do_jump (op1, if_false_label, if_true_label, prob);
- }
- break;
+ {
+ /* Spread the probability evenly between the two conditions. So
+ the first condition has half the total probability of being true.
+ The second condition has the other half of the total probability,
+ so its jump has a probability of half the total, relative to
+ the probability we reached it (i.e. the first condition was false). */
+ int op0_prob = -1;
+ int op1_prob = -1;
+ if (prob != -1)
+ {
+ op0_prob = prob / 2;
+ op1_prob = GCOV_COMPUTE_SCALE ((prob / 2), inv (op0_prob));
+ }
+ if (if_true_label == NULL_RTX)
+ {
+ drop_through_label = gen_label_rtx ();
+ do_jump (op0, NULL_RTX, drop_through_label, op0_prob);
+ do_jump (op1, if_false_label, NULL_RTX, op1_prob);
+ }
+ else
+ {
+ do_jump (op0, NULL_RTX, if_true_label, op0_prob);
+ do_jump (op1, if_false_label, if_true_label, op1_prob);
+ }
+ break;
+ }
default:
gcc_unreachable ();