Re: [PATCH v5] S/390: Optimize atomic_compare_exchange and atomic_compare builtins.

2017-04-25 Thread Andreas Krebbel
On 04/11/2017 04:20 PM, Dominik Vogt wrote:
> On Mon, Mar 27, 2017 at 09:27:35PM +0100, Dominik Vogt wrote:
>> The attached patch optimizes the atomic_exchange and
>> atomic_compare patterns on s390 and s390x (mostly limited to
>> SImode and DImode).  Among general optimizaation, the changes fix
>> most of the problems reported in PR 80080:
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80080
>>
>> Bootstrapped and regression tested on a zEC12 with s390 and s390x
>> biarch.
> 
> v5:
>   * Generate LT pattern directly for const 0 value.
>   * Split into three patches.
> 
> Bootstrapped and regression tested on a zEC12 with s390 and s390x
> biarch.

Applied to mainline. Thanks!

-Andreas-



Re: [PATCH v5] S/390: Optimize atomic_compare_exchange and atomic_compare builtins.

2017-04-24 Thread Ulrich Weigand
Dominik Vogt wrote:
> On Mon, Mar 27, 2017 at 09:27:35PM +0100, Dominik Vogt wrote:
> > The attached patch optimizes the atomic_exchange and
> > atomic_compare patterns on s390 and s390x (mostly limited to
> > SImode and DImode).  Among general optimizaation, the changes fix
> > most of the problems reported in PR 80080:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80080
> > 
> > Bootstrapped and regression tested on a zEC12 with s390 and s390x
> > biarch.
> 
> v5:
>   * Generate LT pattern directly for const 0 value.
>   * Split into three patches.
> 
> Bootstrapped and regression tested on a zEC12 with s390 and s390x
> biarch.

> gcc/ChangeLog-dv-atomic-gcc7-1
> 
>   * config/s390/s390.md ("cstorecc4"): Use load-on-condition and deal
>   with CCZmode for TARGET_Z196.

> gcc/ChangeLog-dv-atomic-gcc7-2
> 
>   * config/s390/s390.md (define_peephole2): New peephole to help
>   combining the load-and-test pattern with volatile memory.

> gcc/ChangeLog-dv-atomic-gcc7-3
> 
>   * s390-protos.h (s390_expand_cs_hqi): Removed.
>   (s390_expand_cs, s390_expand_atomic_exchange_tdsi): New prototypes.
>   * config/s390/s390.c (s390_emit_compare_and_swap): Handle all integer
>   modes as well as CCZ1mode and CCZmode.
>   (s390_expand_atomic_exchange_tdsi, s390_expand_atomic): Adapt to new
>   signature of s390_emit_compare_and_swap.
>   (s390_expand_cs_hqi): Likewise, make static.
>   (s390_expand_cs_tdsi): Generate an explicit compare before trying
>   compare-and-swap, in some cases.
>   (s390_expand_cs): Wrapper function.
>   (s390_expand_atomic_exchange_tdsi): New backend specific expander for
>   atomic_exchange.
>   (s390_match_ccmode_set): Allow CCZmode <-> CCZ1 mode.
>   * config/s390/s390.md ("atomic_compare_and_swap"): Merge the
>   patterns for small and large integers.  Forbid symref memory operands.
>   Move expander to s390.c.  Require cc register.
>   ("atomic_compare_and_swap_internal")
>   ("*atomic_compare_and_swap_1")
>   ("*atomic_compare_and_swapdi_2")
>   ("*atomic_compare_and_swapsi_3"): Use s_operand to forbid
>   symref memory operands.  Remove CC mode and call s390_match_ccmode
>   instead.
>   ("atomic_exchange"): Allow and implement all integer modes.
>
> gcc/testsuite/ChangeLog-dv-atomic-gcc7
> 
>   * gcc.target/s390/md/atomic_compare_exchange-1.c: New test.
>   * gcc.target/s390/md/atomic_compare_exchange-1.inc: New test.
>   * gcc.target/s390/md/atomic_exchange-1.inc: New test.


These all look good to me now.

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  ulrich.weig...@de.ibm.com



Re: [PATCH v5] S/390: Optimize atomic_compare_exchange and atomic_compare builtins.

2017-04-11 Thread Dominik Vogt
On Mon, Mar 27, 2017 at 09:27:35PM +0100, Dominik Vogt wrote:
> The attached patch optimizes the atomic_exchange and
> atomic_compare patterns on s390 and s390x (mostly limited to
> SImode and DImode).  Among general optimizaation, the changes fix
> most of the problems reported in PR 80080:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80080
> 
> Bootstrapped and regression tested on a zEC12 with s390 and s390x
> biarch.

v5:
  * Generate LT pattern directly for const 0 value.
  * Split into three patches.

Bootstrapped and regression tested on a zEC12 with s390 and s390x
biarch.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
gcc/ChangeLog-dv-atomic-gcc7-1

* config/s390/s390.md ("cstorecc4"): Use load-on-condition and deal
with CCZmode for TARGET_Z196.
gcc/ChangeLog-dv-atomic-gcc7-2

* config/s390/s390.md (define_peephole2): New peephole to help
combining the load-and-test pattern with volatile memory.
gcc/ChangeLog-dv-atomic-gcc7-3

* s390-protos.h (s390_expand_cs_hqi): Removed.
(s390_expand_cs, s390_expand_atomic_exchange_tdsi): New prototypes.
* config/s390/s390.c (s390_emit_compare_and_swap): Handle all integer
modes as well as CCZ1mode and CCZmode.
(s390_expand_atomic_exchange_tdsi, s390_expand_atomic): Adapt to new
signature of s390_emit_compare_and_swap.
(s390_expand_cs_hqi): Likewise, make static.
(s390_expand_cs_tdsi): Generate an explicit compare before trying
compare-and-swap, in some cases.
(s390_expand_cs): Wrapper function.
(s390_expand_atomic_exchange_tdsi): New backend specific expander for
atomic_exchange.
(s390_match_ccmode_set): Allow CCZmode <-> CCZ1 mode.
* config/s390/s390.md ("atomic_compare_and_swap"): Merge the
patterns for small and large integers.  Forbid symref memory operands.
Move expander to s390.c.  Require cc register.
("atomic_compare_and_swap_internal")
("*atomic_compare_and_swap_1")
("*atomic_compare_and_swapdi_2")
("*atomic_compare_and_swapsi_3"): Use s_operand to forbid
symref memory operands.  Remove CC mode and call s390_match_ccmode
instead.
("atomic_exchange"): Allow and implement all integer modes.
gcc/testsuite/ChangeLog-dv-atomic-gcc7

* gcc.target/s390/md/atomic_compare_exchange-1.c: New test.
* gcc.target/s390/md/atomic_compare_exchange-1.inc: New test.
* gcc.target/s390/md/atomic_exchange-1.inc: New test.
>From fda471edcdea8b86d678514d4fa6cf11745cd2a5 Mon Sep 17 00:00:00 2001
From: Dominik Vogt 
Date: Mon, 10 Apr 2017 08:29:40 +0100
Subject: [PATCH 1/3] S/390: Use load-on-condition in cstorecc4.

---
 gcc/config/s390/s390.md | 25 +
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md
index 59f189c..6a1cab6 100644
--- a/gcc/config/s390/s390.md
+++ b/gcc/config/s390/s390.md
@@ -6518,13 +6518,30 @@
   [(parallel
 [(set (match_operand:SI 0 "register_operand" "")
  (match_operator:SI 1 "s390_eqne_operator"
-   [(match_operand:CCZ1 2 "register_operand")
+   [(match_operand 2 "cc_reg_operand")
(match_operand 3 "const0_operand")]))
  (clobber (reg:CC CC_REGNUM))])]
   ""
-  "emit_insn (gen_sne (operands[0], operands[2]));
-   if (GET_CODE (operands[1]) == EQ)
- emit_insn (gen_xorsi3 (operands[0], operands[0], const1_rtx));
+  "machine_mode mode = GET_MODE (operands[2]);
+   if (TARGET_Z196)
+ {
+   rtx cond, ite;
+
+   if (GET_CODE (operands[1]) == NE)
+cond = gen_rtx_NE (VOIDmode, operands[2], const0_rtx);
+   else
+cond = gen_rtx_EQ (VOIDmode, operands[2], const0_rtx);
+   ite = gen_rtx_IF_THEN_ELSE (SImode, cond, const1_rtx, const0_rtx);
+   emit_insn (gen_rtx_SET (operands[0], ite));
+ }
+   else
+ {
+   if (mode != CCZ1mode)
+FAIL;
+   emit_insn (gen_sne (operands[0], operands[2]));
+   if (GET_CODE (operands[1]) == EQ)
+emit_insn (gen_xorsi3 (operands[0], operands[0], const1_rtx));
+ }
DONE;")
 
 (define_insn_and_split "sne"
-- 
2.3.0

>From cf55c86d6c8b7aef1a669c9368410f32f333c59a Mon Sep 17 00:00:00 2001
From: Dominik Vogt 
Date: Tue, 11 Apr 2017 12:18:01 +0100
Subject: [PATCH 2/3] S/390: Peephole to merge L followerd by LT.

In some situations this is not done by other optimization passed.
---
 gcc/config/s390/s390.md | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md
index 6a1cab6..9baafcc 100644
--- a/gcc/config/s390/s390.md
+++ b/gcc/config/s390/s390.md
@@ -907,6 +907,21 @@
   [(set_attr "op_type" "RR,RXY")
(set_attr "z10prop" "z10_fr_E1,z10_fwd_A3") ])
 
+; Peephole to combine a load-and-test from volatile memory which combine does
+; not do.
+(define_peephole2
+  [(set