public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Uros Bizjak <ubizjak@gmail.com>, Kirill Yukhin <kirill.yukhin@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Add peephole for -Os lock; dec (PR target/70821)
Date: Thu, 28 Apr 2016 15:42:00 -0000	[thread overview]
Message-ID: <20160428154237.GS26501@tucnak.zalov.cz> (raw)

Hi!

Optimizing atomic_fetch_add followed by comparison into just testing
the flags of the lock; sub is handled by a peephole2, which works usually
fine, except that for -Os we have another peephole2 that transforms
movl $-1, %reg into orl $-1, %reg and that causes the above mentioned
peephole2 not to trigger anymore.

Fixed by adding a peephole2 even for this case.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-04-28  Jakub Jelinek  <jakub@redhat.com>

	PR target/70821
	* config/i386/sync.md (define_peephole2 *atomic_fetch_add_cmp<mode>):
	Add new peephole2 where the first insn is *mov<mode>_or instead of
	*mov<mode>_internal.

	* gcc.target/i386/pr70821.c: New test.

--- gcc/config/i386/sync.md.jj	2016-01-04 14:55:56.000000000 +0100
+++ gcc/config/i386/sync.md	2016-04-28 09:40:28.265764880 +0200
@@ -467,6 +467,36 @@ (define_peephole2
 		   (plus:SWI (match_dup 1)
 			     (match_dup 2)))])])
 
+;; Likewise, but for the -Os special case of *mov<mode>_or.
+(define_peephole2
+  [(parallel [(set (match_operand:SWI 0 "register_operand")
+		   (match_operand:SWI 2 "constm1_operand"))
+	      (clobber (reg:CC FLAGS_REG))])
+   (parallel [(set (match_dup 0)
+		   (unspec_volatile:SWI
+		     [(match_operand:SWI 1 "memory_operand")
+		      (match_operand:SI 4 "const_int_operand")]
+		     UNSPECV_XCHG))
+	      (set (match_dup 1)
+		   (plus:SWI (match_dup 1)
+			     (match_dup 0)))
+	      (clobber (reg:CC FLAGS_REG))])
+   (set (reg:CCZ FLAGS_REG)
+	(compare:CCZ (match_dup 0)
+		     (match_operand:SWI 3 "const_int_operand")))]
+  "peep2_reg_dead_p (3, operands[0])
+   && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
+      == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
+   && !reg_overlap_mentioned_p (operands[0], operands[1])"
+  [(parallel [(set (reg:CCZ FLAGS_REG)
+		   (compare:CCZ
+		     (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
+					  UNSPECV_XCHG)
+		     (match_dup 3)))
+	      (set (match_dup 1)
+		   (plus:SWI (match_dup 1)
+			     (match_dup 2)))])])
+
 (define_insn "*atomic_fetch_add_cmp<mode>"
   [(set (reg:CCZ FLAGS_REG)
 	(compare:CCZ
--- gcc/testsuite/gcc.target/i386/pr70821.c.jj	2016-04-28 09:56:06.239893613 +0200
+++ gcc/testsuite/gcc.target/i386/pr70821.c	2016-04-28 09:55:23.000000000 +0200
@@ -0,0 +1,16 @@
+/* PR target/70821 */
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+/* { dg-additional-options "-march=i686" { target ia32 } } */
+
+void bar (void);
+
+void
+foo (int *p)
+{
+  if (__atomic_sub_fetch (p, 1, __ATOMIC_SEQ_CST))
+    bar ();
+}
+
+/* { dg-final { scan-assembler "lock;? dec" } } */
+/* { dg-final { scan-assembler-not "lock;? xadd" } } */

	Jakub

             reply	other threads:[~2016-04-28 15:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-28 15:42 Jakub Jelinek [this message]
2016-04-28 16:30 ` Uros Bizjak

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=20160428154237.GS26501@tucnak.zalov.cz \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kirill.yukhin@gmail.com \
    --cc=ubizjak@gmail.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).