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

commit r17-4559-gca800bd07d2d0eb1f00dcb3314aaf34df8230053
Author: Wilco Dijkstra <[email protected]>
Date:   Tue Sep 22 10:55:07 2026 +0200

    AArch64: Avoid general_operand in atomic_store
    
    The generic atomic_store<mode> pattern uses general_operand which blocks CSE
    if the store value is an immediate.  Fix by using aarch64_reg_or_zero.
    
    gcc:
            * config/aarch64/atomics.md (atomic_store<mode>): Use 
aarch64_reg_or_zero.
    
    gcc/testsuite:
            * gcc.target/aarch64/atomic-store2.c: New test.

Diff:
---
 gcc/config/aarch64/atomics.md                    |  2 +-
 gcc/testsuite/gcc.target/aarch64/atomic-store2.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/atomics.md b/gcc/config/aarch64/atomics.md
index 940aa15ac718..0cddbfa9b3d1 100644
--- a/gcc/config/aarch64/atomics.md
+++ b/gcc/config/aarch64/atomics.md
@@ -735,7 +735,7 @@
 (define_insn "atomic_store<mode>"
   [(set (match_operand:ALLI 0 "aarch64_rcpc_memory_operand" "=Q,Ust")
     (unspec_volatile:ALLI
-      [(match_operand:ALLI 1 "general_operand" "rZ,rZ")
+      [(match_operand:ALLI 1 "aarch64_reg_or_zero" "rZ,rZ")
        (match_operand:SI 2 "const_int_operand")]                       ;; model
       UNSPECV_STL))]
   ""
diff --git a/gcc/testsuite/gcc.target/aarch64/atomic-store2.c 
b/gcc/testsuite/gcc.target/aarch64/atomic-store2.c
new file mode 100644
index 000000000000..85b6cba6f5bc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/atomic-store2.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=armv8-a -O2" } */
+
+#include <stdatomic.h>
+
+void
+foo (int *p, long *q)
+{
+  atomic_store_explicit (p, 2, memory_order_relaxed);
+  atomic_store_explicit (p + 1, 2, memory_order_release);
+  atomic_store_explicit (p + 2, 2, memory_order_relaxed);
+}
+
+/* { dg-final { scan-assembler-times "mov\tw\[0-9\]+, 2" 1 } } */

Reply via email to