From 0f36b2dafd0b61c7b473be85bc1ff85bf730a88a Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Fri, 5 Aug 2011 10:16:48 +0000 Subject: [PATCH] re PR tree-optimization/49984 (VRP does not handle BIT_XOR_EXPR) 2011-08-05 Richard Guenther 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 --- gcc/ChangeLog | 5 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/tree-ssa/vrp59.c | 35 +++++++++++++++++++++++++++ gcc/tree-vrp.c | 34 ++++++++++++++++++++++++-- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp59.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5859bea2c35..d86d24bbcca 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2011-08-05 Richard Guenther + + PR tree-optimization/49984 + * tree-vrp.c (extract_range_from_binary_expr_1): Handle BIT_XOR_EXPR. + 2011-08-05 Richard Guenther * tree-vrp.c (zero_nonzero_bits_from_vr): Make sure to always diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 666fcd6a167..78017058ccb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-08-05 Richard Guenther + + PR tree-optimization/49984 + * gcc.dg/tree-ssa/vrp59.c: New testcase. + 2011-08-05 Richard Guenther * gcc.dg/tree-ssa/vrp51.c: Disable CCP. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp59.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp59.c new file mode 100644 index 00000000000..30b26f582cf --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp59.c @@ -0,0 +1,35 @@ +/* { 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" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 121746efab6..eb6fc9dcc8c 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -2214,7 +2214,8 @@ extract_range_from_binary_expr_1 (value_range_t *vr, && code != MIN_EXPR && code != MAX_EXPR && code != BIT_AND_EXPR - && code != BIT_IOR_EXPR) + && code != BIT_IOR_EXPR + && code != BIT_XOR_EXPR) { set_value_range_to_varying (vr); return; @@ -2635,7 +2636,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr, min = vrp_int_const_binop (code, vr0.min, vr1.max); 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; double_int may_be_nonzero0, may_be_nonzero1; @@ -2694,6 +2695,35 @@ extract_range_from_binary_expr_1 (value_range_t *vr, if (int_cst_range1) 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 { set_value_range_to_varying (vr); -- 2.30.2