diff options
author | Kazu Hirata <kazu@codesourcery.com> | 2006-01-14 15:42:11 +0000 |
---|---|---|
committer | Kazu Hirata <kazu@gcc.gnu.org> | 2006-01-14 15:42:11 +0000 |
commit | 9b61327b890150182672aa21eb45c6c3bcab0441 (patch) | |
tree | 355ef3795da06c59605a8d8b7e753114173b953d /gcc/tree-vrp.c | |
parent | a916f21d3c176a23f54114a17605813a31cd5d2e (diff) | |
download | gcc-9b61327b890150182672aa21eb45c6c3bcab0441.zip gcc-9b61327b890150182672aa21eb45c6c3bcab0441.tar.gz gcc-9b61327b890150182672aa21eb45c6c3bcab0441.tar.bz2 |
re PR tree-optimization/25485 (VRP misses an "if" with TRUTH_AND_EXPR statement that could be optimized away)
gcc/
PR tree-optimization/25485
* tree-vrp.c (extract_range_from_binary_expr): Handle cases
where one of the operands of TRUTH_AND_EXPR and TRUTH_OR_EXPR
is known to be false and true, respectively.
gcc/testsuite/
PR tree-optimization/25485
* gcc.dg/tree-ssa/pr25485.c: New.
From-SVN: r109704
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r-- | gcc/tree-vrp.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index daa459f..6bd4725 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1230,6 +1230,8 @@ extract_range_from_binary_expr (value_range_t *vr, tree expr) the operands is VR_VARYING or symbolic range. TODO, we may be able to derive anti-ranges in some cases. */ if (code != BIT_AND_EXPR + && code != TRUTH_AND_EXPR + && code != TRUTH_OR_EXPR && (vr0.type == VR_VARYING || vr1.type == VR_VARYING || vr0.type != vr1.type @@ -1277,9 +1279,47 @@ extract_range_from_binary_expr (value_range_t *vr, tree expr) || code == TRUTH_OR_EXPR || code == TRUTH_XOR_EXPR) { - /* Boolean expressions cannot be folded with int_const_binop. */ - min = fold_binary (code, TREE_TYPE (expr), vr0.min, vr1.min); - max = fold_binary (code, TREE_TYPE (expr), vr0.max, vr1.max); + /* If one of the operands is zero, we know that the whole + expression evaluates zero. */ + if (code == TRUTH_AND_EXPR + && ((vr0.type == VR_RANGE + && integer_zerop (vr0.min) + && integer_zerop (vr0.max)) + || (vr1.type == VR_RANGE + && integer_zerop (vr1.min) + && integer_zerop (vr1.max)))) + { + type = VR_RANGE; + min = max = build_int_cst (TREE_TYPE (expr), 0); + } + /* If one of the operands is one, we know that the whole + expression evaluates one. */ + else if (code == TRUTH_OR_EXPR + && ((vr0.type == VR_RANGE + && integer_onep (vr0.min) + && integer_onep (vr0.max)) + || (vr1.type == VR_RANGE + && integer_onep (vr1.min) + && integer_onep (vr1.max)))) + { + type = VR_RANGE; + min = max = build_int_cst (TREE_TYPE (expr), 1); + } + else if (vr0.type != VR_VARYING + && vr1.type != VR_VARYING + && vr0.type == vr1.type + && !symbolic_range_p (&vr0) + && !symbolic_range_p (&vr1)) + { + /* Boolean expressions cannot be folded with int_const_binop. */ + min = fold_binary (code, TREE_TYPE (expr), vr0.min, vr1.min); + max = fold_binary (code, TREE_TYPE (expr), vr0.max, vr1.max); + } + else + { + set_value_range_to_varying (vr); + return; + } } else if (code == PLUS_EXPR || code == MIN_EXPR |