]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/70821 (x86_64: __atomic_fetch_add/sub() uses XADD rather than DECL in...
authorJakub Jelinek <jakub@redhat.com>
Thu, 28 Apr 2016 17:10:14 +0000 (19:10 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 28 Apr 2016 17:10:14 +0000 (19:10 +0200)
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.

From-SVN: r235586

gcc/ChangeLog
gcc/config/i386/sync.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr70821.c [new file with mode: 0644]

index 4a1de895e619a1f6d6eecbc188586d1987a721b2..d18013ef8a4bee420fea236ddd0dede7a21638ec 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2016-04-28  Segher Boesssenkool  <segher@kernel.crashing.org>
 
        * tracer.c (bb_seen): Make static.
index 85a2b9ad630ea1f19c4037409c1404555ec85062..bc4fd34e6d5d4a4b9b76002c2d054981b5a43867 100644 (file)
                   (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
index 00616c895e1c25b3ded1151350a4b197b717fb40..b787d4a34363ed7184062c56f7f2be45adca53ea 100644 (file)
@@ -1,3 +1,8 @@
+2016-04-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/70821
+       * gcc.target/i386/pr70821.c: New test.
+
 2016-04-28  Bill Seurer  <seurer@linux.vnet.ibm.com>
 
        * gcc.target/powerpc/vec-adde.c: New test.
diff --git a/gcc/testsuite/gcc.target/i386/pr70821.c b/gcc/testsuite/gcc.target/i386/pr70821.c
new file mode 100644 (file)
index 0000000..3b5de2f
--- /dev/null
@@ -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" } } */