This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, commited] Handle NE_EXPR guards in bound_difference
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Mar 2007 00:39:55 +0100
- Subject: [patch, commited] Handle NE_EXPR guards in bound_difference
Hello,
this patch improves bound_difference a bit, by making it handle guards
consisting of NE_EXPR with the minimum or maximum of a type. This moves
us closer to being able to eliminate
simplify_using_initial_conditions. Bootstrapped & regtested on i686,
commited.
Zdenek
Index: ChangeLog
===================================================================
*** ChangeLog (revision 122962)
--- ChangeLog (working copy)
***************
*** 1,3 ****
--- 1,8 ----
+ 2007-03-15 Zdenek Dvorak <dvorakz@suse.cz>
+
+ * tree-ssa-loop-niter.c (refine_bounds_using_guard, bound_difference):
+ Handle NE_EXPR guards.
+
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/24924
Index: tree-ssa-loop-niter.c
===================================================================
*** tree-ssa-loop-niter.c (revision 122962)
--- tree-ssa-loop-niter.c (working copy)
*************** refine_bounds_using_guard (tree type, tr
*** 283,289 ****
tree c0, enum tree_code cmp, tree c1,
bounds *bnds)
{
! tree varc0, varc1, tmp;
mpz_t offc0, offc1, loffx, loffy, bnd;
bool lbound = false;
bool no_wrap = nowrap_type_p (type);
--- 283,289 ----
tree c0, enum tree_code cmp, tree c1,
bounds *bnds)
{
! tree varc0, varc1, tmp, ctype;
mpz_t offc0, offc1, loffx, loffy, bnd;
bool lbound = false;
bool no_wrap = nowrap_type_p (type);
*************** refine_bounds_using_guard (tree type, tr
*** 295,311 ****
case LE_EXPR:
case GT_EXPR:
case GE_EXPR:
break;
case EQ_EXPR:
/* We could derive quite precise information from EQ_EXPR, however, such
! a guard is unlikely to appear, so we do not bother with handling it.
! TODO. */
return;
case NE_EXPR:
! /* NE_EXPR comparisons do not contain much of useful information (except for
! special cases like comparing with the bounds of the type, TODO). */
return;
default:
return;
--- 295,342 ----
case LE_EXPR:
case GT_EXPR:
case GE_EXPR:
+ STRIP_SIGN_NOPS (c0);
+ STRIP_SIGN_NOPS (c1);
+ ctype = TREE_TYPE (c0);
+ if (!tree_ssa_useless_type_conversion_1 (ctype, type))
+ return;
+
break;
case EQ_EXPR:
/* We could derive quite precise information from EQ_EXPR, however, such
! a guard is unlikely to appear, so we do not bother with handling
! it. */
return;
case NE_EXPR:
! /* NE_EXPR comparisons do not contain much of useful information, except for
! special case of comparing with the bounds of the type. */
! if (TREE_CODE (c1) != INTEGER_CST
! || !INTEGRAL_TYPE_P (type))
! return;
!
! /* Ensure that the condition speaks about an expression in the same type
! as X and Y. */
! ctype = TREE_TYPE (c0);
! if (TYPE_PRECISION (ctype) != TYPE_PRECISION (type))
! return;
! c0 = fold_convert (type, c0);
! c1 = fold_convert (type, c1);
!
! if (TYPE_MIN_VALUE (type)
! && operand_equal_p (c1, TYPE_MIN_VALUE (type), 0))
! {
! cmp = GT_EXPR;
! break;
! }
! if (TYPE_MAX_VALUE (type)
! && operand_equal_p (c1, TYPE_MAX_VALUE (type), 0))
! {
! cmp = LT_EXPR;
! break;
! }
!
return;
default:
return;
*************** bound_difference (struct loop *loop, tre
*** 422,430 ****
int cnt = 0;
edge e;
basic_block bb;
! tree cond, c0, c1, ctype;
enum tree_code cmp;
mpz_init (bnds->below);
mpz_init (bnds->up);
mpz_init (offx);
--- 453,466 ----
int cnt = 0;
edge e;
basic_block bb;
! tree cond, c0, c1;
enum tree_code cmp;
+ /* Get rid of unnecessary casts, but preserve the value of
+ the expressions. */
+ STRIP_SIGN_NOPS (x);
+ STRIP_SIGN_NOPS (y);
+
mpz_init (bnds->below);
mpz_init (bnds->up);
mpz_init (offx);
*************** bound_difference (struct loop *loop, tre
*** 482,491 ****
c0 = TREE_OPERAND (cond, 0);
cmp = TREE_CODE (cond);
c1 = TREE_OPERAND (cond, 1);
- ctype = TREE_TYPE (c0);
-
- if (!tree_ssa_useless_type_conversion_1 (ctype, type))
- continue;
if (e->flags & EDGE_FALSE_VALUE)
cmp = invert_tree_comparison (cmp, false);
--- 518,523 ----