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 (revision 110916)
--- gcc/tree-vrp.c (working copy)
*************** extract_range_from_binary_expr (value_ra
*** 1278,1285 ****
&& code != TRUTH_ANDIF_EXPR
&& code != TRUTH_ORIF_EXPR
&& code != TRUTH_AND_EXPR
! && code != TRUTH_OR_EXPR
! && code != TRUTH_XOR_EXPR)
{
set_value_range_to_varying (vr);
return;
--- 1278,1284 ----
&& code != TRUTH_ANDIF_EXPR
&& code != TRUTH_ORIF_EXPR
&& code != TRUTH_AND_EXPR
! && code != TRUTH_OR_EXPR)
{
set_value_range_to_varying (vr);
return;
*************** extract_range_from_binary_expr (value_ra
*** 1365,1372 ****
if (code == TRUTH_ANDIF_EXPR
|| code == TRUTH_ORIF_EXPR
|| code == TRUTH_AND_EXPR
! || code == TRUTH_OR_EXPR
! || code == TRUTH_XOR_EXPR)
{
/* If one of the operands is zero, we know that the whole
expression evaluates zero. */
--- 1364,1370 ----
if (code == TRUTH_ANDIF_EXPR
|| code == TRUTH_ORIF_EXPR
|| code == TRUTH_AND_EXPR
! || code == TRUTH_OR_EXPR)
{
/* If one of the operands is zero, we know that the whole
expression evaluates zero. */