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

--- Comment #8 from Christophe Lyon <clyon at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #5)
> Guess the primary question is why there is the gen_lowpart call at all.
> Is it that normally the mode of x is already right due to the prototypes of
> the builtins, with the exception that gcc likes to promote QImode/HImode
> arguments of calls to SImode, so is the intent in that case to just narrow
> down SImode back to HImode (seems VALID_MVE_PRED_MODE is only true for
> HImode from scalar MODE_INT modes)?
> 
We have mode == V4BImode (could be V16BI or V8BI, it depends on the intrinsic
being expanded)
and x is HImode.
The intent is to generate:
(set (reg:V4BI 122)
   (subreg:V4BI (reg:SI 116 [ _3 ]) 0))

This works if x is not a constant (this is what we have in trunk)

> If so, best would be to limit the call to just that case.
> So (completely untested):
> --- gcc/config/arm/arm-mve-builtins.cc.jj     2024-03-19 09:51:05.203631194 
> +0100
> +++ gcc/config/arm/arm-mve-builtins.cc        2024-04-26 15:49:55.380344060 
> +0200
> @@ -2100,7 +2100,12 @@ function_expander::add_input_operand (in
>        mode = GET_MODE (x);
>      }
>    else if (VALID_MVE_PRED_MODE (mode))
> -    x = gen_lowpart (mode, x);
> +    {
> +      if (mode == HImode && GET_MODE (x) != HImode)
> +     /* GCC promotes QI/HImode arguments to int, undo that
> +        here.  */
> +     x = lowpart_subreg (mode, x, SImode);

So we won't enter the 'if' since mode != HImode

> +    }
>  
>    m_ops.safe_grow (m_ops.length () + 1, true);
>    create_input_operand (&m_ops.last (), x, mode);
> 
> I'd hope if the argument is a vector mode x already has that mode...

Reply via email to