On Mon, Mar 03, 2025 at 01:02:07PM +0000, Richard Sandiford wrote:
> ...how about something like this?  Completely untested, and I haven't
> thought about it much.  Just didn't want to hold up the discussion.

Works for me.

Just wonder if there is anything that will actually verify that XEXP (op0, 0)
and XEXP (op1, 0) modes are at least from the same class, rather than say
have one of the comparisons in MODE_CC and another in MODE_INT or vice versa
or whatever other modes.

> --- a/gcc/simplify-rtx.cc
> +++ b/gcc/simplify-rtx.cc
> @@ -2655,6 +2655,7 @@ simplify_context::simplify_logical_relational_operation 
> (rtx_code code,
>  
>    enum rtx_code code0 = GET_CODE (op0);
>    enum rtx_code code1 = GET_CODE (op1);
> +  machine_mode cmp_mode = GET_MODE (XEXP (op0, 0));
>  
>    /* Assume at first that the comparisons are on integers, and that the
>       operands are therefore ordered.  */
> @@ -2672,8 +2673,10 @@ 
> simplify_context::simplify_logical_relational_operation (rtx_code code,
>      }
>    else
>      {
> -      /* See whether the operands might be unordered.  */
> -      if (HONOR_NANS (GET_MODE (XEXP (op0, 0))))
> +      /* See whether the operands might be unordered.  Assume that all
> +      results are possible for CC modes, and punt later if don't get
> +      an all-true or all-false answer.  */
> +      if (GET_MODE_CLASS (cmp_mode) == MODE_CC || HONOR_NANS (cmp_mode))
>       all = 15;
>        mask0 = comparison_to_mask (code0) & all;
>        mask1 = comparison_to_mask (code1) & all;
> @@ -2702,6 +2705,9 @@ simplify_context::simplify_logical_relational_operation 
> (rtx_code code,
>      code = mask_to_unsigned_comparison (mask);
>    else
>      {
> +      if (GET_MODE_CLASS (cmp_mode) == MODE_CC)
> +     return 0;
> +
>        code = mask_to_comparison (mask);
>        /* LTGT and NE are arithmetically equivalent for ordered operands,
>        with NE being the canonical choice.  */

        Jakub

Reply via email to