This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Avoid division by zero during prediction merging
- From: Jakub Jelinek <jakub at redhat dot com>
- To: rth at redhat dot com, jh at suse dot cz
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 7 Jan 2002 17:31:27 +0100
- Subject: [PATCH] Avoid division by zero during prediction merging
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
gcc ICEs when doing combine_predictions_for_insn on:
(jump_insn 6083 6082 6084 (set (pc)
(if_then_else (eq (reg/v:DI 2478)
(const_int 0 [0x0]))
(label_ref 6132)
(pc))) 175 {*bcc_normal} (nil)
(expr_list:REG_BR_PRED (concat (const_int 17 [0x11])
(const_int 3000 [0xbb8]))
(expr_list:REG_BR_PRED (concat (const_int 9 [0x9])
(const_int 28 [0x1c]))
(expr_list:REG_BR_PRED (concat (const_int 9 [0x9])
(const_int 28 [0x1c]))
(expr_list:REG_BR_PRED (concat (const_int 9 [0x9])
(const_int 10000 [0x2710]))
(expr_list:REG_BR_PRED (concat (const_int 9 [0x9])
(const_int 10000 [0x2710]))
(nil)))))))
(the testcase is quite large and cannot be easily simplified, I'll try
harder when I find time to create a testcase from it).
The thing is that if combined_probability is 0% and probability is 100%
(as in this case) or the other way around, d is 0 and thus it tries to
divide by zero. The following patch uses its lim instead (50%).
Ok to commit?
2002-01-07 Jakub Jelinek <jakub@redhat.com>
* predict.c (combine_predictions_for_insn): Avoid division by zero.
--- gcc/predict.c.jj Sat Dec 29 22:11:41 2001
+++ gcc/predict.c Mon Jan 7 18:26:59 2002
@@ -253,8 +253,12 @@ combine_predictions_for_insn (insn, bb)
* (REG_BR_PROB_BASE - probability));
/* Use FP math to avoid overflows of 32bit integers. */
- combined_probability = (((double) combined_probability) * probability
- * REG_BR_PROB_BASE / d + 0.5);
+ if (d == 0)
+ /* If one probability is 0% and one 100%, avoid division by zero. */
+ combined_probability = REG_BR_PROB_BASE / 2;
+ else
+ combined_probability = (((double) combined_probability) * probability
+ * REG_BR_PROB_BASE / d + 0.5);
}
/* Decide which heuristic to use. In case we didn't match anything,
Jakub