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] |

*From*: Roger Sayle <roger at eyesopen dot com>*To*: Jan Hubicka <jh at suse dot cz>*Cc*: gcc-patches at gcc dot gnu dot org*Date*: Thu, 6 Nov 2003 06:27:26 -0700 (MST)*Subject*: Re: [tree-ssa/mainline PATCH] fold "test"==0 into constant

Hi Jan, > The patch bellow is based on merging tree_expr_nonnegative_p and RTL > nonzero_address implementation so it catch these and slightly more > sophisficated cases. You need to guard some of these cases with checks for "! flag_wrapv". The code in rtlanal.c's nonzero_address_p is valid only because it is only used for addressing arithmetic which has undefined overflow. In Java, for example, "max (x, 1) + max (y, 1)" can still be zero, even though each term must be greater than zero. [p.s. it looks like you miss this case :>] Similarly for multiplication where a zero result can be generated from two non-zero operands. > + else if (TREE_CODE (outer_type) == INTEGER_TYPE) > + { > + if (TREE_CODE (inner_type) == REAL_TYPE) > + return tree_expr_nonnegative_p (TREE_OPERAND (t,0)); > + if (TREE_CODE (inner_type) == INTEGER_TYPE) > + return TYPE_PRECISION (inner_type) < TYPE_PRECISION (outer_type) > + && TREE_UNSIGNED (inner_type); > + } > + } > + break; > + case ADDR_EXPR: > + /* Weak declarations may link to NULL. */ And a blank line after the break for consistency with the other cases. Longer-term, I think what constant folding really needs are two functions tree_expr_lower_bound and tree_expr_upper_bound, where we can implement some form of interval arithmetic. Then the two current functions tree_expr_nonnegative_p and tree_expr_nonzero_p can easily be implemented by testing the returned bounds against zero. This will provide for more accurate implementations, but also enable many more optimizations, for example, comparisons against any integer constant, or comparisons between expressions with non-overlapping bounds. For example, we could remove bounds checks from "switch (x & 7)"... Roger --

**Follow-Ups**:**Re: [tree-ssa/mainline PATCH] fold "test"==0 into constant***From:*Jan Hubicka

**Re: [tree-ssa/mainline PATCH] fold "test"==0 into constant***From:*Toon Moene

**References**:**[tree-ssa/mainline PATCH] fold "test"==0 into constant***From:*Jan Hubicka

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |