public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick O'Neill <patrick@rivosinc.com>
To: gcc-patches@gcc.gnu.org
Cc: gnu-toolchain@rivosinc.com, dlustig@nvidia.com,
	kito.cheng@sifive.com, palmer@rivosinc.com, vineetg@rivosinc.com,
	andrew@sifive.com, Patrick O'Neill <patrick@rivosinc.com>
Subject: [RFC 6/7] RISCV: Optimize Atomic Stores
Date: Thu,  7 Apr 2022 11:33:50 -0700	[thread overview]
Message-ID: <20220407183351.295188-7-patrick@rivosinc.com> (raw)
In-Reply-To: <20220407183351.295188-1-patrick@rivosinc.com>

This change brings atomic stores in line with table A.6 of the ISA
manual.

2022-03-31 Patrick O'Neill <patrick@rivosinc.com>

	PR target/89835
	* riscv.cc (atomic_cas_value_strong<mode>): Add %I flag for
	atomic store fences.
	* sync.md (atomic_store<mode>): Use simple store instruction in
	combination with a fence.
	* pr89835.c: New test.
	
Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
---
 gcc/config/riscv/riscv.cc                | 6 ++++++
 gcc/config/riscv/sync.md                 | 2 +-
 gcc/testsuite/gcc.target/riscv/pr89835.c | 9 +++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/pr89835.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 6fbcd62fe73..48d18a83f06 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -3677,6 +3677,7 @@ riscv_memmodel_needs_amo_release (enum memmodel model)
    'A'	Print the atomic operation suffix for memory model OP.
    'I'	Print the LR suffix for memory model OP.
    'J'	Print the SC suffix for memory model OP.
+   'K'  Print a leading fence for the memory model OP.
    'z'	Print x0 if OP is zero, otherwise print OP normally.
    'i'	Print i if the operand is not a register.
    'S'	Print shift-index of single-bit mask OP.
@@ -3728,6 +3729,11 @@ riscv_print_operand (FILE *file, rtx op, int letter)
 	fputs (".rl", file);
       break;
 
+    case 'K':
+      if (riscv_memmodel_needs_amo_release ((enum memmodel) INTVAL (op)))
+	fputs ("fence\trw,w;", file);
+      break;
+
     case 'i':
       if (code != REG)
         fputs ("i", file);
diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md
index b54338d8eb2..1cc3731da38 100644
--- a/gcc/config/riscv/sync.md
+++ b/gcc/config/riscv/sync.md
@@ -65,7 +65,7 @@
        (match_operand:SI 2 "const_int_operand")]      ;; model
       UNSPEC_ATOMIC_STORE))]
   "TARGET_ATOMIC"
-  "amoswap.<amo>%A2 zero,%z1,%0"
+  "%K2s<amo>\t%z1,%0"
   [(set (attr "length") (const_int 4))])
 
 (define_insn "atomic_<atomic_optab><mode>"
diff --git a/gcc/testsuite/gcc.target/riscv/pr89835.c b/gcc/testsuite/gcc.target/riscv/pr89835.c
new file mode 100644
index 00000000000..ab190e11b60
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr89835.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* Verify that relaxed atomic stores use simple store instuctions.  */
+/* { dg-final { scan-assembler-not "amoswap" } } */
+
+void
+foo(int bar, int baz)
+{
+  __atomic_store_n(&bar, baz, __ATOMIC_RELAXED);
+}
-- 
2.25.1


  parent reply	other threads:[~2022-04-07 18:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 18:33 [RFC 0/7] RISCV: Implement ISA Manual Table A.6 Mappings Patrick O'Neill
2022-04-07 18:33 ` [RFC 1/7] RISCV: Enforce Libatomic LR/SC SEQ_CST Patrick O'Neill
2022-04-07 18:33 ` [RFC 2/7] RISCV: Enforce Atomic Compare Exchange SEQ_CST Patrick O'Neill
2022-04-07 18:33 ` [RFC 3/7] RISCV: Add AMO release bits Patrick O'Neill
2022-04-07 18:33 ` [RFC 4/7] RISCV: Optimize AMO Ops Patrick O'Neill
2022-04-07 18:33 ` [RFC 5/7] RISCV: Optimize LR/SC Pairs Patrick O'Neill
2022-04-07 18:33 ` Patrick O'Neill [this message]
2022-04-07 18:33 ` [RFC 7/7] RISCV: Relax mem_thread_fence Patrick O'Neill
2022-05-10  0:52 ` [RFC 0/7] RISCV: Implement ISA Manual Table A.6 Mappings Patrick O'Neill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220407183351.295188-7-patrick@rivosinc.com \
    --to=patrick@rivosinc.com \
    --cc=andrew@sifive.com \
    --cc=dlustig@nvidia.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gnu-toolchain@rivosinc.com \
    --cc=kito.cheng@sifive.com \
    --cc=palmer@rivosinc.com \
    --cc=vineetg@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).