This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] tree-vrp.c: Pick up a constant from an assertion.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dnovillo at redhat dot com
- Date: Thu, 14 Apr 2005 09:05:43 -0400 (EDT)
- Subject: [patch] tree-vrp.c: Pick up a constant from an assertion.
Hi,
Attached is a patch to improve VRP by picking up a range from an
expression that maybe_add_assert_expr inserts.
If we see an "if" statement of the form
if (a == 123)
We insert "a = 123;" into the "then" arm of the "if" statement
so that the propagation engine can pick up range [123, 123].
The problem is that the propagation engine does not pick up a range
from "a = 123;". Instead it thinks that the value of 'a' is
VR_VARYING.
The patch fixes this problem by noticing an assignment of an integer
constant into an SSA_NAME to create an appropriate VR_RANGE.
With the current pass ordering, the number of COND_EXPRs that VRP
folds into unconditional jumps stays the same while compiling cc1-i
files, with or without this patch. I guess this kind of opportunity
is easily taken by DOM.
With a TCB-like pass ordering
NEXT_PASS (pass_ccp);
NEXT_PASS (pass_copy_prop);
NEXT_PASS (pass_fre);
NEXT_PASS (pass_dce);
NEXT_PASS (pass_vrp);
but without this patch, VRP folds 658 COND_EXPRs into unconditonal
jumps while compiling cc1-i files. With this patch, VRP folds 721
COND_EXPRs into unconditional jumps. A 9.6% improvement! (There are
other cases where we fold COND_EXPRs into an SSA_NAME, but I am not
including those as they are not as cool as folding them into
unconditonal jumps.)
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2005-04-14 Kazu Hirata <kazu@cs.umass.edu>
PR tree-optimization/20657
* tree-vrp.c (extract_range_from_expr): Notice INTEGER_CST to
create an appropriate range from it.
2005-04-14 Kazu Hirata <kazu@cs.umass.edu>
PR tree-optimization/20657
* gcc.dg/tree-ssa/pr20657.c: New.
Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.6
diff -u -d -p -r2.6 tree-vrp.c
--- tree-vrp.c 13 Apr 2005 15:33:02 -0000 2.6
+++ tree-vrp.c 13 Apr 2005 15:36:52 -0000
@@ -830,6 +830,8 @@ extract_range_from_expr (value_range *vr
extract_range_from_unary_expr (vr, expr);
else if (expr_computes_nonzero (expr))
set_value_range_to_nonnull (vr, TREE_TYPE (expr));
+ else if (TREE_CODE (expr) == INTEGER_CST)
+ set_value_range (vr, VR_RANGE, expr, expr);
else
set_value_range (vr, VR_VARYING, NULL_TREE, NULL_TREE);
}
--- /dev/null 2005-04-13 14:59:22.325563136 -0400
+++ testsuite/gcc.dg/tree-ssa/pr20657.c 2005-04-13 10:57:15.000000000 -0400
@@ -0,0 +1,17 @@
+/* PR tree-optimization/20657
+ VRP did not pick up a conditional equivalence from the first "if"
+ statement, which was needed to eliminate the second "if" statement. */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-vrp-details" } */
+
+int
+foo (int a)
+{
+ if (a == 0)
+ if (a == 0)
+ return 1;
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Folding predicate" 1 "vrp"} } */