Re: [PATCH v1] match: Simplify type-bound guarded min/max expressions [PR125700]

Drea Pinski via Sourceware Forge <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <bmm.hl7ez7u4hs.gcc.gcc.pinskia.214.542.REVIEW@forge-stage.sourceware.org>
Drea Pinski (pinskia) <[email protected]> requested changes to the code:


> +++ gcc/match.pd
> @@ -12710,0 +12719,4 @@
> +   (with {
> +     tree bound = (minmax == MIN_EXPR)
> +		  ? TYPE_MAX_VALUE (type)
> +		  : TYPE_MIN_VALUE (type);
I think we should use the ranger here.
Similar to minmax_from_comparison.
It should be something like
```
          int_range_max r;
          get_range_query (cfun)->range_of_expr (r, @0);
          if (r.undefined_p ())
            r.set_varying (TREE_TYPE (@0));
          widest_int value;
          if (minmax == MIN_EXPR)
            value = widest_int::from (r.upper_bound (),
                                                     TYPE_SIGN (TREE_TYPE (@0)));
          else
            value = widest_int::from (r.lower_bound (),
                                                     TYPE_SIGN (TREE_TYPE (@0)));
```
Then the if would be:
          if (max == wi::to_widdest (@0))


--
https://forge.sourceware.org/gcc/gcc/pulls/214#issuecomment-7122
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.