https://gcc.gnu.org/g:cdb8a10e1a826670ad5555cfb7cd973bf41cfefe

commit r17-6552-gcdb8a10e1a826670ad5555cfb7cd973bf41cfefe
Author: Jakub Jelinek <[email protected]>
Date:   Sat Nov 21 10:01:24 2026 +0100

    rtl-optimization: Fix r17-4656 side_effects_p [PR128119]
    
    r17-4656 side_effects_p should be on op0 for
    testcase to produce correct code.
    
    2026-11-21  Kael Andrew Franco  <[email protected]>
                Jakub Jelinek  <[email protected]>
    
            PR rtl-optimization/128119
            * simplify-rtx.cc (simplify_binary_operation_1) <UMUL_HIGHPART>:
            Fix side_effects_p argument for x h* 1 to 0 simplification.
    
            * gcc.target/i386/pr128119.c: New test.
    
    Signed-off-by: Kael Andrew Franco <[email protected]>
    Reviewed-by: Richard Biener <[email protected]>

Diff:
---
 gcc/simplify-rtx.cc                      |  2 +-
 gcc/testsuite/gcc.target/i386/pr128119.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 53c8da5c156e..72274b22e5ff 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -5232,7 +5232,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 000000000000..8e0e290953d9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr128119.c
@@ -0,0 +1,23 @@
+/* PR rtl-optimization/128119 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2 -msse2 -masm=att -fno-stack-protector" } */
+
+#include <emmintrin.h>
+
+unsigned long long
+foo (volatile unsigned long long *p, __m128d m)
+{
+  unsigned long long c = (unsigned long long) _mm_comieq_sd (m, m) | 1;
+  unsigned long long v = *p;
+  return ((unsigned __int128) v * c) >> 64;
+}
+
+unsigned long long
+bar (unsigned long long *p, __m128d m)
+{
+  unsigned long long c = (unsigned long long) _mm_comieq_sd (m, m) | 1;
+  unsigned long long v = __atomic_load_n (p, __ATOMIC_RELAXED);
+  return ((unsigned __int128) v * c) >> 64;
+}
+
+/* { dg-final { scan-assembler-times "(?:movq|mulq)\t\\\(" 2 } } */

Reply via email to