https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115092

--- Comment #9 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #8)
> > Yeah, that look like it is missing some test.
> 
> I'd go with
> --- gcc/combine.cc.jj 2024-05-07 18:10:10.415874636 +0200
> +++ gcc/combine.cc    2024-05-15 13:33:26.555081215 +0200
> @@ -11852,8 +11852,10 @@ simplify_compare_const (enum rtx_code co
>       `and'ed with that bit), we can replace this with a comparison
>       with zero.  */
>    if (const_op
> -      && (code == EQ || code == NE || code == GE || code == GEU
> -       || code == LT || code == LTU)
> +      && (code == EQ || code == NE || code == GEU || code == LTU
> +       /* This optimization is incorrect for signed >= INT_MIN or
> +          < INT_MIN, those are always true or always false.  */
> +       || ((code == GE || code == LT) && const_op > 0))
>        && is_a <scalar_int_mode> (mode, &int_mode)
>        && GET_MODE_PRECISION (int_mode) - 1 < HOST_BITS_PER_WIDE_INT
>        && pow2p_hwi (const_op & GET_MODE_MASK (int_mode))

Pre-approved.  Thanks!

> Seems there is no canonical way to return this is always true or this is
> always false,
> sure, we could make up something like NE 1 0 or EQ 1 0 or similar, but it
> wouldn't likely match and the question is if it would simplify.

Later code will likely pick this up.  More likely than with the GE anyway :-)

> The const_op == -1 handling below this looks correct to me.

Yup.

> > That needs to be fixed of course, but independent of that, this should 
> > really
> > have been completely folded away earlier already?
> 
> It would if one wouldn't carefully disable tons of optimizations (say -O1,
> so no (significant) VRP, dom* disabled, fre disabled).

Ha :-)

Reply via email to