On Sat, Dec 20, 2025 at 6:16 AM Jakub Jelinek <[email protected]> wrote:
>
> Hi!
>
> target can be especially at -O0 a MEM, not just a REG, and most of the
> ix86_expand_builtin spots which use target and can't support MEM
> destinations deal with it properly, except these 3 spots don't.
>
> Fixed thusly, when we change target to a new pseudo, the caller will
> take care of storing that pseudo into the MEM, and this is the
> solution other spots with similar requirements use in the function.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok, thanks.

>
> 2025-12-19  Jakub Jelinek  <[email protected]>
>
>         PR target/123217
>         * config/i386/i386-expand.cc (ix86_expand_builtin)
>         <case IX86_BUILTIN_ENCODEKEY128U32, case IX86_BUILTIN_ENCODEKEY256U32,
>         case IX86_BUILTIN_URDMSR>: Set target to a new pseudo even if it is
>         non-NULL but doesn't satisfy register_operand predicate.
>
>         * gcc.target/i386/keylocker-pr123217.c: New test.
>         * gcc.target/i386/user_msr-pr123217.c: New test.
>
> --- gcc/config/i386/i386-expand.cc.jj   2025-12-09 10:18:55.165234010 +0100
> +++ gcc/config/i386/i386-expand.cc      2025-12-19 12:10:19.807303172 +0100
> @@ -15131,7 +15131,7 @@ ix86_expand_builtin (tree exp, rtx targe
>         for (i = 0; i < 3; i++)
>           xmm_regs[i] = gen_rtx_REG (V2DImode, GET_SSE_REGNO (i));
>
> -       if (target == 0)
> +       if (target == 0 || !register_operand (target, SImode))
>           target = gen_reg_rtx (SImode);
>
>         emit_insn (gen_encodekey128u32 (target, op0));
> @@ -15174,7 +15174,7 @@ ix86_expand_builtin (tree exp, rtx targe
>         for (i = 0; i < 4; i++)
>           xmm_regs[i] = gen_rtx_REG (V2DImode, GET_SSE_REGNO (i));
>
> -       if (target == 0)
> +       if (target == 0 || !register_operand (target, SImode))
>           target = gen_reg_rtx (SImode);
>
>         emit_insn (gen_encodekey256u32 (target, op0));
> @@ -15323,7 +15323,7 @@ ix86_expand_builtin (tree exp, rtx targe
>           }
>         else
>           {
> -           if (target == 0)
> +           if (target == 0 || !register_operand (target, DImode))
>               target = gen_reg_rtx (DImode);
>             icode = CODE_FOR_urdmsr;
>             op1 = op0;
> --- gcc/testsuite/gcc.target/i386/keylocker-pr123217.c.jj       2025-12-19 
> 12:32:05.196732591 +0100
> +++ gcc/testsuite/gcc.target/i386/keylocker-pr123217.c  2025-12-19 
> 12:32:01.055804254 +0100
> @@ -0,0 +1,13 @@
> +/* PR target/123217 */
> +/* { dg-do compile } */
> +/* { dg-options "-mkl -O0" } */
> +
> +__attribute__((__vector_size__(16))) long long v, w;
> +
> +unsigned
> +foo (void *p, void *q)
> +{
> +  unsigned x = __builtin_ia32_encodekey128_u32 (0U, v, p);
> +  unsigned y = __builtin_ia32_encodekey256_u32 (0U, v, w, q);
> +  return x + y;
> +}
> --- gcc/testsuite/gcc.target/i386/user_msr-pr123217.c.jj        2025-12-19 
> 12:32:29.643309515 +0100
> +++ gcc/testsuite/gcc.target/i386/user_msr-pr123217.c   2025-12-19 
> 12:33:12.444568797 +0100
> @@ -0,0 +1,10 @@
> +/* PR target/123217 */
> +/* { dg-do compile { target { ! ia32 } } } */
> +/* { dg-options "-musermsr -O0" } */
> +
> +unsigned long long
> +foo (unsigned long long x)
> +{
> +  unsigned long long y = __builtin_ia32_urdmsr (x);
> +  return y;
> +}
>
>         Jakub
>


-- 
BR,
Hongtao

Reply via email to