OSDN Git Service

2008-08-20 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Aug 2008 16:01:59 +0000 (16:01 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Aug 2008 16:01:59 +0000 (16:01 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@139326 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr21829.c
gcc/tree-vrp.c

index 940cec6..a8e04a9 100644 (file)
@@ -1,5 +1,11 @@
 2008-08-20  Richard Guenther  <rguenther@suse.de>
 
+       * 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  <rguenther@suse.de>
+
        * tree-ssa-ccp.c (maybe_fold_stmt_indirect): Do not mess
        with TREE_THIS_VOLATILE on shared nodes.
        (fold_stmt_r): Likewise.
index fd849c4..f20a46e 100644 (file)
@@ -1,5 +1,11 @@
 2008-08-20  Richard Guenther  <rguenther@suse.de>
 
+       * 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  <rguenther@suse.de>
+
        * gcc.c-torture/compile/20080820-1.c: New testcase.
 
 2008-08-20  Jakub Jelinek  <jakub@redhat.com>
index 2f7078c..6b5c4bb 100644 (file)
@@ -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 <L1>; else goto <L3>;
+
+   <L1>:;
+
+    # x_1 = PHI <0(3), 1(1)>;
+   <L3>:;
+    return x_1;
+
+   retaining only a single conditional.  This doesn't work as nobody
+   combines the two tests
+
+    if (v < 0) goto <bb 4>; else goto <bb 3>;
+
+   <bb 3>:
+
+    if (v <= 0) goto <bb 4>; else goto <bb 5>;
+
+   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" } } */
index 7351912..a71002f 100644 (file)
@@ -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;
     }