From 73019a428f45b47ebae03a759afd7f3501c165db Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 20 Aug 2008 16:01:59 +0000 Subject: [PATCH] tree-vrp.c (op_with_constant_singleton_value_range): New function. 2008-08-20 Richard Guenther * tree-vrp.c (op_with_constant_singleton_value_range): New function. (extract_range_from_binary_expr): Fall back to constant propagation. (extract_range_from_unary_expr): Likewise. * gcc.dg/tree-ssa/pr21829.c: Scan optimized and cddce2 dumps instead of phicprop2. Make sure all is fine after cddce2, add an XFAILed scan for merging the two remaining ifs. From-SVN: r139326 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr21829.c | 33 ++++++++++++++++++++--- gcc/tree-vrp.c | 47 +++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 940cec6..a8e04a9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2008-08-20 Richard Guenther + * tree-vrp.c (op_with_constant_singleton_value_range): New function. + (extract_range_from_binary_expr): Fall back to constant propagation. + (extract_range_from_unary_expr): Likewise. + +2008-08-20 Richard Guenther + * tree-ssa-ccp.c (maybe_fold_stmt_indirect): Do not mess with TREE_THIS_VOLATILE on shared nodes. (fold_stmt_r): Likewise. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fd849c4..f20a46e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2008-08-20 Richard Guenther + * gcc.dg/tree-ssa/pr21829.c: Scan optimized and cddce2 dumps + instead of phicprop2. Make sure all is fine after cddce2, + add an XFAILed scan for merging the two remaining ifs. + +2008-08-20 Richard Guenther + * gcc.c-torture/compile/20080820-1.c: New testcase. 2008-08-20 Jakub Jelinek diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c b/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c index 2f7078c..6b5c4bb 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr21829.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-phicprop-details" } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-cddce2" } */ int test(int v) { @@ -16,6 +16,33 @@ int test(int v) return x; } -/* { dg-final { scan-tree-dump-times "Original statement:.*% 2\[ \t\n]*Updated statement.*=1" 0 "phicprop2" } } */ -/* { dg-final { cleanup-tree-dump "phicprop\[1-2\]" } } */ +/* This should be optimized to + if (v <= 0) goto ; else goto ; + + :; + + # x_1 = PHI <0(3), 1(1)>; + :; + return x_1; + + retaining only a single conditional. This doesn't work as nobody + combines the two tests + + if (v < 0) goto ; else goto ; + + : + + if (v <= 0) goto ; else goto ; + + this late in the game. tree-ssa-ifcombine.c would do it if we would + unroll the loop during early loop unrolling though. + + For now vrp2 does all the needed folding and threading and cddce2 + provides a nice IL to scan. */ + +/* { dg-final { scan-tree-dump-times "if " 1 "optimized" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "if " 2 "cddce2" } } */ +/* { dg-final { scan-tree-dump "x_. = PHI <0\\\(.\\\), 1\\\(.\\\)>" "cddce2" } } */ +/* { dg-final { cleanup-tree-dump "cddce2" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 7351912..a71002f 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1353,6 +1353,30 @@ ssa_name_nonzero_p (const_tree t) return false; } +/* If OP has a value range with a single constant value return that, + otherwise return NULL_TREE. This returns OP itself if OP is a + constant. */ + +static tree +op_with_constant_singleton_value_range (tree op) +{ + value_range_t *vr; + + if (is_gimple_min_invariant (op)) + return op; + + if (TREE_CODE (op) != SSA_NAME) + return NULL_TREE; + + vr = get_value_range (op); + if (vr->type == VR_RANGE + && operand_equal_p (vr->min, vr->max, 0) + && is_gimple_min_invariant (vr->min)) + return vr->min; + + return NULL_TREE; +} + /* Extract value range information from an ASSERT_EXPR EXPR and store it in *VR_P. */ @@ -2033,6 +2057,18 @@ extract_range_from_binary_expr (value_range_t *vr, && code != TRUTH_AND_EXPR && code != TRUTH_OR_EXPR) { + /* We can still do constant propagation here. */ + if ((op0 = op_with_constant_singleton_value_range (op0)) != NULL_TREE + && (op1 = op_with_constant_singleton_value_range (op1)) != NULL_TREE) + { + tree tem = fold_binary (code, expr_type, op0, op1); + if (is_gimple_min_invariant (tem) + && !is_overflow_infinity (tem)) + { + set_value_range (vr, VR_RANGE, tem, tem, NULL); + return; + } + } set_value_range_to_varying (vr); return; } @@ -2437,6 +2473,17 @@ extract_range_from_unary_expr (value_range_t *vr, enum tree_code code, || code == BIT_NOT_EXPR || code == CONJ_EXPR) { + /* We can still do constant propagation here. */ + if ((op0 = op_with_constant_singleton_value_range (op0)) != NULL_TREE) + { + tree tem = fold_unary (code, type, op0); + if (is_gimple_min_invariant (tem) + && !is_overflow_infinity (tem)) + { + set_value_range (vr, VR_RANGE, tem, tem, NULL); + return; + } + } set_value_range_to_varying (vr); return; } -- 2.7.4