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.

Passes regress, OK for commit?

gcc:
        * config/aarch64/atomics.md (atomic_store<mode>): Use 
aarch64_reg_or_zero.

gcc/testsuite:
        * gcc.target/aarch64/atomic-store2.c: New test.

---

diff --git a/gcc/config/aarch64/atomics.md b/gcc/config/aarch64/atomics.md
index 
2316fea8135a061a6afd850d5c5fe37062749e4a..c0da49fdb3fb6b2cad1f5d8514013424c9aad7d5
 100644
--- a/gcc/config/aarch64/atomics.md
+++ b/gcc/config/aarch64/atomics.md
@@ -735,7 +735,7 @@ (define_insn "*aarch64_atomic_load<ALLX:mode>_rcpc_sext"
 (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 
0000000000000000000000000000000000000000..85b6cba6f5bc1533780cc69757de62f655d5b48d
--- /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)
+{
+  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