On Dec 17, 2024, Alexandre Oliva <ol...@adacore.com> wrote:

> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index 92f02ddd77408..06913d57f8aec 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -7554,13 +7554,10 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
> *pbitsize,
>       narrowing then widening casts, or vice-versa, for those that are not
>       essential for the compare have already been optimized out at this
>       point.  */
> -  if (gimple_convert_def_p (exp, res_ops))
> +  if (!outer_type && gimple_convert_def_p (exp, res_ops))

Oops, I failed to update the comment.
Please consider it combined with this patchlet.

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index d8f0df97b8f53..9ee854bec4dc6 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7313,10 +7313,14 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
   if (! INTEGRAL_TYPE_P (TREE_TYPE (exp)))
     return NULL_TREE;
 
-  /* Drop casts, only save the outermost type.  We need not worry about
-     narrowing then widening casts, or vice-versa, for those that are not
-     essential for the compare have already been optimized out at this
-     point.  */
+  /* Drop casts, saving only the outermost type, effectively used in
+     the compare.  We can deal with at most one conversion, and it may
+     appear at various points in the chain of recognized preparation
+     statements.  Earlier optimizers will often have already dropped
+     unneeded extensions, but they may survive, as in PR118046.  ???
+     Can we do better and allow multiple conversions, perhaps taking
+     note of the narrowest intermediate type, sign extensions and
+     whatnot?  */
   if (!outer_type && gimple_convert_def_p (exp, res_ops))
     {
       outer_type = TREE_TYPE (exp);


-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

Reply via email to