diff mbox series

s390: Fix UNSPEC_CC_TO_INT canonicalization

Message ID 20241206180057.45958-1-jchrist@linux.ibm.com
State New
Headers show
Series s390: Fix UNSPEC_CC_TO_INT canonicalization | expand

Commit Message

Juergen Christ Dec. 6, 2024, 6 p.m. UTC
Canonicalization of comparisons for UNSPEC_CC_TO_INT missed one case
causing unnecessarily complex code.  This especially seems to hit the
Linux kernel.

gcc/ChangeLog:

	* config/s390/s390.cc (s390_canonicalize_comparison): Add
          missing UNSPEC_CC_TO_INT case.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/ccusage.c: New test.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>

Bootstrapped and regression tested on s390.  Okay for trunk?
Okay to backport to GCC 14?

---
 gcc/config/s390/s390.cc                 |  2 +-
 gcc/testsuite/gcc.target/s390/ccusage.c | 37 +++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/ccusage.c

Comments

Andreas Krebbel Dec. 9, 2024, 2:07 p.m. UTC | #1
On 12/6/24 19:00, Juergen Christ wrote:
> Canonicalization of comparisons for UNSPEC_CC_TO_INT missed one case
> causing unnecessarily complex code.  This especially seems to hit the
> Linux kernel.
>
> gcc/ChangeLog:
>
> 	* config/s390/s390.cc (s390_canonicalize_comparison): Add
>            missing UNSPEC_CC_TO_INT case.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/s390/ccusage.c: New test.

Ok. Thanks!

Andreas


>
> Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
>
> Bootstrapped and regression tested on s390.  Okay for trunk?
> Okay to backport to GCC 14?
>
> ---
>   gcc/config/s390/s390.cc                 |  2 +-
>   gcc/testsuite/gcc.target/s390/ccusage.c | 37 +++++++++++++++++++++++++
>   2 files changed, 38 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/gcc.target/s390/ccusage.c
>
> diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
> index 25d43ae3e138..c36c33ff8280 100644
> --- a/gcc/config/s390/s390.cc
> +++ b/gcc/config/s390/s390.cc
> @@ -1859,7 +1859,7 @@ s390_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
>         && CONST_INT_P (XEXP (*op0, 1))
>         && CONST_INT_P (*op1)
>         && INTVAL (XEXP (*op0, 1)) == -3
> -      && *code == EQ)
> +      && (*code == EQ || *code == NE))
>       {
>         if (INTVAL (*op1) == 0)
>   	{
> diff --git a/gcc/testsuite/gcc.target/s390/ccusage.c b/gcc/testsuite/gcc.target/s390/ccusage.c
> new file mode 100644
> index 000000000000..e25f712e25ca
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/s390/ccusage.c
> @@ -0,0 +1,37 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -march=zEC12 -mzarch" } */
> +
> +static __attribute__((always_inline)) inline
> +int __atomic_dec_and_test(int *ptr)
> +{
> +        int cc;
> +        asm volatile(
> +                "       alsi    %[ptr],-1\n"
> +                : "=@cc" (cc), [ptr] "+QS" (*ptr) : : "memory");
> +        return (cc == 0) || (cc == 2);
> +}
> +
> +int a;
> +void dummy(void);
> +long fu(void)
> +{
> +        if (__atomic_dec_and_test(&a))
> +                return 5;
> +        return 8;
> +}
> +
> +void bar(void)
> +{
> +        if (__atomic_dec_and_test(&a))
> +                dummy();
> +}
> +
> +int foo(int x)
> +{
> +        int cc;
> +        asm volatile ("ahi %[x],42\n"
> +                        : [x] "+d" (x), "=@cc" (cc));
> +        return !(cc == 0 || cc == 2) ? 42 : 13;
> +}
> +
> +/* { dg-final { scan-assembler-not {ipm} } } */
diff mbox series

Patch

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 25d43ae3e138..c36c33ff8280 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -1859,7 +1859,7 @@  s390_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
       && CONST_INT_P (XEXP (*op0, 1))
       && CONST_INT_P (*op1)
       && INTVAL (XEXP (*op0, 1)) == -3
-      && *code == EQ)
+      && (*code == EQ || *code == NE))
     {
       if (INTVAL (*op1) == 0)
 	{
diff --git a/gcc/testsuite/gcc.target/s390/ccusage.c b/gcc/testsuite/gcc.target/s390/ccusage.c
new file mode 100644
index 000000000000..e25f712e25ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/ccusage.c
@@ -0,0 +1,37 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=zEC12 -mzarch" } */
+
+static __attribute__((always_inline)) inline
+int __atomic_dec_and_test(int *ptr)
+{
+        int cc;
+        asm volatile(
+                "       alsi    %[ptr],-1\n"
+                : "=@cc" (cc), [ptr] "+QS" (*ptr) : : "memory");
+        return (cc == 0) || (cc == 2);
+}
+ 
+int a;
+void dummy(void);
+long fu(void)
+{
+        if (__atomic_dec_and_test(&a))
+                return 5;
+        return 8;
+}
+ 
+void bar(void)
+{
+        if (__atomic_dec_and_test(&a))
+                dummy();
+}
+
+int foo(int x)
+{
+        int cc;
+        asm volatile ("ahi %[x],42\n"
+                        : [x] "+d" (x), "=@cc" (cc));
+        return !(cc == 0 || cc == 2) ? 42 : 13;
+}
+
+/* { dg-final { scan-assembler-not {ipm} } } */