This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] tree-vrp.c: Improve compare_range_with_value.


Hi,

Attached is a patch to improve compare_range_with_value.

Consider

int
foo (int a)
{
  if (a > 1)
    if (a == 0)
      return 1;
  return 0;
}

Note that the second "if" statement can be folded to "if (0)".
However, VRP doesn't fold it.  The problem is that
compare_range_with_value doesn't handle EQ_EXPR very well.
Specifically, all it handles is the case where the value of 'a' is a
singleton range.  If the range is a multi-value range like [2, +INF],
then compare_range_with_value returns NULL_TREE, which I think is too
naive.

The patch fixes the problem by returning boolean_false_node when
SSA_NAME in "if (SSA_NAME == CST)" is strictly smaller than or
strictly larger than CST.

Without this patch, VRP folds 6723 predicates while compiling cc1-i
files.  With this patch, it folds 6855 predicates, so we have a 2.0%
improvement.

Tested on i686-pc-linux-gnu.  Committed as approved by Diego on the PR
trail.

Kazu Hirata

2005-05-14  Kazu Hirata  <kazu@cs.umass.edu>

	PR tree-optimization/21563
	* tree-vrp.c (compare_value): Return boolean_false_node when
	SSA_NAME in "if (SSA_NAME == CST)" is strictly smaller than or
	strictly larger than CST.

2005-05-14  Kazu Hirata  <kazu@cs.umass.edu>

	PR tree-optimization/21563
	* gcc.dg/tree-ssa/pr21563.c: New.

Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.17
diff -u -d -p -r2.17 tree-vrp.c
--- tree-vrp.c	3 May 2005 12:19:52 -0000	2.17
+++ tree-vrp.c	14 May 2005 04:03:03 -0000
@@ -1204,6 +1204,9 @@ compare_range_with_value (enum tree_code
 	  else if (cmp == -1 || cmp == 1 || cmp == 2)
 	    return boolean_false_node;
 	}
+      else if (compare_values (val, vr->min) == -1
+	       || compare_values (vr->max, val) == -1)
+	return boolean_false_node;
 
       return NULL_TREE;
     }
--- /dev/null	2005-05-05 09:22:29.000000000 -0400
+++ testsuite/gcc.dg/tree-ssa/pr21563.c	2005-05-14 00:01:50.000000000 -0400
@@ -0,0 +1,17 @@
+/* PR tree-optimization/21563
+   Make sure VRP folds the second "if" statement.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-vrp-details" } */
+
+int
+foo (int a)
+{
+  if (a > 1)
+    if (a == 0)
+      return 1;
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Folding predicate" 1 "vrp"} } */
+/* { dg-final { cleanup-tree-dump "vrp" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]