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" } */
+
+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;
+ 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