This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR ipa/65318
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Jan Hubicka <hubicka at ucw dot cz>,Jeff Law <law at redhat dot com>
- Cc: Martin LiÅka <mliska at suse dot cz>,Marek Polacek <polacek at redhat dot com>,GCC Patches <gcc-patches at gcc dot gnu dot org>,"hubi >> Jan Hubicka" <hubicka at ucw dot cz>
- Date: Thu, 05 Mar 2015 19:25:55 +0100
- Subject: Re: [PATCH] Fix PR ipa/65318
- Authentication-results: sourceware.org; auth=none
- References: <54F85FE8 dot 2070104 at suse dot cz> <20150305142915 dot GB26802 at redhat dot com> <54F86A28 dot 8040804 at suse dot cz> <54F88104 dot 6050409 at redhat dot com> <20150305180816 dot GB87243 at kam dot mff dot cuni dot cz>
On March 5, 2015 7:08:16 PM CET, Jan Hubicka <hubicka@ucw.cz> wrote:
>Hi,
>this patch sovles the incorrect folding. The very same unification
>(ignoring
>signedness by checking that memory representation is the same) is done
>by
>constant pool.
>
>Some of the other uses of ctor_for_folding therefore already uses
>VIEW_CONVERT_EXPR, I suppose as a partial fix for past bugs. This
>particular
>case is handled by get_symbol_constant_value that does not VCE. Maybe
>we usually don't drop scalar constant to constant pool that often, so
>this
>did not show up.
>
>Attached is non-ICF testcase. It is bit questionable if we consider
>this to be
>valid, but it is better to be safe than sorry. Mixing signed/unsigned
>may be
>more common with LTO.
With LTO we wrap all memory accesses in MEM_REFs during streaming which preserves the original types (and thus act as view-conversion if necessary). Without LTO the aliases should provide the same.
Richard.
>Bootstrap/regtest running in x86_64-linux, seems sane?
>
>Honza
>
>static short a __attribute__ ((alias ("c")));
>short b = -1;
>static unsigned short c = 0;
>
>int
>main ()
>{
> if (a <= b)
> return 1;
> return 0;
>}
>
>
> * gimple-fold.c (get_symbol_constant_value): Convert to symbol type.
>
>Index: gimple-fold.c
>===================================================================
>--- gimple-fold.c (revision 221170)
>+++ gimple-fold.c (working copy)
>@@ -263,7 +263,16 @@ get_symbol_constant_value (tree sym)
> {
> val = canonicalize_constructor_val (unshare_expr (val), sym);
> if (val && is_gimple_min_invariant (val))
>- return val;
>+ {
>+ if (!useless_type_conversion_p (TREE_TYPE (sym),
>TREE_TYPE (val)))
>+ {
>+ if (operand_equal_p (TYPE_SIZE (TREE_TYPE (sym)),
>+ TYPE_SIZE (TREE_TYPE (val)), 0))
>+ return NULL_TREE;
>+ val = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (sym), val);
>+ }
>+ return val;
>+ }
> else
> return NULL_TREE;
> }