This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is this a bug in the folder?
- From: Diego Novillo <dnovillo at redhat dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Richard Henderson <rth at redhat dot com>
- Date: Tue, 21 Sep 2004 21:21:16 -0400
- Subject: Re: Is this a bug in the folder?
- Organization: Red Hat Canada
- References: <Pine.LNX.4.44.0409210906290.20106-100000@www.eyesopen.com>
On Tue, 2004-09-21 at 11:27, Roger Sayle wrote:
> (1) Check that TREE_CODE (TREE_TYPE (tem)) == INTEGER_TYPE after
> the assignment of tem.
>
> (2) Check that TREE_CODE (TREE_TYPE (tem)) == INTEGER_TYPE in
> the final condition immediately before the call to int_fits_type_p.
>
> or slightly more effort
>
> (3) Fix get_unwidened such that t1 is a VECTOR_CST of the approriate
> type and not an INTEGER_CST. Unfortunately, fold_convert doesn't
> yet know how to convert an integer_cst into a vector_cst for values
> other than zero, however it would be useful functionality to have.
> See http://gcc.gnu.org/ml/gcc-patches/2004-09/msg00773.html
>
> I suspect (2) is the safest short term solution to get your code working,
> but ultimately (3) [and the reciprocal vector_cst to integer_cst] would
> allow for better optimizations, for example, to enable constant folding
> of your example comparison at compile-time.
>
I went with #2 in the interest of minimal intrusion for 4.0. The fix to
fold() allowed me to simplify the folding of COND_EXPR predicates
without all the twisty logic we had before.
OK for mainline? (no new tests are necessary, the second part of the
patch produces 3 new failures in gcc.c-torture without the fold patch).
Thanks. Diego.
2004-09-21 Diego Novillo <dnovillo@redhat.com>
* fold-const.c (fold): Avoid non INTEGER_TYPEs when widening
operands in an integer comparison.
* tree-cfg.c (find_taken_edge): Call fold() to determine
whether the predicate is known.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.461
diff -d -c -p -u -r1.461 fold-const.c
--- fold-const.c 17 Sep 2004 21:54:32 -0000 1.461
+++ fold-const.c 22 Sep 2004 01:11:30 -0000
@@ -8290,6 +8290,7 @@ fold (tree expr)
&& (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0
&& (TREE_TYPE (t1) == TREE_TYPE (tem)
|| (TREE_CODE (t1) == INTEGER_CST
+ && TREE_CODE (TREE_TYPE (tem)) == INTEGER_TYPE
&& int_fits_type_p (t1, TREE_TYPE (tem)))))
return fold (build2 (code, type, tem,
fold_convert (TREE_TYPE (tem), t1)));
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.56
diff -d -c -p -u -r2.56 tree-cfg.c
--- tree-cfg.c 18 Sep 2004 21:54:53 -0000 2.56
+++ tree-cfg.c 22 Sep 2004 01:11:30 -0000
@@ -2001,22 +2001,9 @@ find_taken_edge (basic_block bb, tree va
gcc_assert (is_ctrl_stmt (stmt));
/* If VAL is a predicate of the form N RELOP N, where N is an
- SSA_NAME, we can always determine its truth value (except when
- doing floating point comparisons that may involve NaNs). */
- if (val
- && COMPARISON_CLASS_P (val)
- && TREE_OPERAND (val, 0) == TREE_OPERAND (val, 1)
- && TREE_CODE (TREE_OPERAND (val, 0)) == SSA_NAME
- && (TREE_CODE (TREE_TYPE (TREE_OPERAND (val, 0))) != REAL_TYPE
- || !HONOR_NANS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (val, 0))))))
- {
- enum tree_code code = TREE_CODE (val);
-
- if (code == EQ_EXPR || code == LE_EXPR || code == GE_EXPR)
- val = boolean_true_node;
- else if (code == LT_EXPR || code == GT_EXPR || code == NE_EXPR)
- val = boolean_false_node;
- }
+ SSA_NAME, we can usually determine its truth value. */
+ if (val && COMPARISON_CLASS_P (val))
+ val = fold (val);
/* If VAL is not a constant, we can't determine which edge might
be taken. */