public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4] rs6000: Improve volatile memory handling
@ 2019-07-20 17:19 Segher Boessenkool
  2019-07-20 17:19 ` [PATCH 2/4] rs6000: Make lwa_operand use any_memory_operand Segher Boessenkool
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Segher Boessenkool @ 2019-07-20 17:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: dje.gcc, Segher Boessenkool

Most of our loads and stores are atomic when done on aligned operands.
This patch series cleans up our handling of that a little bit, and makes
us handle a few more cases.

The lwa_operand one has a testcase, which is how I noticed this could
use some improvement.  Looking at the combine dump for that shows
input_operand isn't handled properly, either.  And finally there is
offsettable_mem_operand as well.  I didn't see any other memory
operands we should handle as volatile as well, but who knows :-)

Tested on powerpc64-linux {-m32,-m64}; committing to trunk.


Segher


Segher Boessenkool (4):
  rs6000: New predicate any_memory_operand
  rs6000: Make lwa_operand use any_memory_operand
  rs6000: Make input_operand use any_memory_operand
  rs6000: Make offsettable_mem_operand use any_memory_operand

 gcc/config/rs6000/predicates.md                 | 22 +++++++++++++---------
 gcc/testsuite/gcc.target/powerpc/volatile-mem.c | 16 ++++++++++++++++
 2 files changed, 29 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/volatile-mem.c

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] rs6000: Make lwa_operand use any_memory_operand
  2019-07-20 17:19 [PATCH 0/4] rs6000: Improve volatile memory handling Segher Boessenkool
@ 2019-07-20 17:19 ` Segher Boessenkool
  2019-07-20 17:19 ` [PATCH 1/4] rs6000: New predicate any_memory_operand Segher Boessenkool
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2019-07-20 17:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: dje.gcc, Segher Boessenkool

Testcase from comex, see https://lwn.net/Articles/793932/ .


2019-07-20  Segher Boessenkool  <segher@kernel.crashing.org>

	* config/rs6000/predicates.md (lwa_operand): Allow volatile memory.

gcc/testsuite/
	* gcc.target/powerpc/volatile-mem.c: New testcase.

---
 gcc/config/rs6000/predicates.md                 |  2 +-
 gcc/testsuite/gcc.target/powerpc/volatile-mem.c | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/volatile-mem.c

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 13c7c02..23d626b 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -929,7 +929,7 @@ (define_predicate "lwa_operand"
 
   if (gpc_reg_operand (inner, mode))
     return true;
-  if (!memory_operand (inner, mode))
+  if (!any_memory_operand (inner, mode))
     return false;
 
   addr = XEXP (inner, 0);
diff --git a/gcc/testsuite/gcc.target/powerpc/volatile-mem.c b/gcc/testsuite/gcc.target/powerpc/volatile-mem.c
new file mode 100644
index 0000000..c8a7444
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/volatile-mem.c
@@ -0,0 +1,16 @@
+/* { dg-options "-O2 -std=c11" } */
+/* { dg-require-effective-target lp64 } */
+
+/* This tests if the instructions used for C atomic are optimised properly
+   as atomic by the target code, too.  */
+
+#include <stdatomic.h>
+
+int load(_Atomic int *ptr)
+{
+        return atomic_load_explicit(ptr, memory_order_relaxed);
+}
+
+/* There should be only two machine instructions, an lwa and a blr: */
+/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 2 } } */
+/* { dg-final { scan-assembler-times {\mlwa\M} 1 } } */
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] rs6000: Make offsettable_mem_operand use any_memory_operand
  2019-07-20 17:19 [PATCH 0/4] rs6000: Improve volatile memory handling Segher Boessenkool
  2019-07-20 17:19 ` [PATCH 2/4] rs6000: Make lwa_operand use any_memory_operand Segher Boessenkool
  2019-07-20 17:19 ` [PATCH 1/4] rs6000: New predicate any_memory_operand Segher Boessenkool
@ 2019-07-20 17:19 ` Segher Boessenkool
  2019-07-20 17:30 ` [PATCH 3/4] rs6000: Make input_operand " Segher Boessenkool
  3 siblings, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2019-07-20 17:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: dje.gcc, Segher Boessenkool

2019-07-20  Segher Boessenkool  <segher@kernel.crashing.org>

	* config/rs6000/predicates.md (offsettable_mem_operand): Allow volatile
	memory.

---
 gcc/config/rs6000/predicates.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 7c451df..5a2d2d3 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -716,7 +716,7 @@ (define_predicate "any_memory_operand"
 
 ;; Return 1 if the operand is an offsettable memory operand.
 (define_predicate "offsettable_mem_operand"
-  (and (match_operand 0 "memory_operand")
+  (and (match_operand 0 "any_memory_operand")
        (match_test "offsettable_nonstrict_memref_p (op)")))
 
 ;; Return 1 if the operand is a simple offsettable memory operand
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] rs6000: New predicate any_memory_operand
  2019-07-20 17:19 [PATCH 0/4] rs6000: Improve volatile memory handling Segher Boessenkool
  2019-07-20 17:19 ` [PATCH 2/4] rs6000: Make lwa_operand use any_memory_operand Segher Boessenkool
@ 2019-07-20 17:19 ` Segher Boessenkool
  2019-07-20 17:19 ` [PATCH 4/4] rs6000: Make offsettable_mem_operand use any_memory_operand Segher Boessenkool
  2019-07-20 17:30 ` [PATCH 3/4] rs6000: Make input_operand " Segher Boessenkool
  3 siblings, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2019-07-20 17:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: dje.gcc, Segher Boessenkool

The new predicate accepts both memory_operand and volatile_mem_operand.


2019-07-20  Segher Boessenkool  <segher@kernel.crashing.org>

	* config/rs6000/predicates.md (volatile_mem_operand): Modernize syntax.
	(any_memory_operand): New predicate.
	(reg_or_mem_operand): Use it.

---
 gcc/config/rs6000/predicates.md | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 5f687ea..13c7c02 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -703,12 +703,17 @@ (define_predicate "zero_fp_constant"
 ;; memory references.  So this function allows us to recognize volatile
 ;; references where it's safe.
 (define_predicate "volatile_mem_operand"
-  (and (and (match_code "mem")
-	    (match_test "MEM_VOLATILE_P (op)"))
+  (and (match_code "mem")
+       (match_test "MEM_VOLATILE_P (op)")
        (if_then_else (match_test "reload_completed")
 	 (match_operand 0 "memory_operand")
 	 (match_test "memory_address_p (mode, XEXP (op, 0))"))))
 
+;; Return 1 if the operand is a volatile or non-volatile memory operand.
+(define_predicate "any_memory_operand"
+  (ior (match_operand 0 "memory_operand")
+       (match_operand 0 "volatile_mem_operand")))
+
 ;; Return 1 if the operand is an offsettable memory operand.
 (define_predicate "offsettable_mem_operand"
   (and (match_operand 0 "memory_operand")
@@ -891,11 +896,10 @@ (define_predicate "scc_eq_operand"
 
 ;; Return 1 if the operand is a general non-special register or memory operand.
 (define_predicate "reg_or_mem_operand"
-  (ior (match_operand 0 "memory_operand")
+  (ior (match_operand 0 "gpc_reg_operand")
+       (match_operand 0 "any_memory_operand")
        (and (match_code "mem")
-	    (match_test "macho_lo_sum_memory_operand (op, mode)"))
-       (match_operand 0 "volatile_mem_operand")
-       (match_operand 0 "gpc_reg_operand")))
+	    (match_test "macho_lo_sum_memory_operand (op, mode)"))))
 
 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
 (define_predicate "zero_reg_mem_operand"
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] rs6000: Make input_operand use any_memory_operand
  2019-07-20 17:19 [PATCH 0/4] rs6000: Improve volatile memory handling Segher Boessenkool
                   ` (2 preceding siblings ...)
  2019-07-20 17:19 ` [PATCH 4/4] rs6000: Make offsettable_mem_operand use any_memory_operand Segher Boessenkool
@ 2019-07-20 17:30 ` Segher Boessenkool
  3 siblings, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2019-07-20 17:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: dje.gcc, Segher Boessenkool

2019-07-20  Segher Boessenkool  <segher@kernel.crashing.org>

	* config/rs6000/predicates.md (input_operand): Allow volatile memory.

---
 gcc/config/rs6000/predicates.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 23d626b..7c451df 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -1031,7 +1031,7 @@ (define_predicate "input_operand"
 	       const_double,const_wide_int,const_vector,const_int")
 {
   /* Memory is always valid.  */
-  if (memory_operand (op, mode))
+  if (any_memory_operand (op, mode))
     return 1;
 
   /* For floating-point, easy constants are valid.  */
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-20 17:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-20 17:19 [PATCH 0/4] rs6000: Improve volatile memory handling Segher Boessenkool
2019-07-20 17:19 ` [PATCH 2/4] rs6000: Make lwa_operand use any_memory_operand Segher Boessenkool
2019-07-20 17:19 ` [PATCH 1/4] rs6000: New predicate any_memory_operand Segher Boessenkool
2019-07-20 17:19 ` [PATCH 4/4] rs6000: Make offsettable_mem_operand use any_memory_operand Segher Boessenkool
2019-07-20 17:30 ` [PATCH 3/4] rs6000: Make input_operand " Segher Boessenkool

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).