This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] More CCP in VRP
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 Aug 2008 10:34:01 +0200 (CEST)
- Subject: [PATCH] More CCP in VRP
As noted by Andrew in the audit-trail of PR37207 we fail to constant
propagate during VRP for some binary operators when only one operand
is a constant.
Fixed thusly.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the trunk.
Richard.
2008-08-29 Richard Guenther <rguenther@suse.de>
PR tree-optimization/37207
* tree-vrp.c (extract_range_from_binary_expr): Also try
to constant fold if only one of the operands is a constant.
* gcc.dg/tree-ssa/vrp46.c: New testcase.
Index: tree-vrp.c
===================================================================
*** tree-vrp.c (revision 139713)
--- tree-vrp.c (working copy)
*************** extract_range_from_binary_expr (value_ra
*** 2058,2067 ****
&& 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 (tem
&& is_gimple_min_invariant (tem)
&& !is_overflow_infinity (tem))
--- 2058,2070 ----
&& code != TRUTH_OR_EXPR)
{
/* We can still do constant propagation here. */
! tree const_op0 = op_with_constant_singleton_value_range (op0);
! tree const_op1 = op_with_constant_singleton_value_range (op1);
! if (const_op0 || const_op1)
{
! tree tem = fold_binary (code, expr_type,
! const_op0 ? const_op0 : op0,
! const_op1 ? const_op1 : op1);
if (tem
&& is_gimple_min_invariant (tem)
&& !is_overflow_infinity (tem))
Index: testsuite/gcc.dg/tree-ssa/vrp46.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/vrp46.c (revision 0)
--- testsuite/gcc.dg/tree-ssa/vrp46.c (revision 0)
***************
*** 0 ****
--- 1,28 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+ void
+ func_18 ( int t )
+ {
+ unsigned l_889;
+ int l_895 = 1;
+ for (0; 1; ++l_889)
+ {
+ int t1 = 0;
+ if (func_81 (1))
+ {
+ int rhs = l_895;
+ if (rhs == 0)
+ rhs = 1;
+ if (1 & (t % rhs))
+ t1 = 1;
+ }
+ func_98 (t1);
+ l_895 = 0;
+ }
+ }
+
+ /* There should be a single if left. */
+
+ /* { dg-final { scan-tree-dump-times "if" 1 "vrp1" } } */
+ /* { dg-final { cleanup-tree-dump "vrp1" } } */