This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Fix folding of X - X to 0
- From: Jeff Law <law at redhat dot com>
- To: Richard Biener <rguenther at suse dot de>, gcc-patches at gcc dot gnu dot org
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Wed, 22 Oct 2014 09:47:51 -0600
- Subject: Re: [PATCH] Fix folding of X - X to 0
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot LSU dot 2 dot 11 dot 1410221447190 dot 9891 at zhemvz dot fhfr dot qr>
On 10/22/14 06:58, Richard Biener wrote:
The following fixes a bug in fold-const.c which happily drops
side-effects when simplifying X - X to 0. I ran into this because
on match-and-simplify I cannot simplify expressions with
TREE_SIDE_EFFECTS and it happens that TYPE_SIZE for VLAs has
side-effects because it usually contains a SAVE_EXPR which are
forced to have side-effects (even if its arg does not have
side-effects). This is appearantly because you can use SAVE_EXPRs
to force creation of initialized temporaries at defined place
in the instruction stream. For example fold-const.c currently
(save_expr<global> - save_expr<global>, (global = 1, save_expr<global>))
Of course all this makes my life hard on match-and-simplify
branch and I wonder why we need to use SAVE_EXPRs for these cases
where the initialization of a new temporary could be done
explicitely (using INIT_EXPR or TARGET_EXPR).
Anyway - fixing the fold-const.c bug requires fixing the bug
I run into on match-and-simplify branch - here by simply
"stripping" the side-effects to get to the actual difference
of the two DECL_FIELD_OFFSETs (I wonder if I missed an obvious
tool to do such stripping).
Bootstrap & regtest running on x86_64-unknown-linux-gnu.
Of course this doesn't help me on match-and-simplify branch
(example testcase that ICEs there with the assert in stor-layout.c
visible below is gcc.c-torture/execute/20040308-1.c). In
theory it should be ok to simplify these late in GIMPLE and
for the stor-layout.c case unset TREE_SIDE_EFFECTS temporarily
to make generic_simplify happy ... (ugh).
2014-10-22 Richard Biener <email@example.com>
* fold-const.c (fold_binary_loc): Preserve side-effects of
X - X when simplifying to 0.
* stor-layout.c (finish_bitfield_representative): Strip
side-effects of evaluating the difference of two DECL_FIELD_OFFSET.