public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@linux-mips.org>
To: gcc-patches@gcc.gnu.org
Cc: Jeff Law <law@redhat.com>, Anders Magnusson <ragge@tethuvudet.se>,
	Paul Koning <ni1d@arrl.net>, Matt Thomas <matt@3am-software.com>
Subject: [PATCH 11/31] VAX: Correct `sync_lock_test_and_set' and `sync_lock_release' builtins
Date: Fri, 20 Nov 2020 03:35:02 +0000 (GMT)	[thread overview]
Message-ID: <alpine.LFD.2.21.2011200247340.656242@eddie.linux-mips.org> (raw)
In-Reply-To: <alpine.LFD.2.21.2010251020560.866917@eddie.linux-mips.org>

Remove an ICE like:

during RTL pass: expand
.../libatomic/tas_n.c: In function 'libat_test_and_set_1':
.../libatomic/tas_n.c:39:1: internal compiler error: in patch_jump_insn, at cfgrtl.c:1298
   39 | }
      | ^
0x108a09ff patch_jump_insn
	.../gcc/cfgrtl.c:1298
0x108a0b07 redirect_branch_edge
	.../gcc/cfgrtl.c:1325
0x108a124b rtl_redirect_edge_and_branch
	.../gcc/cfgrtl.c:1458
0x1087f6d3 redirect_edge_and_branch(edge_def*, basic_block_def*)
	.../gcc/cfghooks.c:373
0x11d6264b try_forward_edges
	.../gcc/cfgcleanup.c:562
0x11d6b0eb try_optimize_cfg
	.../gcc/cfgcleanup.c:2960
0x11d6ba4f cleanup_cfg(int)
	.../gcc/cfgcleanup.c:3174
0x10870b3f execute
	.../gcc/cfgexpand.c:6763

triggered with an RTL pattern like:

(jump_insn 8 7 20 2 (parallel [
            (set (pc)
                (if_then_else (ne (zero_extract:SI (mem/v:QI (mem/f/c:SI (reg/f:SI 16 virtual-incoming-args) [1 mptr+0 S4 A32]) [-1  S1 A8])
                            (const_int 1 [0x1])
                            (const_int 0 [0]))
                        (const_int 0 [0]))
                    (label_ref 10)
                    (pc)))
            (set (zero_extract:SI (mem/v:QI (mem/f/c:SI (reg/f:SI 16 virtual-incoming-args) [1 mptr+0 S4 A32]) [-1  S1 A8])
                    (const_int 1 [0x1])
                    (const_int 0 [0]))
                (const_int 1 [0x1]))
        ]) ".../libatomic/tas_n.c":38:12 -1
     (nil)
 -> 10)

caused by a volatile memory reference used that is not accepted by the
`memory_operand' predicate of the `jbbssiqi' insn explicitly referred
from the `sync_lock_test_and_setqi' expander.  Also seen with:

FAIL: gcc.dg/pr61756.c (internal compiler error)

Define a new `any_memory_operand' predicate accepting both ordinary and
volatile memory references and use it with the `jbb<ccss>i<mode>' insn,
so as to address the ICE.

Also remove useless operations from the `sync_lock_test_and_set<mode>'
and `sync_lock_release<mode>' expanders as those always either complete
or fail and therefore never fall through to using their template other
than to match operands.  Wrap `jbb<ccss>i<mode>' into `unspec_volatile'
instead so that the jump does not get removed or reordered.  Share one
index to avoid a complication around the iterators since the index is
nowhere referred to anyway and the pattern required pulled by its name.

Test cases will be added separately.

	gcc/
	* config/vax/predicates.md (volatile_mem_operand)
	(any_memory_operand): New predicates.
	* config/vax/builtins.md (VUNSPEC_UNLOCK): Remove constant.
	(sync_lock_test_and_set<mode>): Remove `set' and `unspec'
	operations, match operands only.  Reformat.
	(sync_lock_release<mode>): Likewise.  Remove cruft.
	(jbb<ccss>i<mode>): Wrap into `unspec_volatile', use
	`any_memory_operand' predicate.
---
 gcc/config/vax/builtins.md   | 36 +++++++++++++++++-------------------
 gcc/config/vax/predicates.md | 16 ++++++++++++++++
 2 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/gcc/config/vax/builtins.md b/gcc/config/vax/builtins.md
index 8bbcd603d13..7e27854a8b0 100644
--- a/gcc/config/vax/builtins.md
+++ b/gcc/config/vax/builtins.md
@@ -19,8 +19,7 @@
 
 (define_constants
   [
-    (VUNSPEC_LOCK 100)		; sync lock and test
-    (VUNSPEC_UNLOCK 101)	; sync lock release
+    (VUNSPEC_LOCK 100)		; sync lock operations
   ]
 )
 
@@ -58,10 +57,9 @@ (define_insn "ffssi2_internal"
   "ffs $0,$32,%1,%0")
 
 (define_expand "sync_lock_test_and_set<mode>"
-  [(set (match_operand:VAXint 0 "nonimmediate_operand" "=&g")
-	(unspec:VAXint [(match_operand:VAXint 1 "memory_operand" "+m")
-		    (match_operand:VAXint 2 "const_int_operand" "n")
-		   ] VUNSPEC_LOCK))]
+  [(match_operand:VAXint 0 "nonimmediate_operand" "=&g")
+   (match_operand:VAXint 1 "memory_operand" "+m")
+   (match_operand:VAXint 2 "const_int_operand" "n")]
   ""
   "
 {
@@ -72,46 +70,46 @@ (define_expand "sync_lock_test_and_set<mode>"
 
   label = gen_label_rtx ();
   emit_move_insn (operands[0], const1_rtx);
-  emit_jump_insn (gen_jbbssi<mode> (operands[1], const0_rtx, label, operands[1]));
+  emit_jump_insn (gen_jbbssi<mode> (operands[1], const0_rtx, label,
+				    operands[1]));
   emit_move_insn (operands[0], const0_rtx);
   emit_label (label);
   DONE;
 }")
 
 (define_expand "sync_lock_release<mode>"
-  [(set (match_operand:VAXint 0 "memory_operand" "+m")
-	(unspec:VAXint [(match_operand:VAXint 1 "const_int_operand" "n")
-		   ] VUNSPEC_UNLOCK))]
+  [(match_operand:VAXint 0 "memory_operand" "+m")
+   (match_operand:VAXint 1 "const_int_operand" "n")]
   ""
   "
 {
   rtx label;
+
   if (operands[1] != const0_rtx)
     FAIL;
-#if 1
+
   label = gen_label_rtx ();
-  emit_jump_insn (gen_jbbcci<mode> (operands[0], const0_rtx, label, operands[0]));
+  emit_jump_insn (gen_jbbcci<mode> (operands[0], const0_rtx, label,
+				    operands[0]));
   emit_label (label);
-#else
-  emit_move_insn (operands[0], const0_rtx);
-#endif
   DONE;
 }")
 
 (define_insn "jbb<ccss>i<mode>"
-  [(parallel
+  [(unspec_volatile
     [(set (pc)
 	  (if_then_else
 	    (eq (zero_extract:SI
-		  (match_operand:VAXint 0 "memory_operand" "<bb_mem>")
+		  (match_operand:VAXint 0 "any_memory_operand" "<bb_mem>")
 		  (const_int 1)
 		  (match_operand:SI 1 "general_operand" "nrmT"))
 		(const_int bit))
 	    (label_ref (match_operand 2 "" ""))
 	    (pc)))
-     (set (zero_extract:SI (match_operand:VAXint 3 "memory_operand" "+0")
+     (set (zero_extract:SI (match_operand:VAXint 3 "any_memory_operand" "+0")
 			   (const_int 1)
 			   (match_dup 1))
-	  (const_int bit))])]
+	  (const_int bit))]
+    VUNSPEC_LOCK)]
   ""
   "jb<ccss>i %1,%0,%l2")
diff --git a/gcc/config/vax/predicates.md b/gcc/config/vax/predicates.md
index 93e91e499a6..7c97b366604 100644
--- a/gcc/config/vax/predicates.md
+++ b/gcc/config/vax/predicates.md
@@ -93,3 +93,19 @@ (define_predicate "general_addsub_di_operand"
    (and (match_code "const_int,const_double,subreg,reg,mem")
 	(and (match_operand:DI 0 "general_operand" "")
 	     (not (match_operand:DI 0 "illegal_addsub_di_memory_operand")))))
+
+;; Return 1 if the operand is in volatile memory.  Note that during the
+;; RTL generation phase, `memory_operand' does not return TRUE for
+;; volatile memory references.  So this function allows us to recognize
+;; volatile references where it's safe.
+(define_predicate "volatile_mem_operand"
+  (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")))
-- 
2.11.0


  parent reply	other threads:[~2020-11-20  3:35 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  3:38 [PATCH 00/31] VAX: Bring the port up to date (yes, MODE_CC conversion is included) Maciej W. Rozycki
2020-11-20  3:34 ` [PATCH 01/31] PR target/58901: reload: Handle SUBREG of MEM with a mode-dependent address Maciej W. Rozycki
2020-11-20 10:55   ` Eric Botcazou
2020-11-20 15:30     ` Maciej W. Rozycki
2020-11-24  6:19       ` [PATCH v2 " Maciej W. Rozycki
2020-11-24 11:03         ` Eric Botcazou
2020-11-26 17:22           ` Maciej W. Rozycki
2020-11-27  3:51             ` Maciej W. Rozycki
2020-11-27 10:52         ` Ulrich Weigand
2020-11-27 19:22           ` Maciej W. Rozycki
2020-11-27 20:47             ` Maciej W. Rozycki
2020-11-27 20:50               ` [PATCH v3 " Maciej W. Rozycki
2020-11-30 18:51                 ` Jeff Law
2020-11-29 17:31             ` [PATCH v2 " Jeff Law
2020-11-20  3:34 ` [PATCH 02/31] VAX: Remove `c' operand format specifier overload Maciej W. Rozycki
2020-11-20 23:16   ` Jeff Law
2020-11-24  1:12   ` Segher Boessenkool
2020-11-20  3:34 ` [PATCH 03/31] VAX: Define LEGITIMATE_PIC_OPERAND_P Maciej W. Rozycki
2020-11-21  3:17   ` Jeff Law
2020-11-20  3:34 ` [PATCH 04/31] VAX/testsuite: Run target testing over all the usual optimization levels Maciej W. Rozycki
2020-11-20 23:17   ` Jeff Law
2020-11-20  3:34 ` [PATCH 05/31] VAX: Rationalize expression and address costs Maciej W. Rozycki
2020-11-21  3:48   ` Jeff Law
2020-11-20  3:34 ` [PATCH 06/31] VAX: Correct fatal issues with the `ffs' builtin Maciej W. Rozycki
2020-11-20 23:19   ` Jeff Law
2020-11-20  3:34 ` [PATCH 07/31] RTL: Also support HOST_WIDE_INT with int iterators Maciej W. Rozycki
2020-11-21  4:19   ` Jeff Law
2020-11-20  3:34 ` [PATCH 08/31] jump: Also handle jumps wrapped in UNSPEC or UNSPEC_VOLATILE Maciej W. Rozycki
2020-11-21  4:25   ` Jeff Law
2020-12-03  3:50     ` [PATCH v2 " Maciej W. Rozycki
2020-12-03 22:20       ` Jeff Law
2020-11-20  3:34 ` [PATCH 09/31] VAX: Use a mode iterator to produce individual interlocked branches Maciej W. Rozycki
2020-11-20 23:20   ` Jeff Law
2020-11-20  3:34 ` [PATCH 10/31] VAX: Use an int " Maciej W. Rozycki
2020-11-20 23:20   ` Jeff Law
2020-11-20  3:35 ` Maciej W. Rozycki [this message]
2020-11-21  4:26   ` [PATCH 11/31] VAX: Correct `sync_lock_test_and_set' and `sync_lock_release' builtins Jeff Law
2020-11-20  3:35 ` [PATCH 12/31] VAX: Actually enable `builtins.md' now that it is fully functional Maciej W. Rozycki
2020-11-20 23:21   ` Jeff Law
2020-11-20  3:35 ` [PATCH 13/31] VAX: Add a test for the SImode `ffs' operation Maciej W. Rozycki
2020-11-20 23:22   ` Jeff Law
2020-11-20  3:35 ` [PATCH 14/31] VAX: Add tests for `sync_lock_test_and_set' and `sync_lock_release' Maciej W. Rozycki
2020-11-20 23:22   ` Jeff Law
2020-11-20  3:35 ` [PATCH 15/31] VAX: Provide the `ctz' operation Maciej W. Rozycki
2020-11-20 23:23   ` Jeff Law
2020-11-20  3:35 ` [PATCH 16/31] VAX: Also provide QImode and HImode `ctz' and `ffs' operations Maciej W. Rozycki
2020-11-20 23:24   ` Jeff Law
2020-11-20  3:35 ` [PATCH 17/31] VAX: Actually produce QImode and HImode `ctz' operations Maciej W. Rozycki
2020-11-20 23:24   ` Jeff Law
2020-11-20  3:35 ` [PATCH 18/31] VAX: Add a test for the `cpymemhi' instruction Maciej W. Rozycki
2020-11-20 23:25   ` Jeff Law
2020-11-20  3:35 ` [PATCH 19/31] VAX: Add the `movmemhi' instruction Maciej W. Rozycki
2020-11-20 23:25   ` Jeff Law
2020-11-20  3:35 ` [PATCH 20/31] VAX: Fix predicates and constraints for EXTV/EXTZV/INSV insns Maciej W. Rozycki
2020-11-21 17:01   ` Jeff Law
2020-11-20  3:35 ` [PATCH 21/31] VAX: Remove EXTV/EXTZV/INSV instruction use from aligned case insns Maciej W. Rozycki
2020-11-21 17:25   ` Jeff Law
2020-11-20  3:35 ` [PATCH 22/31] VAX: Ensure PIC mode address is adjustable with aligned bitfield insns Maciej W. Rozycki
2020-11-21 17:03   ` Jeff Law
2020-11-20  3:36 ` [PATCH 23/31] VAX: Make `extv' an expander matching the remaining bitfield operations Maciej W. Rozycki
2020-11-21 17:26   ` Jeff Law
2020-11-20  3:36 ` [PATCH 24/31] VAX: Fix predicates and constraints for bitfield comparison insns Maciej W. Rozycki
2020-11-21 17:27   ` Jeff Law
2020-11-20  3:36 ` [PATCH 25/31] VAX: Fix predicates for widening multiply and multiply-add insns Maciej W. Rozycki
2020-11-21  4:05   ` Jeff Law
2020-11-30 16:02     ` Maciej W. Rozycki
2020-11-30 18:29       ` Jeff Law
2020-11-20  3:36 ` [PATCH 26/31] VAX: Correct issues with commented-out insns Maciej W. Rozycki
2020-11-21  4:05   ` Jeff Law
2020-11-20  3:36 ` [PATCH 27/31] VAX: Make the `divmoddisi4' and `*amulsi4' comment notation consistent Maciej W. Rozycki
2020-11-21  4:06   ` Jeff Law
2020-11-24  1:37   ` Segher Boessenkool
2020-11-20  3:36 ` [PATCH 28/31] RTL: Add `const_double_zero' syntactic rtx Maciej W. Rozycki
2020-11-21 17:29   ` Jeff Law
2020-11-20  3:36 ` [PATCH 29/31] PDP11: Use `const_double_zero' to express double zero constant Maciej W. Rozycki
2020-11-21  4:07   ` Jeff Law
2020-12-15  8:26   ` Martin Liška
2020-12-15 14:06     ` Maciej W. Rozycki
2020-12-15 18:02       ` Paul Koning
2020-12-15 18:38         ` Maciej W. Rozycki
2020-11-20  3:36 ` [PATCH 30/31] PR target/95294: VAX: Convert backend to MODE_CC representation Maciej W. Rozycki
2020-11-22  3:27   ` Jeff Law
2020-12-09 16:09   ` Maciej W. Rozycki
2020-11-20  3:37 ` [PATCH 31/31] PR target/95294: VAX: Add test cases for " Maciej W. Rozycki
2020-11-21  4:08   ` Jeff Law
2020-12-05 18:40     ` Maciej W. Rozycki
2020-11-20  7:58 ` [PATCH 00/31] VAX: Bring the port up to date (yes, MODE_CC conversion is included) Anders Magnusson
2020-11-23 20:31   ` Maciej W. Rozycki
2020-11-21 21:02 ` Toon Moene
2020-11-23 21:51   ` Maciej W. Rozycki
2020-11-23 22:12     ` Thomas Koenig
2020-11-24  4:28       ` Maciej W. Rozycki
2020-11-24  5:27         ` Maciej W. Rozycki
2020-11-24  6:04           ` Maciej W. Rozycki
2020-11-24  6:16             ` Thomas Koenig
2020-11-25 19:22               ` Maciej W. Rozycki
2020-11-25 18:26             ` Maciej W. Rozycki
2020-11-25 22:20               ` Joseph Myers
2020-11-26 18:01                 ` Maciej W. Rozycki
2020-11-26 18:08                   ` Martin Husemann
2020-12-08 14:38                     ` Maciej W. Rozycki
2020-12-08 15:22                       ` Martin Husemann
2020-11-25 22:26           ` coypu
2020-11-26 17:59             ` Maciej W. Rozycki
2020-11-26 19:35               ` Maciej W. Rozycki
2020-11-23 15:48 ` Paul Koning
2020-11-25 17:07   ` Maciej W. Rozycki
2020-11-28 18:48     ` Paul Koning
2020-12-09 14:06       ` Maciej W. Rozycki
2020-12-10  1:33         ` Paul Koning
2020-12-11 14:54           ` Maciej W. Rozycki
2020-12-11 21:50             ` Paul Koning
2020-11-25 18:36 ` Maciej W. Rozycki
2020-11-26 14:46   ` Ian Lance Taylor
2020-11-26 18:07     ` Maciej W. Rozycki
2020-11-29 17:56   ` Martin Sebor
2020-12-07 14:25     ` Maciej W. Rozycki

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=alpine.LFD.2.21.2011200247340.656242@eddie.linux-mips.org \
    --to=macro@linux-mips.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=matt@3am-software.com \
    --cc=ni1d@arrl.net \
    --cc=ragge@tethuvudet.se \
    /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).