Re: [Committed] IBM Z: Add pattern for load truth value of comparison into reg

2019-11-11 Thread Richard Henderson
On 11/11/19 4:03 PM, Andreas Krebbel wrote:
> On 11.11.19 15:39, Richard Henderson wrote:
>> On 11/7/19 12:52 PM, Andreas Krebbel wrote:
>>> +; Such patterns get directly emitted by noce_emit_store_flag.
>>> +(define_insn_and_split "*cstorecc_z13"
>>> +  [(set (match_operand:GPR  0 "register_operand""=")
>>> +   (match_operator:GPR 1 "s390_comparison"
>>> +   [(match_operand 2 "cc_reg_operand""c")
>>> +(match_operand 3 "const_int_operand"  "")]))]
>>
>> The clobbered-output seems superfluous, since it can't overlap "c".
> I thought it would be "more" correct this way, but it might lead to an extra 
> reload being emitted - right?

Well, possibly no extra reloads either, since no input will overlap.

>> I believe the only valid const_int is 0, fwiw, so perhaps matching any
>> const_int is overkill.
> We also have CCRAW mode where that value is != 0.

Oh wow.  That's an interesting way to fold those combinations.

>> Does it help Z12 to allow the 3-insn sequence using LOC(G)R?
> Prior to z13 we prefer the variant using a conditional branch.

Ok, just checking.  Thanks,


r~


Re: [Committed] IBM Z: Add pattern for load truth value of comparison into reg

2019-11-11 Thread Andreas Krebbel
On 11.11.19 15:39, Richard Henderson wrote:
> On 11/7/19 12:52 PM, Andreas Krebbel wrote:
>> +; Such patterns get directly emitted by noce_emit_store_flag.
>> +(define_insn_and_split "*cstorecc_z13"
>> +  [(set (match_operand:GPR  0 "register_operand""=")
>> +(match_operator:GPR 1 "s390_comparison"
>> +[(match_operand 2 "cc_reg_operand""c")
>> + (match_operand 3 "const_int_operand"  "")]))]
> 
> The clobbered-output seems superfluous, since it can't overlap "c".
I thought it would be "more" correct this way, but it might lead to an extra 
reload being emitted -
right?

> I believe the only valid const_int is 0, fwiw, so perhaps matching any
> const_int is overkill.
We also have CCRAW mode where that value is != 0.

> Does it help Z12 to allow the 3-insn sequence using LOC(G)R?
Prior to z13 we prefer the variant using a conditional branch.

Andreas

> 
>> +  "TARGET_Z13"
>> +  "#"
>  > +  "reload_completed"
>> +  [(set (match_dup 0) (const_int 0))
>> +   (set (match_dup 0)
>> +(if_then_else:GPR
>> + (match_op_dup 1 [(match_dup 2) (match_dup 3)])
>> + (const_int 1)
>> + (match_dup 0)))])
> 
> 
> r~
> 



Re: [Committed] IBM Z: Add pattern for load truth value of comparison into reg

2019-11-11 Thread Richard Henderson
On 11/7/19 12:52 PM, Andreas Krebbel wrote:
> +; Such patterns get directly emitted by noce_emit_store_flag.
> +(define_insn_and_split "*cstorecc_z13"
> +  [(set (match_operand:GPR  0 "register_operand""=")
> + (match_operator:GPR 1 "s390_comparison"
> + [(match_operand 2 "cc_reg_operand""c")
> +  (match_operand 3 "const_int_operand"  "")]))]

The clobbered-output seems superfluous, since it can't overlap "c".
I believe the only valid const_int is 0, fwiw, so perhaps matching any
const_int is overkill.

Does it help Z12 to allow the 3-insn sequence using LOC(G)R?

> +  "TARGET_Z13"
> +  "#"
 > +  "reload_completed"
> +  [(set (match_dup 0) (const_int 0))
> +   (set (match_dup 0)
> + (if_then_else:GPR
> +  (match_op_dup 1 [(match_dup 2) (match_dup 3)])
> +  (const_int 1)
> +  (match_dup 0)))])


r~


[Committed] IBM Z: Add pattern for load truth value of comparison into reg

2019-11-07 Thread Andreas Krebbel
The RTXs used to express an overflow condition check in add/sub/mul are
too complex for if conversion.  However, there is code in
noce_emit_store_flag which generates a simple CC compare as the base
for using a conditional load.  All we have to do is to provide a
pattern to store the truth value of a CC compare into a GPR.

Done with the attached patch.

Bootstrapped and regression tested on s390x.
Committed to mainline.

2019-11-07  Andreas Krebbel  

* config/s390/s390.md ("*cstorecc_z13"): New insn_and_split
pattern.

gcc/testsuite/ChangeLog:

2019-11-07  Andreas Krebbel  

* gcc.target/s390/addsub-signed-overflow-1.c: Expect lochi
instructions to be used.
* gcc.target/s390/addsub-signed-overflow-2.c: Likewise.
* gcc.target/s390/mul-signed-overflow-1.c: Likewise.
* gcc.target/s390/mul-signed-overflow-2.c: Likewise.
* gcc.target/s390/vector/vec-scalar-cmp-1.c: Check for 32 and 64
bit variant of lochi.  Swap the values for the lochi's.
* gcc.target/s390/zvector/vec-cmp-1.c: Likewise.
---
 gcc/config/s390/s390.md   | 15 
 .../s390/addsub-signed-overflow-1.c   |  2 +
 .../s390/addsub-signed-overflow-2.c   |  2 +
 .../gcc.target/s390/mul-signed-overflow-1.c   |  2 +
 .../gcc.target/s390/mul-signed-overflow-2.c   |  2 +
 .../gcc.target/s390/vector/vec-scalar-cmp-1.c | 18 +++--
 .../gcc.target/s390/zvector/vec-cmp-1.c   | 72 ---
 7 files changed, 83 insertions(+), 30 deletions(-)

diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md
index e3881d07f2b..c1d73d5ca42 100644
--- a/gcc/config/s390/s390.md
+++ b/gcc/config/s390/s390.md
@@ -6810,6 +6810,21 @@
 [(set (match_dup 0) (ashiftrt:SI (match_dup 0) (const_int 28)))
  (clobber (reg:CC CC_REGNUM))])])
 
+; Such patterns get directly emitted by noce_emit_store_flag.
+(define_insn_and_split "*cstorecc_z13"
+  [(set (match_operand:GPR  0 "register_operand""=")
+   (match_operator:GPR 1 "s390_comparison"
+   [(match_operand 2 "cc_reg_operand""c")
+(match_operand 3 "const_int_operand"  "")]))]
+  "TARGET_Z13"
+  "#"
+  "reload_completed"
+  [(set (match_dup 0) (const_int 0))
+   (set (match_dup 0)
+   (if_then_else:GPR
+(match_op_dup 1 [(match_dup 2) (match_dup 3)])
+(const_int 1)
+(match_dup 0)))])
 
 ;;
 ;; - Conditional move instructions (introduced with z196)
diff --git a/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-1.c 
b/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-1.c
index 367dbcb3774..143220d5541 100644
--- a/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-1.c
+++ b/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-1.c
@@ -79,3 +79,5 @@ main ()
 /* { dg-final { scan-assembler-not "\trisbg" { target { lp64 } } } } */
 /* Just one for the ret != 6 comparison.  */
 /* { dg-final { scan-assembler-times "ci" 1 } } */
+/* { dg-final { scan-assembler-times "\tlochio\t" 6 { target { ! lp64 } } } } 
*/
+/* { dg-final { scan-assembler-times "\tlocghio\t" 6 { target lp64 } } } */
diff --git a/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-2.c 
b/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-2.c
index 230ad4af1e7..798e489cece 100644
--- a/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-2.c
+++ b/gcc/testsuite/gcc.target/s390/addsub-signed-overflow-2.c
@@ -78,3 +78,5 @@ main ()
 /* { dg-final { scan-assembler-not "\trisbg" { target { lp64 } } } } */
 /* Just one for the ret != 3 comparison.  */
 /* { dg-final { scan-assembler-times "ci" 1 } } */
+/* { dg-final { scan-assembler-times "\tlochio\t" 6 { target { ! lp64 } } } } 
*/
+/* { dg-final { scan-assembler-times "\tlocghio\t" 6 { target lp64 } } } */
diff --git a/gcc/testsuite/gcc.target/s390/mul-signed-overflow-1.c 
b/gcc/testsuite/gcc.target/s390/mul-signed-overflow-1.c
index b3db60ffef5..fdf56d6e695 100644
--- a/gcc/testsuite/gcc.target/s390/mul-signed-overflow-1.c
+++ b/gcc/testsuite/gcc.target/s390/mul-signed-overflow-1.c
@@ -54,3 +54,5 @@ main ()
 /* { dg-final { scan-assembler-not "\trisbg" { target { lp64 } } } } */
 /* Just one for the ret != 3 comparison.  */
 /* { dg-final { scan-assembler-times "ci" 1 } } */
+/* { dg-final { scan-assembler-times "\tlochio\t" 3 { target { ! lp64 } } } } 
*/
+/* { dg-final { scan-assembler-times "\tlocghio\t" 3 { target lp64 } } } */
diff --git a/gcc/testsuite/gcc.target/s390/mul-signed-overflow-2.c 
b/gcc/testsuite/gcc.target/s390/mul-signed-overflow-2.c
index 76b3fa60361..d0088188aa2 100644
--- a/gcc/testsuite/gcc.target/s390/mul-signed-overflow-2.c
+++ b/gcc/testsuite/gcc.target/s390/mul-signed-overflow-2.c
@@ -54,3 +54,5 @@ main ()
 /* { dg-final { scan-assembler-not "\trisbg" { target { lp64 } } } } */
 /* Just one for the ret != 3 comparison.  */
 /* { dg-final { scan-assembler-times "ci" 1 } } */
+/* { dg-final { scan-assembler-times "\tlochio\t" 3 { target { ! lp64 } }