On Wed, 9 Dec 2020, Jakub Jelinek wrote:

> Hi!
> 
> For Ada with LTO, boolean_{false,true}_node can be 1-bit precision boolean,
> while TREE_TYPE (lhs) can be 8-bit precision boolean and thus we can end up
> with wide_int mismatches.
> 
> The following patch fixes it by using TYPE_{MIN,MAX}_VALUE instead.

Are you sure the Ada boolean types have 1/0 as MIN/MAX value?  ISTR
that's not the case as the middle-end has to support out-of-bound
values.  Now, this might mean using MIN/MAX value is even required
since the transform cannot assume 0/[-]1 here?

So maybe do

>    if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
         && TYPE_PRECISION (TREE_TYPE (lhs)) == 1)

and thus rely on get_range_info for Ada?

Eric?

Thanks,
Richard.

> Bootstrapped/regtested on x86_64-linux and i686-linux (the former including
> Ada as usually), ok for trunk?
> Or do you prefer your version with wi::zero/wi::one?
> 
> 2020-12-09  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR bootstrap/98188
>       * tree-ssa-phiopt.c (two_value_replacement): For boolean, set
>       min and max from minimum and maximum of the type.
> 
> --- gcc/tree-ssa-phiopt.c.jj  2020-12-06 10:57:00.142847537 +0100
> +++ gcc/tree-ssa-phiopt.c     2020-12-08 15:00:09.091063392 +0100
> @@ -660,8 +660,8 @@ two_value_replacement (basic_block cond_
>    wide_int min, max;
>    if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE)
>      {
> -      min = wi::to_wide (boolean_false_node);
> -      max = wi::to_wide (boolean_true_node);
> +      min = wi::to_wide (TYPE_MIN_VALUE (TREE_TYPE (lhs)));
> +      max = wi::to_wide (TYPE_MAX_VALUE (TREE_TYPE (lhs)));
>      }
>    else if (get_range_info (lhs, &min, &max) != VR_RANGE)
>      return false;
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Reply via email to