Commit 0f36b2da by Richard Guenther Committed by Richard Biener

re PR tree-optimization/49984 (VRP does not handle BIT_XOR_EXPR)

2011-08-05  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/49984
	* tree-vrp.c (extract_range_from_binary_expr_1): Handle BIT_XOR_EXPR.

	* gcc.dg/tree-ssa/vrp59.c: New testcase.

From-SVN: r177425
parent 8b201bc5
2011-08-05 Richard Guenther <rguenther@suse.de> 2011-08-05 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49984
* tree-vrp.c (extract_range_from_binary_expr_1): Handle BIT_XOR_EXPR.
2011-08-05 Richard Guenther <rguenther@suse.de>
* tree-vrp.c (zero_nonzero_bits_from_vr): Make sure to always * tree-vrp.c (zero_nonzero_bits_from_vr): Make sure to always
return true for constant integer ranges. return true for constant integer ranges.
(extract_range_from_binary_expr_1): Simplify BIT_AND_EXPR and (extract_range_from_binary_expr_1): Simplify BIT_AND_EXPR and
......
2011-08-05 Richard Guenther <rguenther@suse.de> 2011-08-05 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49984
* gcc.dg/tree-ssa/vrp59.c: New testcase.
2011-08-05 Richard Guenther <rguenther@suse.de>
* gcc.dg/tree-ssa/vrp51.c: Disable CCP. * gcc.dg/tree-ssa/vrp51.c: Disable CCP.
* gcc.dg/tree-ssa/vrp52.c: Likewise. * gcc.dg/tree-ssa/vrp52.c: Likewise.
* gcc.dg/tree-ssa/vrp53.c: Likewise. * gcc.dg/tree-ssa/vrp53.c: Likewise.
......
/* { dg-do compile } */
/* { dg-options "-O2 -fno-tree-ccp -fdump-tree-vrp1" } */
int f(int x)
{
if (x >= 0 && x <= 3)
{
x = x ^ 3;
x = x & 3;
}
return x;
}
int g(int x)
{
if (x >= 0 && x <= 3)
{
x = x ^ 2;
x = x & 3;
}
return x;
}
int h(int x)
{
if (x >= 0 && x <= 3)
{
x = x ^ 1;
x = x & 3;
}
return x;
}
/* { dg-final { scan-tree-dump-not " & 3;" "vrp1" } } */
/* { dg-final { cleanup-tree-dump "vrp1" } } */
...@@ -2214,7 +2214,8 @@ extract_range_from_binary_expr_1 (value_range_t *vr, ...@@ -2214,7 +2214,8 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
&& code != MIN_EXPR && code != MIN_EXPR
&& code != MAX_EXPR && code != MAX_EXPR
&& code != BIT_AND_EXPR && code != BIT_AND_EXPR
&& code != BIT_IOR_EXPR) && code != BIT_IOR_EXPR
&& code != BIT_XOR_EXPR)
{ {
set_value_range_to_varying (vr); set_value_range_to_varying (vr);
return; return;
...@@ -2635,7 +2636,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr, ...@@ -2635,7 +2636,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
min = vrp_int_const_binop (code, vr0.min, vr1.max); min = vrp_int_const_binop (code, vr0.min, vr1.max);
max = vrp_int_const_binop (code, vr0.max, vr1.min); max = vrp_int_const_binop (code, vr0.max, vr1.min);
} }
else if (code == BIT_AND_EXPR || code == BIT_IOR_EXPR) else if (code == BIT_AND_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR)
{ {
bool int_cst_range0, int_cst_range1; bool int_cst_range0, int_cst_range1;
double_int may_be_nonzero0, may_be_nonzero1; double_int may_be_nonzero0, may_be_nonzero1;
...@@ -2694,6 +2695,35 @@ extract_range_from_binary_expr_1 (value_range_t *vr, ...@@ -2694,6 +2695,35 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
if (int_cst_range1) if (int_cst_range1)
min = vrp_int_const_binop (MAX_EXPR, min, vr1.min); min = vrp_int_const_binop (MAX_EXPR, min, vr1.min);
} }
else if (code == BIT_XOR_EXPR)
{
double_int result_zero_bits, result_one_bits;
result_zero_bits
= double_int_ior (double_int_and (must_be_nonzero0,
must_be_nonzero1),
double_int_not
(double_int_ior (may_be_nonzero0,
may_be_nonzero1)));
result_one_bits
= double_int_ior (double_int_and
(must_be_nonzero0,
double_int_not (may_be_nonzero1)),
double_int_and
(must_be_nonzero1,
double_int_not (may_be_nonzero0)));
max = double_int_to_tree (expr_type,
double_int_not (result_zero_bits));
min = double_int_to_tree (expr_type, result_one_bits);
/* Return a [min, max] range if we know the
result range is either positive or negative. */
if (tree_int_cst_sgn (max) >= 0)
/* The range is bound by a lower value of 0. */;
else if (tree_int_cst_sgn (min) < 0)
/* The range is bound by an upper value of -1. */;
else
/* We don't know whether the sign bit is set or not. */
max = min = NULL_TREE;
}
else else
{ {
set_value_range_to_varying (vr); set_value_range_to_varying (vr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment