This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Avoid introducing TREE_OVERFLOWs in (T)(x&cst) -> (T)x& (T)cst optimization (PR middle-end/19857)
- From: Roger Sayle <roger at eyesopen dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 15 Feb 2005 06:37:27 -0700 (MST)
- Subject: Re: [PATCH] Avoid introducing TREE_OVERFLOWs in (T)(x&cst) -> (T)x& (T)cst optimization (PR middle-end/19857)
On Tue, 15 Feb 2005, Jakub Jelinek wrote:
> 2005-02-15 Jakub Jelinek <jakub@redhat.com>
>
> PR middle-end/19857
> * fold-const.c (fold): Don't optimize (T)(x & cst) to
> (T)x & (T)cst if (T)cst overflows.
> * convert.c (convert_to_integer) <case POINTER_TYPE>: Pass
> TYPE_UNSIGNED (type) as type_for_size's UNSIGNEDP argument.
>
> * gcc.dg/tree-ssa/20050215-1.c: New test.
> * gcc.c-torture/execute/20050215-1.c: New test.
This is Ok for mainline. Thanks.
However, a slight improvement on your fold change would be:
> if (change)
> + {
tem = build_int_cst_wide (type, TREE_INT_CST_LOW (and1),
TREE_INT_CST_HIGH (and1));
tem = force_fit_type (tem, 0, false, false);
> + return fold (build2 (BIT_AND_EXPR, type,
> + fold_convert (type, and0), tem));
> + }
> }
This allows us to force conversion of integer constants without worrying
about overflow. The obvious benefit is that we can continue to optimize
the testcase in the PR.
If bootstrap and regression test of the above change suceeds, consider
the modified patch pre-approved.
Thanks in advance,
Roger
--