On Sun, Oct 25, 2026 at 6:36 PM Kael Andrew Alonzo Franco
<[email protected]> wrote:
>
> r17-4656 side_effects_p should be on op0 for
> testcase to produce correct code.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu.
>
>         PR rtl-optimization/128119
>
> gcc/ChangeLog:
>
>         * simplify-rtx.cc (simplify_binary_operation_1) <UMUL_HIGHPART>:
>         Fix r17-4656 side_effects_p.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/pr128119.c: New test.
>
> Signed-off-by: Kael Andrew Franco <[email protected]>
> ---
>  gcc/simplify-rtx.cc                      |  2 +-
>  gcc/testsuite/gcc.target/i386/pr128119.c | 22 ++++++++++++++++++++++
>  2 files changed, 23 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr128119.c
>
> diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
> index 6b19008c0d3..244f5dd522d 100644
> --- a/gcc/simplify-rtx.cc
> +++ b/gcc/simplify-rtx.cc
> @@ -5131,7 +5131,7 @@ simplify_ashift:
>         return op1;
>        /* Simplify x h* 1 to 0.  */
>        if (trueop1 == CONST1_RTX (mode)
> -         && !side_effects_p (op1))
> +         && !side_effects_p (op0))
>         return CONST0_RTX (mode);
>        /* Simplify UMUL_HIGHPART by power of two as LSHIFRT.  */
>        if (CONST_INT_P (trueop1)
> diff --git a/gcc/testsuite/gcc.target/i386/pr128119.c 
> b/gcc/testsuite/gcc.target/i386/pr128119.c
> new file mode 100644
> index 00000000000..8a7f2d323f6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr128119.c
> @@ -0,0 +1,22 @@
> +/* { dg-do assemble } */
> +/* { dg-options "-O2 -save-temps -msse2" } */

This needs either:
`{ target { ! ia32 } }`
or `{ target int128 }` for the dg-do.

as this will fail for -m32 as __int128 does not exist there.

> +
> +typedef double v2df __attribute__ ((vector_size (16)));
> +
> +unsigned long
> +a (volatile unsigned long *p, v2df m)
> +{
> +  unsigned long c = (unsigned long) __builtin_ia32_comisdeq(m, m) | 1;
This should be using the intrinsics instead of the builtin directly.
Yes the testcase in the bug report had the intrinsics but that should
not matter.

I think the only reason why it using the builtin here is to get 1 on
the RTL level.
You should write a gimple testcase which starts at optimized instead
to get the same behavior and one that does not depend on the
intrinsics simplifying on the gimple level.
A hint here is __MULT_HIGHPART .

Thanks,
Andrea


> +  unsigned long v = *p;
> +  return ((unsigned __int128) v * c) >> 64;
> +}
> +
> +unsigned long
> +b (unsigned long *p, v2df m)
> +{
> +  unsigned long c = (unsigned long) __builtin_ia32_comisdeq(m, m) | 1;
> +  unsigned long v = __atomic_load_n(p, __ATOMIC_RELAXED);
> +  return ((unsigned __int128) v * c) >> 64;
> +}
> +
> +/* { dg-final { scan-assembler-not "xor" } } */
> --
> 2.56.0
>

Reply via email to