diff mbox series

[v5,rs6000] Add a combine pattern for CA minus one [PR95737]

Message ID 5f5cd8d8-b88b-324b-3777-25e6560d7616@linux.ibm.com
State New
Headers show
Series [v5,rs6000] Add a combine pattern for CA minus one [PR95737] | expand

Commit Message

HAO CHEN GUI May 16, 2022, 5:22 a.m. UTC
Hi,
   This patch adds a combine pattern for "CA minus one". As CA only has two
values (0 or 1), we could convert following pattern
      (sign_extend:DI (plus:SI (reg:SI 98 ca)
                (const_int -1 [0xffffffffffffffff]))))
to
       (plus:DI (reg:DI 98 ca)
            (const_int -1 [0xffffffffffffffff])))
   With this patch, one unnecessary sign extend is eliminated.

   Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.
Is this okay for trunk? Any recommendations? Thanks a lot.

ChangeLog
2022-05-16 Haochen Gui <guihaoc@linux.ibm.com>

gcc/
	PR target/95737
	* config/rs6000/rs6000.md (subfsi3_carry_in_xx_64): New.

gcc/testsuite/
	PR target/95737
	* gcc.target/powerpc/pr95737.c: New.

patch.diff

Comments

Kewen.Lin May 16, 2022, 6:56 a.m. UTC | #1
Hi Haochen,

on 2022/5/16 13:22, HAO CHEN GUI wrote:
> Hi,
>    This patch adds a combine pattern for "CA minus one". As CA only has two
> values (0 or 1), we could convert following pattern
>       (sign_extend:DI (plus:SI (reg:SI 98 ca)
>                 (const_int -1 [0xffffffffffffffff]))))
> to
>        (plus:DI (reg:DI 98 ca)
>             (const_int -1 [0xffffffffffffffff])))
>    With this patch, one unnecessary sign extend is eliminated.
> 
>    Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.
> Is this okay for trunk? Any recommendations? Thanks a lot.
> 
> ChangeLog
> 2022-05-16 Haochen Gui <guihaoc@linux.ibm.com>
> 
> gcc/
> 	PR target/95737
> 	* config/rs6000/rs6000.md (subfsi3_carry_in_xx_64): New.

(subfsi3_carry_in_xx_64) -> (*subfsi3_carry_in_xx_64)
Sorry for nit-picking, but they are different.

> 
> gcc/testsuite/
> 	PR target/95737
> 	* gcc.target/powerpc/pr95737.c: New.
> 
> patch.diff
> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
> index 64049a6e521..b97ac453fc0 100644
> --- a/gcc/config/rs6000/rs6000.md
> +++ b/gcc/config/rs6000/rs6000.md
> @@ -2353,6 +2353,19 @@ (define_insn "subf<mode>3_carry_in_xx"
>    "subfe %0,%0,%0"
>    [(set_attr "type" "add")])
> 
> +(define_insn_and_split "*subfsi3_carry_in_xx_64"
> +  [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
> +	(sign_extend:DI (plus:SI (reg:SI CA_REGNO)
> +				 (const_int -1))))]
> +  "TARGET_POWERPC64"
> +  "#"
> +  ""

"&& 1"

> +  [(parallel [(set (match_dup 0)
> +		   (plus:DI (reg:DI CA_REGNO)
> +			    (const_int -1)))
> +	      (clobber (reg:DI CA_REGNO))])]
> +  ""
> +)
> 
>  (define_insn "@neg<mode>2"
>    [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c
> new file mode 100644
> index 00000000000..30f0f819393
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c
> @@ -0,0 +1,11 @@
> +/* PR target/95737 */
> +/* { dg-do compile } */
> +/* Disable isel for P9 and later */

Maybe it looks better with "later.  */"

Test case doesn't need strict formatting, so your call.  :)

> +/* { dg-options "-O2 -mno-isel" } */
> +/* { dg-final { scan-assembler-not {\mextsw\M} } } */
> +
> +
> +unsigned long negativeLessThan (unsigned long a, unsigned long b)
> +{
> +   return -(a < b);
> +}

OK with split condition fixed, with or without those nits tweaked.

BR,
Kewen
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 64049a6e521..b97ac453fc0 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -2353,6 +2353,19 @@  (define_insn "subf<mode>3_carry_in_xx"
   "subfe %0,%0,%0"
   [(set_attr "type" "add")])

+(define_insn_and_split "*subfsi3_carry_in_xx_64"
+  [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
+	(sign_extend:DI (plus:SI (reg:SI CA_REGNO)
+				 (const_int -1))))]
+  "TARGET_POWERPC64"
+  "#"
+  ""
+  [(parallel [(set (match_dup 0)
+		   (plus:DI (reg:DI CA_REGNO)
+			    (const_int -1)))
+	      (clobber (reg:DI CA_REGNO))])]
+  ""
+)

 (define_insn "@neg<mode>2"
   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c
new file mode 100644
index 00000000000..30f0f819393
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c
@@ -0,0 +1,11 @@ 
+/* PR target/95737 */
+/* { dg-do compile } */
+/* Disable isel for P9 and later */
+/* { dg-options "-O2 -mno-isel" } */
+/* { dg-final { scan-assembler-not {\mextsw\M} } } */
+
+
+unsigned long negativeLessThan (unsigned long a, unsigned long b)
+{
+   return -(a < b);
+}