File vrp.patch of Package gcc41
While working on improving tree-vrp's ability to discover
non-null ranges and half-ranges I discovered that it was
mis-handling TRUTH_XOR_EXPR.
The current code will incorrectly handle
[0, 1] TRUTH_XOR [0, 1]
The obvious result should be [0, 1], but due to a bug in
extract_range_from_binary_expr, we instead get [0, 0].
Long term it's not clear to me that we get any significant
benefit from handling TRUTH_XXX_EXPRs in tree-vrp.c. If we
do nothing we should be getting [0, 1]. The only time we
can do better is when one of the operands is known true or
known false. And those kind of cases should really be
encoded into fold-const.c rather than in each optimizer.
Anyway, this patch removes the buggy handling of TRUTH_XOR_EXPR.
Bootstrapped and regression tested on i686-pc-linux-gnu. I've
also verified this fixes the bootstrap failure when the VRP
enhancements to find more non-null and half ranges.
* tree-vrp.c (extract_range_from_binary_expr): Remove handling of
TRUTH_XOR_EPR.
Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c.orig 2007-01-15 11:13:48.000000000 +0100
+++ gcc/tree-vrp.c 2009-11-20 13:41:18.000000000 +0100
@@ -1226,8 +1226,7 @@ extract_range_from_binary_expr (value_ra
&& code != TRUTH_ANDIF_EXPR
&& code != TRUTH_ORIF_EXPR
&& code != TRUTH_AND_EXPR
- && code != TRUTH_OR_EXPR
- && code != TRUTH_XOR_EXPR)
+ && code != TRUTH_OR_EXPR)
{
set_value_range_to_varying (vr);
return;
@@ -1305,8 +1304,7 @@ extract_range_from_binary_expr (value_ra
if (code == TRUTH_ANDIF_EXPR
|| code == TRUTH_ORIF_EXPR
|| code == TRUTH_AND_EXPR
- || code == TRUTH_OR_EXPR
- || code == TRUTH_XOR_EXPR)
+ || code == TRUTH_OR_EXPR)
{
/* Boolean expressions cannot be folded with int_const_binop. */
min = fold_binary (code, TREE_TYPE (expr), vr0.min, vr1.min);